I have an app I wrote in Python/wxPython. When I click a button, the action that is taken will depend on whether or not a modifier key (such as CTRL) is currently pressed. I can't toggle a swich based on a keypress event (eg ctrldown = True or False) because the form may not have focus continuously. Ideally, the button click code should be something like

if ctrldown:
    #ctrl key is pressed - do one action
    #ctlr key is not pressed - do something else

Is there any way of checking the current status of the keys like CTRL, SHIFT, ALT, etc?

MouseEvent (you are talking mouse events, right?) has methods AltDown(), ControlDown(), ShiftDown(), MetaDown()...

It's not a mouse event. it's a buttonClick event and the ControlDown method doesn't apply there. I tried the following:

def OnButtonClick(self,event):
        #get the name of the image set from the button

        self.Curr = event.EventObject
        #hide the previous set
        if not event.ControlDown() and self.Prev != None and self.Prev != self.Curr:
            #print "hide",self.Prev.GetName()
            self.Prev = None
        if self.Curr.Show:
            #print "HIDE",self.Curr.GetName()
            self.Curr = None
            #print "SHOW",self.Curr.GetName()
            self.Prev = self.Curr

This article has been dead for over six months. Start a new discussion instead.