Search code examples
pythonwindowskeypressmsvcrtgetch

Catching Keypresses on Windows with Python using MSVCRT when terminal window not in Focus


I want to be able to use the msvcrt package in python to catch keypresses via the msvcrt.getch() method but it appears the the terminal window needs to be in focus for it to work. Is there a way around this?


Solution

  • I found a python wrapper for Ctypes as suggested by @IInspectable. It wraps the low_level Keyboard hooks with a nice monitor class.

    https://github.com/ethanhs/pyhooked