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,555
  • 31
  • 31
  • 45
RuthIsRoot
  • 135
  • 2
  • 8
  • 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
  • 7,248
  • 2
  • 11
  • 31
RuthIsRoot
  • 135
  • 2
  • 8