Polling the keyboard (detect a keypress) in python

The standard approach is to use the select module.

However, this doesn’t work on Windows. For that, you can use the msvcrt module’s keyboard polling.

Often, this is done with multiple threads — one per device being “watched” plus the background processes that might need to be interrupted by the device.

Leave a Comment