0

I would like Python to run the following code in a loop e.g.

while(True): 
   pyautogui.moveTo(844,222)
   pyautogui.click(interval=2)

until ANY button is pressed so that the logic can continue as follows:

if keyboard.is_pressed("1"):
    pyautogui.moveTo(1021,308)
    pyautogui.click()
    pyautogui.moveTo(958,771)
    pyautogui.click()
    pyautogui.moveTo(961,531)
    
if keyboard.is_pressed("2"):
    pyautogui.moveTo(1446,308)
    pyautogui.click()
    pyautogui.moveTo(958,771)
    pyautogui.click()
    pyautogui.moveTo(961,531)
petezurich
  • 9,280
  • 9
  • 43
  • 57
  • This can be done using the `pynput` library. Reference: [pynput](https://pypi.org/project/pynput/), Also, there is no way to do this in `pyautogui` – Anshumaan Mishra Mar 25 '22 at 15:40
  • Could you please give an example of how this would work ? – user13794497 Mar 25 '22 at 15:48
  • Unfortunately, I do not have experience with this library, you can see this question for reference https://stackoverflow.com/questions/39235454/how-to-know-if-the-left-mouse-click-is-pressed – Anshumaan Mishra Mar 25 '22 at 15:50

1 Answers1

-1

This should work :)

!pip install keyboard
import keyboard

while True:
    # do your stuff
    if keyboard.read_key() != "":
        break

#continu here
Ren
  • 157
  • 12