0

I have the following script, which detects keyboard inputs and prints the pressed keys:

import msvcrt

while True:
    if msvcrt.kbhit():
        key = msvcrt.getch()
        print("Key is {}".format(key))

The problem is that I can only type/enter characters into my terminal window, where the script output is. In other words, if I open a new program/window and start typing there, the script is not detecting the input. How do I solve this?

  • Are you looking for a keylogger type of functionality? – Zeeshan Nov 05 '19 at 13:50
  • I'm not sure. I just want to have a pipeline from a game to python, where I can save my keyboard inputs that I press inside a game. Also the reverse - being able to send inputs to the game using Python. – Lazy_Beaver Nov 05 '19 at 14:14
  • See if this helps. [detect key press in python?](https://stackoverflow.com/questions/24072790/detect-key-press-in-python) – Zeeshan Nov 05 '19 at 14:17
  • Thank you, seems to work exactly as I want it. – Lazy_Beaver Nov 05 '19 at 14:30

0 Answers0