Python Forum

Full Version: Need help with infinite loop & making hotkeys/shortcuts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Before you ask, yes i'm new, i started coding like today, and no i have no idea what i'm doing.

I want to be able to run my code on an infinite loop, and be able to toggle it on/off using key combos (leftalt + M specifically) but whatever solution i've found on youtube is either ancient, not what i'm looking for or straight up doesn't work.

import time
import random
import pyautogui

pyautogui.moveTo(1560, 970, duration=random.uniform(0.1,0.14))
pyautogui.mouseDown(button='left', duration=(5))
time.sleep(5)
pyautogui.mouseUp(button='left')
pyautogui.mouseDown(button='left')
pyautogui.moveTo(1060, 500, duration=random.uniform(0.08,0.16))
pyautogui.moveTo(1170, 500, duration=random.uniform(0.08,0.16))
pyautogui.moveTo(1280, 500, duration=random.uniform(0.08,0.16))
pyautogui.mouseUp(button='left')
this is the code that i want to run on an infinite loop with a key combination toggle.
Have you looked at pynput for doing the hotkeys?