In wxPython how do you bind a EVT_KEY_DOWN event to the whole window?

后端 未结 2 1084
栀梦
栀梦 2021-02-04 06:05

I can bind an event to a textctrl box np. The problem is I have to be clicked inside of the textctrl box to \"catch\" this event. I am hoping to be able to catch anytime someo

2条回答
  •  野性不改
    2021-02-04 06:24

    Instead try binding to wx.EVT_CHAR_HOOK

    e.g..

    self.Bind(wx.EVT_CHAR_HOOK, self.onKey)
    
      ...
    
    def onKey(self, evt):
        if evt.GetKeyCode() == wx.WXK_DOWN:
            print "Down key pressed"
        else:
            evt.Skip()
    

提交回复
热议问题