console - Polling the keyboard (detect a keypress) in python -


how can poll keyboard console python app? specifically, akin in midst of lot of other i/o activities (socket selects, serial port access, etc.):

   while 1:       # doing amazing pythonic embedded stuff       # ...        # periodically non-blocking check see if       # being told else       x = keyboard.read(1000, timeout = 0)        if len(x):           # ok, key got pressed           # 

what correct pythonic way on windows? also, portability linux wouldn't bad, though it's not required.

the standard approach use select module.

however, doesn't work on windows. that, can use msvcrt module's keyboard polling.

often, done multiple threads -- 1 per device being "watched" plus background processes might need interrupted device.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -