I want to build a program that moves a mouse in a square and have a delay between each action so it doesn't go crazy.
The only way I know of right now is time.sleep()
. The only problem is that I want to terminate the program with a keypress but, while the program sleeps, it doesn't take in any input. So the key must be pressed down as long as it takes for the next loop iteration to be registered. My goal is to terminate it at any (even when sleeping) moment. The only way I could imagine fixing it would be to make my program multi-threaded and ending the thread via a separate thread or "master thread" by killing the working one.
Please let me know what you think.