Python 检测任务栏菜单上的ctrl单击

Python 检测任务栏菜单上的ctrl单击,python,wxpython,Python,Wxpython,下面的代码是我的任务栏图标类的简化版本,我没有检查GetKeyCode()值以查看它是否为ctrl,因为没有触发按键事件。我应该把按键绑定到其他地方吗 class TBI(wx.TaskBarIcon): TBMENU_CTRLCLICK= wx.NewId() def __init__(self,frame): wx.TaskBarIcon.__init__(self) self.frame=frame self.ctrl_do

下面的代码是我的任务栏图标类的简化版本,我没有检查
GetKeyCode()
值以查看它是否为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()
这样使用:

右键单击任务栏图标,然后尝试按住ctrl键以查看其操作

import wx

class TBI(wx.TaskBarIcon):
    def __init__(self):
        wx.TaskBarIcon.__init__(self)
        icon = wx.ArtProvider.GetIcon(wx.ART_FILE_OPEN, wx.ART_TOOLBAR)
        self.SetIcon(icon, "Icon")
        self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.on_right_up)

    def on_right_up(self, event):
         if wx.GetKeyState(wx.WXK_CONTROL):
             print 'ctrl was pressed!'


app = wx.App(redirect=False)
icon = TBI()
app.MainLoop()