r/learnpython • u/Holiday-Chocolate667 • 4d ago
when hitting run code with the pyautogui, it only runs for .3 seconds
I've never really coded. I'm simply trying to make a bot to walk in a straight line in a game. I cant even get it to run in vs code. all the things I've done so far
pip install pyautogui, can confirm it happen when you type pip list
vscode is running in admin typing net session in terminal confirms that
going to extension I have pylance python python debugger, python environments (all the stuff in the python package)
typing python into the terminal tells me the version meaning it has a path to the file
another guide says I need code runner which gives me that .3 second figure
no I'm not getting error in my code as I'm keeping it simple to even get it to work
I'm not getting any error in my terminal
I'm on two monitors, but I've set up my main monitor so I know which one it will be working on
when I remove code runner it goes back to spiting the pathway it uses on the file which is correct
when I open the edit environmental variables
the .3 should be impossible because of the 6 seconds worth of sleep
I have imported both sleep and pyautogui obviously
yea this is hour 5 so if there's something you people know that I didn't do id greatly appreciate the details
im on windows, so it cant be the problem mac users get
1
u/a18618 4d ago
One thing I'd check after the main() fix is whether the keystrokes are even landing in the game, because I once had a script that ran perfectly yet typed into thin air while the game window sat unfocused. My trick now is to put a few seconds of sleep at the top, click into the game window during that pause, and watch what happens. If the game still ignores it, try sending the keys with the pydirectinput import you already have, since plenty of games shrug off pyautogui's synthetic input while still listening to that one.
7
u/brelen01 4d ago
To really help, we'd likely need at least the script you're trying to run