0

im working with tkinter and win32api. I've declared the next function:

def on_press():
        leftBtn = 0x01
        key = win32api.GetKeyState(leftBtn)
        if key < 0:
                print("Left click pressed")
                time.sleep(0.1)
                root.after(100,on_press)
        
root.after(100,on_press)

Already tried to do the .after to don't have two infinite loops but still crashing. Any answer??

Git to my project (not finished...): https://github.com/alexcibubins/NoRecoilScript-notFinished-.git

General Grievance
  • 4,259
  • 21
  • 28
  • 43
RuthIsRoot
  • 145
  • 1
  • 7
  • Remove the `while True` loop. Also you might want to take a look at [this](https://stackoverflow.com/a/459131/11106801) – TheLizzard Sep 06 '21 at 10:29
  • Move the `root.after(100,on_press)` one level down. Right now it only runs if the left mouse button is pressed. – TheLizzard Sep 06 '21 at 11:02

1 Answers1

0
def on_press():
        leftBtn = 0x01
        key = win32api.GetKeyState(leftBtn)
        if key < 0:
                print("Left click pressed")
                time.sleep(0.1)
        root.after(100, on_press)
        
root.after(100,on_press)
TheLizzard
  • 6,523
  • 2
  • 10
  • 26
RuthIsRoot
  • 145
  • 1
  • 7