Hi everyone,
I'm trying to add a Keyboard shortcut to a Button and can't seem to get it to work:
Below is what I have so far:
import wx, os
class TestKey(wx.Frame):
def __init__(self, parent, id, title, position, size):
wx.Frame.__init__(self, parent, id, title, position, size)
d = wx.Button(self, -1, "Press Me")
wx.EVT_BUTTON(self, d.GetId(), self.OnKeyDown)
wx.EVT_KEY_DOWN(self,self.OnKeyDown)
def OnKeyDown(self, event):
key = event.KeyCode()
if key == WXK_UP:
print "Up Key Pressed"
event.Skip()
class App(wx.App):
def OnInit(self):
frame = TestKey(wx.NULL, -1, "Key Press Test", wx.DefaultPosition,(200,200))
self.SetTopWindow(frame)
frame.Show(True)
return True
if __name__ == "__main__":
app = App(0)
app.MainLoop()
If I press the "Up" key, nothing is printed.
I tried the following variations:
wx.EVT_KEY_DOWN(parent,self.OnKeyDown)
wx.EVT_KEY_DOWN(wx.Frame,self.OnKeyDown)
wx.EVT_KEY_DOWN(d,self.OnKeyDown)
but "Up" key still isn't detecteed
What am I missing?
Thanks in advance.
-gohaku