I was trying around with making my own GUI and combining it with some pyautogui stuff and was trying in this case to create a button that moves the mouse to the first position, then waits there until any button on the keyboard is pressed and only then continues moving to the next position.
My problem is that it works, but only if I manually select the Terminal and then press any key to continue the code. However, I want it to continue without me having to manually select the Command Prompt / Terminal as I might also add later mouse clicks with pyautogui and select different windows with it.
I tried a few different methods such as using input() / msvcrt.getch() / keyboard.wait() but all of them ended with the same problem.
(I also tried converting the .py into a .exe in hopes that it might work but to no avail.)
Is there any way to pause it and let it continue after pressing any key without having to select the Terminal myself?
(Yes I'm still very new to coding and English is not my first language, so sorry if some things are not so easy to understand)
Edit: I see there has been some misunderstanding about what I am trying to achieve and what exactly my problem is so I'm going to try to explain it in a bit more detail.
I want to make an Interface with multiple buttons. Each button is supposed to run a function to automate simple things like a sequence of mouse clicks/key presses.
A different problem I was running into with something inside the sequence of clicks the button was supposed to do, was with my script not being able to detect if the other program it was supposed to click in was fully loaded yet or not. This is why I want my code to stop in between and only continue after I press a key.
The problem is after moving the mouse and clicking inside the different programs it is supposed to wait for a key press by me and then continue but it only listens to my key presses while my interface is still selected, once it clicks inside the different program it won't continue.
I saw a suggestion about using a keylogger to always listen to my keys but I couldn't yet figure out how to integrate such one within my script. Gonna look more into those when I have more time again.
Sorry if I'm not good at explaining things properly.
import customtkinter, pyautogui, time
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
def tryout():
pyautogui.moveTo(1632,133)
pyautogui.leftClick()
print("Waiting for Key press...")
input()
print("Continuing...")
pyautogui.moveTo(1792, 1076)
pyautogui.leftClick()
root = customtkinter.CTk()
root.geometry("900x550")
frame = customtkinter.CTkFrame(master=root)
frame.pack(pady=20, padx=60, fill="both", expand=True)
button = customtkinter.CTkButton(master=frame, text="Test", command=tryout)
button.pack(pady=12, padx=10)
root.mainloop()
There is a way to pause your execution with the use of a breakpoint(), it is built into python, here is the documentation pdb. Please note that this is more of debugging tool, I am note entirely sure if this is what you are asking for. You can set multiple breakpoints in your code, then use continue(continue is an actual command you would run) to move to the next breakpoint() in your code. When you are done, you can use exit() to break out of the debugger. Try replacing it here in place of your input().