source: trunk/loplug/plugins/input/test.py @ 2290

Revision 1679, 1.3 KB checked in by tolteque, 2 years ago (diff)

o LoPlug?

  • Change way of working for pyHook. No need to invoke PumpMessage?() which is done by QT
Line 
1import threading
2from time import *
3import pythoncom
4import pyHook
5
6keyPressed = []
7def OnKeyBoardEvent( event):
8  global keyPressed
9#  print 'MessageName:',event.MessageName
10#  print 'Message:',event.Message
11#  print 'Time:',event.Time
12#  print 'Window:',event.Window
13#  print 'WindowName:',event.WindowName
14#  print 'Ascii:', event.Ascii, chr(event.Ascii)
15#  print 'Key:', event.Key
16#  print 'KeyID:', event.KeyID
17#  print 'ScanCode:', event.ScanCode
18#  print 'Extended:', event.Extended
19#  print 'Injected:', event.Injected
20#  print 'Alt', event.Alt
21#  print 'Transition', event.Transition
22#  print '---'
23
24  key = event.KeyID
25  if event.IsTransition():
26    if key in keyPressed:
27      print "key up"
28      keyPressed.remove( key)
29      print keyPressed
30
31  else:
32    if not ( key in keyPressed):
33      print "key down"
34      keyPressed.append( key)
35      print keyPressed
36
37  return True
38
39 
40def process():
41  hookManager = pyHook.HookManager()
42  hookManager.SubscribeKeyAll( OnKeyBoardEvent)
43  hookManager.HookKeyboard()
44  pythoncom.PumpMessages()
45   
46 
47# =================================================
48if __name__ == "__main__":
49  processThread = threading.Thread( target = process)
50  processThread.setDaemon( True)
51  processThread.start()
52  while( 1):
53    sleep( 10)
Note: See TracBrowser for help on using the repository browser.