Use pyautogui.press(“enter”) or pyautogui.hotkey(“enter”)
for pressing 3 times:
use pyautogui.press(“enter”, presses=3)
or
for i in range(3):
pyautogui.press(“enter”)
for pressing lots of keys:
pyautogui.press([“enter”, “shift”])
or
for key in [“enter”, “shift”]:
pyautogui.press(key)
dispatch user holding down the key until keyup:
pyautogui.keyDown(“enter”)
and for keyup:
pyautogui.keyUp(“enter”)
and also one thing, if you’re used keyDown, you can still use pyautogui.press(“enter”) too :D
If you want to know more go to https://pyautogui.readthedocs.io/en/latest/keyboard.html
Answer from user18627525 on Stack OverflowUse pyautogui.press(“enter”) or pyautogui.hotkey(“enter”)
for pressing 3 times:
use pyautogui.press(“enter”, presses=3)
or
for i in range(3):
pyautogui.press(“enter”)
for pressing lots of keys:
pyautogui.press([“enter”, “shift”])
or
for key in [“enter”, “shift”]:
pyautogui.press(key)
dispatch user holding down the key until keyup:
pyautogui.keyDown(“enter”)
and for keyup:
pyautogui.keyUp(“enter”)
and also one thing, if you’re used keyDown, you can still use pyautogui.press(“enter”) too :D
If you want to know more go to https://pyautogui.readthedocs.io/en/latest/keyboard.html
Short answer
pyautogui.press('enter')
or
pyautogui.write('\n')
source
If not working, could be because the mouse cursor is not on the desired place, maybe you would need to first click over the app you want to enter with for example pyautogui.click(100, 200); where (100,200) are the X,Y coordinates of screen, you will need to locate where do you need that enter.
For more details, you could see this
Enter key not being recognized by web page
Keyboard press in game not working
Pyautogui doesn't want to press enter in game
PyAutoGui module problem... buttons pressed have no effect on single player video games!
For anyone finding their way to this post. The answer is essentially that this can't be done in this fashion due to how most games interpret keypresses. A working system is shown here: Simulate Python keypresses for controlling a game
None of \n nor return works to me, so I have to use pydirectinput: https://github.com/learncodebygaming/pydirectinput
Install it using pip install pydirectinput, then import it and use as the README. Note that the file also needs to run as admin.
hey guys... PyAutoGui module works fine with the clicks... though I am having a very frustrating problem tbh... The press(), typewrite(), pressDown(), pressUp(), they all work fine in text documents or on the desktop. but pressing them have no effect on single player video games... the same thing happens if I use import instead of from...
from pyautogui import *
press('m')
typewrite('m')none of those above work... though the map shows up if I just press M... thanks...
edit: If it helps, I am using a laptop keyboard and on Windows 7...
I'm writing a program that
-
navigates to an open window
-
clicks to input text into a box
-
presses shift and then enter to load some information onto a page
-
presses shift 6 times and then enter to navigate to the button on screen that will download a file
The program is failing in steps 3 and 4, where it will skip out on pressing some keys, or will press enter before pressing shift 6 times, so it navigates to the wrong button.
I've tried setting pyautogui.PAUSE to 1-5 seconds, but I still have the same issue.
I'm using a mac, if relevant.
This is my code:
def entertext(name):
pyautogui.click(350, 200) # activate the window
pyautogui.click(695, 495) # click the text input box
pyautogui.press('backspace', presses = len(name)) # clear previous input
pyautogui.write(name) # enter new text input
pyautogui.press('shift')
pyautogui.press('enter') # load the information on the page
pyautogui.press('shift', presses=6) # navigate to download button
pyautogui.press('enter') # enter to download
pyautogui.press('shiftleft') # navigate to close button
pyautogui.press('enter') # closeI'm trying to create a simple bot that controls the keyboard. I was having trouble installing pyautogui, so eventually a friend just sent me the source code to put into the folder I was working with.
Here is the code I have so far:
import pyautogui, time
time.sleep(5)
f = open("beemovie", 'r')
for word in f:
pyautogui.typewrite(word)
pyautogui.press("enter")
Whenever I run the scipt it says that typewrite is not a valid function of pyautogui. What should I do?