class _Getch: """Gets a single character from standard input. Does not echo to the screen.""" def __init__(self): self.impl = _GetchWindows() def __call__(self): return self.impl() class _GetchWindows: def __init__(self): import msvcrt def __call__(self): import msvcrt return msvcrt.getch() if __name__ == '__main__': # a little test print ('Press a key') inkey = _Getch() import sys for i in range(100): k=inkey() print ('you pressed ',k) if k.decode()=='q': break