I've started learning python recently and I'm trying to write an app that moves the mouse so my computer doesn't go to sleep. I've created a while loop where the mouse is constantly moving and I want to break out of the loop with the 'any' key, I know I can have a pause in the movement so I could just click a button to stop the process but now I've run into this problem I want to solve it. Here is my code so far:
from tkinter import *
import pyautogui
root = Tk()
def click():
while True:
pyautogui.moveRel(100, 0, 2)
pyautogui.moveRel(0, 100, 2)
pyautogui.moveRel(-100, 0, 2)
pyautogui.moveRel(0, -100, 2)
title = Label(root, text="mouse mover")
title.pack()
move = Button(root, text="begin", command=click)
move.pack()
root.mainloop()
I know it's a bit overkill and I could just run the script from terminal but it's all about the learning process!
I've tried if, else, try, except, while True/False, keyboardinterrupt (which doesn't seem to work from the app window in 'def click' and around 'move.pack/root.mainloop' and even 'move =...' and keyboard.is_pressed with sudo from terminal (which as far as I'm aware defeats of object of my app), not sure what is supposed to go where anymore and I'm rather ironically going round in circles trying to find a solution. feel like I'm missing something obvious or I've put something in the wrong place.
my beginner brain hurts please help