0
下面的代碼是我的任務欄圖標類的簡化版本,我沒有檢查GetKeyCode()
的值,看看它是否爲ctrl,因爲按鍵事件不是被解僱。我應該將鍵盤按鍵綁定到別的地方嗎?檢測任務欄菜單上的ctrl單擊
class TBI(wx.TaskBarIcon):
TBMENU_CTRLCLICK= wx.NewId()
def __init__(self,frame):
wx.TaskBarIcon.__init__(self)
self.frame=frame
self.ctrl_down=False
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
self.Bind(wx.EVT_MENU, self.OnCtrlClick, id=self.TBMENU_CTRLCLICK)
def CreatePopupMenu(self):
menu= wx.Menu()
if self.ctrl_down:
menu.Append(self.TBMENU_CTRLCLICK, "Ctrl Click")
menu.AppendSeparator()
menu.Append(wx.ID_EXIT, "Exit")
return menu
def OnKeyDown(self,event):
self.ctrl_down=True
event.Skip()
def OnKeyUp(self,event):
self.ctrl_down=False
event.Skip()