0

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
else:
    #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?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Reverend Jim
0

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

0

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.HideFiles(self.Prev)
            self.Prev = None
            
        if self.Curr.Show:
            #print "HIDE",self.Curr.GetName()
            self.HideFiles(self.Curr)
            self.Curr = None
        else:
            #print "SHOW",self.Curr.GetName()
            self.ShowFiles(self.Curr)
            self.Prev = self.Curr

        self.RefreshViewer()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.