1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #!/usr/bin/python
# -*- coding: iso-8859-1 -*-
import pythoncom, pyHook
try:
import wx
except ImportError:
raise ImportError,"The wxPython module is required to run this program"
class simpleapp_wx(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title)
self.parent = parent
self.initialize()
self.Bind(wx.EVT_CLOSE, self.OnClose)
def initialize(self):
self.Show(True)
def OnClose(self, event):
self.Destroy()
if __name__ == "__main__":
#app = wx.App()
app = wx.App(redirect=True, filename="err.log")
frame = simpleapp_wx(None,-1,'my application')
def OnKeyboardEvent(event):
print 'MessageName:',event.MessageName
print 'Message:',event.Message
print 'Time:',event.Time
print 'Window:',event.Window
print 'WindowName:',event.WindowName
print 'Ascii:', event.Ascii, chr(event.Ascii)
k = event.Key
print 'Key:', event.Key
print 'KeyID:', event.KeyID
print 'ScanCode:', event.ScanCode
print 'Extended:', event.Extended
print 'Injected:', event.Injected
print 'Alt', event.Alt
print 'Transition', event.Transition
print '---'
frame.SetFocus()
if k == "X":
print "xx"
frame.Lower()
if k == "Y":
print "yy"
frame.Raise()
frame.SetFocus()
# return True to pass the event to other handlers
return True
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyUp = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
app.MainLoop() |
Partager