944,017 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 2937
  • Python RSS
Oct 11th, 2009
0

grab mouse and key input outside of python window

Expand Post »
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 ). 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
python Syntax (Toggle Plain Text)
  1. from msvcrt import getch

Anyone have any suggestions?
Similar Threads
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
fallopiano is offline Offline
68 posts
since Jun 2009
Oct 12th, 2009
0
Re: grab mouse and key input outside of python window
For the keyboard I use pyHook and pythoncom.
Try something like this.

Python Syntax (Toggle Plain Text)
  1. import pythoncom, pyHook, sys
  2.  
  3. def OnKeyboardEvent(event):
  4. x = chr(event.Ascii)
  5. print "Key: ", chr(event.Ascii)
  6. #do something here
  7. #x can be a conditional for something
  8. return True #,return x
  9.  
  10. hm = pyHook.HookManager()
  11. hm.KeyDown = OnKeyboardEvent
  12. hm.HookKeyboard()
  13. 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
Last edited by Tech B; Oct 12th, 2009 at 3:52 pm. Reason: code tag fix
Reputation Points: 59
Solved Threads: 33
Posting Whiz in Training
Tech B is offline Offline
268 posts
since May 2009
Oct 12th, 2009
0
Re: grab mouse and key input outside of python window
really cool, thanks!
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
fallopiano is offline Offline
68 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: How to do Input in Python?
Next Thread in Python Forum Timeline: call function from string (with arguements)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC