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 6605981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:20:52+00:00 2026-05-25T19:20:52+00:00

I’m trying to create a hotkey toggle(f12) that will turn on a loop when

  • 0

I’m trying to create a hotkey toggle(f12) that will turn on a loop when pressed once then turn that loop off when pressed again. The loop is a mouse click every .5 seconds when toggled on. I found a recipe for a hot keys on the wxpython site and I can get the loop to turn on but can’t figure a way to get it to turn off. I tried created a separate key to turn it off without success.
The mouse module simulates 1 left mouse click.

Here’s my current code:

import wx, win32con, mouse

from time import sleep

class Frameclass(wx.Frame):

    def __init__(self, parent, title):
            super(Frameclass, self).__init__(parent, title=title, size=(400, 200))
            self.Centre()
            self.Show()
            self.regHotKey()
            self.Bind(wx.EVT_HOTKEY, self.handleHotKey, id=self.hotKeyId)
            self.regHotKey2()
            self.Bind(wx.EVT_HOTKEY, self.handleHotKey2, id=self.hotKeyId2)
    def regHotKey(self):
            """
            This function registers the hotkey Alt+F12 with id=150
            """
            self.hotKeyId = 150
            self.RegisterHotKey(self.hotKeyId,win32con.MOD_ALT, win32con.VK_F12)#the key to watch for
           
            
    def handleHotKey(self, evt):
            loop=True
            print('clicks on')
            while loop==True:
            #simulated left mouse click
                 mouse.click()
                 sleep(0.50)
                 
                 x=self.regHotKey2()
                 print(x)
                 if x==False:
                         print('Did it work?')
                         break
            else:
                 pass

———————second keypress hotkey——–

    def regHotKey2(self):
            self.hotKeyId2 = 100
            self.RegisterHotKey(self.hotKeyId2,win32con.MOD_ALT, win32con.VK_F11)
                    
    def handleHotKey2(self, evt):
            return False
            loop=False
            print(loop)
                         

if name==’main‘:

showytitleapp=wx.App()
#gotta have one of these in every wxpython program apparently
Frameclass(None, title='Rapid Clicks')
showytitleapp.MainLoop()
#infinite manloop for catching all the program's stuff
  • 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-25T19:20:52+00:00Added an answer on May 25, 2026 at 7:20 pm

    Your loop variable is locally scoped inside of handleHotKey. Because regHotKey2 is bound to handleHotKey2, which is a different listener, the event it generates will never affect the loop within handleHotKey. Besides that, the first line of handleHotKey2 is a return value, which will quit the function before the following two lines are executed.

    Out of curiousity, what output does x=self.regHotKey2(); print(x) produce?

    Try defining your loop variable at the class level instead of the function level –

    def __init__(self, parent, title):
        ... your original stuff ...
        self.clicker_loop = False
    

    and then modifying that loop in your handlers –

    def handleHotKey(self, evt):
        self.clicker_loop = True
        while self.clicker_loop:
            ... do the thing ...
    
    def handleHotKey2(self, evt):
        self.clicker_loop = False
    

    Please try this and tell me if this works.

    And maybe this will toggle the loop from the same hotkey…

    def handleHotKey(self, evt):
        if self.clicker_loop:
            self.clicker_loop = False
        else:
            self.clicker_loop = True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.