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
| import wx
import win32con #for the VK keycodes
class FrameWithHotKey(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.regHotKey()
self.Bind(wx.EVT_HOTKEY, self.handleHotKey, id=self.hotKeyId)
def regHotKey(self):
"""
This function registers the hotkey Alt+F1 with id=100
"""
self.hotKeyId = 25
self.RegisterHotKey(
self.hotKeyId, #a unique ID for this hotkey
win32con.MOD_ALT, #the modifier key
win32con.VK_LEFT) #the key to watch for
def handleHotKey(self, evt):
"""
Prints a simple message when a hotkey event is received.
"""
print "do hot key actions"
if __name__ == "__main__":
app = wx.App()#redirect=True, filename="err.log")
frame = FrameWithHotKey(None,-1,'my application')
frame.Show(True)
app.MainLoop() |
Partager