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
Post a Comment