0

so Im trying to write a program that needs to log keystrokes. I have this current script:

def __call__(self):
    ch=msvcrt.getch()
    if ch in b'\x00\xe0':
        ch=msvcrt.getch()
    return ch

this works for basic keys but does not show arrowkeys, backspace, enter. it also does not work outside of the program window. how would i make it run outside of the window and log these other keys on Windows?

J leong
  • 285
  • 5
  • 13

1 Answers1

2

I would suggest using pyHook and following one of the demos they have. It is an external library that you can use that allows you to monitor global keyboard and mouse events.

agardler
  • 66
  • 4
  • This seems to be Windows specific. What OS are you working with @Jleong – joel goldstick Mar 31 '16 at 20:09
  • 1
    I use Windows personally. I think this may be duplicate question, check out [this](http://stackoverflow.com/questions/676713/is-there-a-cross-platform-python-low-level-api-to-capture-or-generate-keyboard-e) – agardler Mar 31 '16 at 20:15
  • @agardler do you know if there is any documentation for pyHook? I do not understand the entire example that pyHook provided. However for now implementing it in my code seems to be working with a few modifications to the parts I do understand – J leong Apr 01 '16 at 15:23
  • @J leong [this](http://pyhook.sourceforge.net/doc_1.5.0/) is what I found in terms of keyboard stroke documentation – agardler Apr 01 '16 at 17:02