0

hi everyone. just recently I've been messing around with controlling itunes with python (you should check it out on google; some pretty fun stuff to mess with :D). I've already got all of my functions down, but my questions is that how would I go about grabbing keyboard/mouse input (mouse buttons, not really mouse movement) outside of the python window? (or while a different window is the current active window). I know how to get keyboard input inside of the python window using

from msvcrt import getch

Anyone have any suggestions?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by fallopiano
0

For the keyboard I use pyHook and pythoncom.
Try something like this.

import pythoncom, pyHook, sys

def OnKeyboardEvent(event):
    x = chr(event.Ascii)
    print "Key: ", chr(event.Ascii)
    #do something here
    #x can be a conditional for something
    return True #,return x
    
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages() #will wait forever

I haven't tested this actual code, but play around with it.
I have an example using this http://www.daniweb.com/forums/thread229564.html

Edited by Tech B: code tag fix

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.