python closes when it does pyautogui.press('enter')

Viewed 120

I am making a bot that can type but when it presses enter the program closes while it is not done

import sched, time, pyautogui
s = sched.scheduler(time.time, time.sleep)
def do_something(sc): 
    pyautogui.write('hello')
    pyauogui.press('enter')
    s.enter(30, 1, do_something, (sc,))

s.enter(5, 1, do_something, (s,))
s.run()

I found this code on a forum to create a loop that waits x time before repeats but it closes when it comes to the line pyauogui.press('enter') why is this?

2 Answers

I ran your code and got the same issue, then I looked at it and in line 5 you have a type "pyaugui.press('enter')" as you may guess by now it is spelt pyautogui as seen in the line above and in your import statement.

# Fixed Code
import sched, time, pyautogui
s = sched.scheduler(time.time, time.sleep)
def do_something(sc):
    pyautogui.write('hello')
    # Your type was here
    pyautogui.press('enter')
    s.enter(30, 1, do_something, (sc,))

s.enter(5, 1, do_something, (s,))
s.run()

I've tested and it now runs. I can recommend getting a IDE or text editor with built in error highlighting.

Examples:

Visual studio code (Microsoft) - https://code.visualstudio.com/

Visual studio (Microsoft) - https://visualstudio.microsoft.com/

PyCharm (Jetbrains) https://www.jetbrains.com/pycharm/

All of these are free (PyCharm has a paid version)

You just did a little mistake... Look at your source code properly...

pyauogui.press('enter')

while there's no function called pyauogui. It should be pyautogui. That's a typo mistake...

import sched, time, pyautogui
s = sched.scheduler(time.time, time.sleep)
def do_something(sc): 
    pyautogui.write('hello')
    pyautogui.press('enter')
    s.enter(30, 1, do_something, (sc,))

s.enter(5, 1, do_something, (s,))
s.run()
Related