Is that what you mean? You need to look at global accelerators. Coincidentally, I looked at this on the last day or two. Assuming the wxpython application window has focus, the following should invoke the appropriate keystroke procedure. Work on my ubuntu 11.04 / py 2.7.1 / wxpython 2.8
Obviously, you can potentially consolidate the event method.
There is not much in this thread, but this link and this link helped me (same site)
import wx class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "Global Keypress") self.panel = wx.Panel(self, wx.ID_ANY) self.CreateStatusBar() # Global accelerators id_F1 = wx.NewId() id_F2 = wx.NewId() self.Bind(wx.EVT_MENU, self.pressed_F1, id=id_F1) self.Bind(wx.EVT_MENU, self.pressed_F2, id=id_F2) accel_tbl = wx.AcceleratorTable([ (wx.ACCEL_NORMAL, wx.WXK_F1, id_F1 ), (wx.ACCEL_NORMAL, wx.WXK_F2, id_F2 ) ]) self.SetAcceleratorTable(accel_tbl) def pressed_F1(self, event): print "Pressed F1" return True def pressed_F2(self, event): print "Pressed F2" return True if __name__ == "__main__": app = wx.PySimpleApp() f = MyFrame().Show() app.MainLoop()
source share