grab mouse and key input outside of python window

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 54
Reputation: fallopiano is an unknown quantity at this point 
Solved Threads: 3
fallopiano's Avatar
fallopiano fallopiano is offline Offline
Junior Poster in Training

grab mouse and key input outside of python window

 
0
  #1
Oct 11th, 2009
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
  1. from msvcrt import getch

Anyone have any suggestions?
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 29
Reputation: Tech B is an unknown quantity at this point 
Solved Threads: 2
Tech B's Avatar
Tech B Tech B is offline Offline
Light Poster
 
0
  #2
Oct 12th, 2009
For the keyboard I use pyHook and pythoncom.
Try something like this.

  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
"In worn down shoes i found redemption; judge me not for I've walked with sin...."
~K.B. Carte
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 54
Reputation: fallopiano is an unknown quantity at this point 
Solved Threads: 3
fallopiano's Avatar
fallopiano fallopiano is offline Offline
Junior Poster in Training
 
0
  #3
Oct 12th, 2009
really cool, thanks!
Reply With Quote Quick reply to this message  
Reply

Tags
input, itunes, keyboard, mouse, python

Message:



Similar Threads
Other Threads in the Python Forum


Views: 947 | Replies: 2
Thread Tools Search this Thread



Tag cloud for input, itunes, keyboard, mouse, python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC