thekindlyone
thekindlyone

Reputation: 509

How do I get python to detect keystrokes from the keyboard and send different strings based on the input key(s) in windows

I am trying to write a script that duplicates a little bit of what Autohotkey does, because it doesn't work very well for me. I need the script to detect keyboard/mouse-click input to a program, and send different strings/sequence of keystrokes based on the original key pressed. For example if I press mouse middle button, I want to send the three keystrokes 8,9 and 0 in place of the click. All this while some other application is being used. i.e. Torchlight II. Can anyone tell me

  1. what to use to get the global keyboard input and
  2. How to send keystrokes to an application?

I would have used Autohotkey for this but it is acting very unreliably with random unacceptable bugs. I am using python 2.7 64bit, windows 7.

Upvotes: 2

Views: 1108

Answers (1)

thekindlyone
thekindlyone

Reputation: 509

I found the solutions and finished the script. Here are my findings.

1.I got the global keyboard/mouse inputs from Pyhook. Installing it on Python 2.7 amdx64 might be a bit tricky.

2.To send keystrokes/input to an application I used sendkeys-ctypes which works well with python 2.7

Upvotes: 2

Related Questions