R
R
Rich2021-11-06 07:10:12
Python
Rich, 2021-11-06 07:10:12

Endless loop with button exit, how to implement?

from ahk import AHK, Hotkey
import time
import keyboard

ahk = AHK()

if keyboard.is_pressed('Page_Up'):
    while True:

        ahk.key_press('TAB')

        if keyboard.is_pressed('Page_Down'):
            print("Stoping...")
            break


As you can see from the code. I want to make a script, something similar to AHK, start and stop on a button.
Logically, I click on the button, there is an endless loop with pressing "TAB", and at any time I can stop the script by pressing the PageDown button, but something didn't work) Tell me how to fix or fix something.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denisca Gareev, 2021-11-06
@oldzhmih

I think you wanted to do something like this

from ahk import AHK, Hotkey
import time
import keyboard

ahk = AHK()

while True:
  if keyboard.is_pressed('Page_Up'):
      while True:

          ahk.key_press('TAB')

          if keyboard.is_pressed('Page_Down'):
              print("Stoping...")
              break

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question