Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:57:33+00:00 2026-05-27T22:57:33+00:00

Hello i am wondering if there is a way to check if a certain

  • 0

Hello i am wondering if there is a way to check if a certain key is being held down.

Here is an example of the situation

self.button2.Bind(wx.EVT_LEFT_DOWN, self.clickedbutton)
def clickedbutton(self, e):
    if (Control is held down while the button has been clicked):
        print "it works"

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:57:34+00:00Added an answer on May 27, 2026 at 10:57 pm

    The problem with using only wx for this is that you need a KeyEvent to access the actual state of the control key. Since you need this information outside of such an event you need to keep track of it manually, and the problem with that is that it is easy to miss a KeyEvent since only focused controls get them and you can’t count on them propagating.

    The foolproof way would be to utilize some platform specific way of querying this information, if you are on windows look in to pyHook or win32api for this.

    In some cases though the wx only approach can work and here is how you do it:

    import wx
    
    
    class Example(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None)
    
            btn = wx.Button(self, label="press me")
            self.Sizer = wx.BoxSizer()
            self.Sizer.Add(btn)
    
            self.ctrl_down = False
    
            self.Bind(wx.EVT_KEY_UP, self.OnUpdateCtrlState)
            self.Bind(wx.EVT_KEY_DOWN, self.OnUpdateCtrlState)
            btn.Bind(wx.EVT_KEY_UP, self.OnUpdateCtrlState)
            btn.Bind(wx.EVT_KEY_DOWN, self.OnUpdateCtrlState)
            btn.Bind(wx.EVT_BUTTON, self.OnButton)
    
        def OnUpdateCtrlState(self, event):
            self.ctrl_down = event.ControlDown()
            print self.ctrl_down
            event.Skip()
    
        def OnButton(self, event):
            if self.ctrl_down:
                wx.MessageBox("control down")
    
    
    app = wx.App(False)
    app.TopWindow = f = Example()
    f.Show()
    app.MainLoop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello wondering if there is an easier way to display odd / even numbers.
Hello I was wondering if there is a nice way to find out what
Hello I am wondering if there is a way to change a string value
Hello Python experts, I am wondering if there is any shorter way to assign
Just wondering if there is a way around this (or if it is even
all, I was just wondering if there was a logistical way to not reassign
Hey I was just wondering if there is a way to set JTextField width
I'm wondering if there is a way to call variable functions with namespaces. Basically
hello i was wondering what is the best way to upload a video to
I was wondering if there is a way to disallow the following in javascript:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.