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 Overflow
🌐
PyAutoGUI
pyautogui.readthedocs.io › en › latest › keyboard.html
Keyboard Control Functions — PyAutoGUI documentation
To press these keys, call the press() function and pass it a string from the pyautogui.KEYBOARD_KEYS such as enter, esc, f1.
Discussions

Enter key not being recognized by web page
When I physically press enter or use windows virtual keyboard, that conditional is true and the search proceeds. How do I get pyautogui to send the correct keyboard input for enter? I have no control over the programming of that web page. Therefore, I just do a workaround by having the mouse ... More on github.com
🌐 github.com
0
June 9, 2024
Keyboard press in game not working
I am writing this automation for a game, but keyboard function are not working. In game if you press certain key, inside game it will open its own dialog. I try all this function but none working: ... More on github.com
🌐 github.com
5
June 20, 2018
Pyautogui doesn't want to press enter in game
So i'm making a Roblox bot (don't worry not a scam bot) that says something in chat using pyautogui. It joins a Roblox game and types it's message in chat but for some reason it doesn't want to press enter. It presses all the other keys without an issue but not enter. More on reddit.com
🌐 r/learnpython
3
1
March 21, 2020
PyAutoGui module problem... buttons pressed have no effect on single player video games!
It's probably the game blocking the key press. Try running your script as admin More on reddit.com
🌐 r/learnpython
4
2
December 25, 2015
🌐
GitHub
github.com › asweigart › pyautogui › issues › 862
Enter key not being recognized by web page · Issue #862 · asweigart/pyautogui
June 9, 2024 - I inspected the page search box with the developer console in Chrome and Edge with monitorEvents($0). The pyautogui enter key input is recognized as a keyboard event, but it’s different from what the web page was expecting. See below. Also I’m not an experienced programmer… · Physical keyboard press for ‘enter’ KeyBoardEvent{isTrusted: true, key: 'Enter', code: 'Enter',Location: 0, ctrlKey: false, …} Pyautogui keyboard ‘enter’ KeyBoardEvent{ isTrusted: true, key: 'Enter', code: '', Location: 0, ctrlKey: false, ...}
Author   gds13z240
🌐
GitHub
github.com › asweigart › pyautogui › issues › 583
can not press enter · Issue #583 · asweigart/pyautogui
i have used these varieties of codes: pyautogui.press('enter') pyautogui.keyDown('enter') pyautogui.keyDown('enter') pyautogui.keyUp('enter') pyautogui.write(['enter']) code runs fine but never presses enter i am also actually testing it...
Author   ghost
🌐
CodersLegacy
coderslegacy.com › home › python › pyautogui keyboard automation
PyAutoGUI Keyboard Automation - CodersLegacy
May 25, 2022 - On the other hand, passing this string to the press() function will press the actual “enter” key on your keyboard. That’s a pretty big difference right there. import pyautogui pyautogui.write("Hello World", interval = 0.1) pyautogui.press("enter") pyautogui.write("Hello World", interval = 0.1) pyautogui.press("enter") pyautogui.write("Hello World", interval = 0.1)
🌐
GitHub
github.com › asweigart › pyautogui › issues › 235
Keyboard press in game not working · Issue #235 · asweigart/pyautogui
June 20, 2018 - I am writing this automation for a game, but keyboard function are not working. In game if you press certain key, inside game it will open its own dialog. I try all this function but none working: pyautogui.press('b'), pyautogui.keyDown('b') and pyautogui.keyUp('b') but none seems to work.
Author   mtkilic
🌐
Snyk
snyk.io › advisor › pyautogui › functions › pyautogui.press
How to use the pyautogui.press function in PyAutoGUI | Snyk
def keep_delete_model(key='k'): import pyautogui click(200, 1300) # click(80, 1020) pyautogui.press(key) pyautogui.press('enter')
Find elsewhere
🌐
Reddit
reddit.com › r › learnpython › comments › fmcy12 › pyautogui_doesnt_want_to_press_enter_in_game
Pyautogui doesn't want to press enter in game : r/learnpython
March 21, 2020 - So i'm making a Roblox bot (don't worry not a scam bot) that says something in chat using pyautogui. It joins a Roblox game and types it's message in chat but for some reason it doesn't want to press enter. It presses all the other keys without an issue but not enter.
🌐
Read the Docs
pyautogui.readthedocs.io
Welcome to PyAutoGUI’s documentation! — PyAutoGUI documentation
There is also a pyautogui.DARWIN_CATCH_UP_TIME setting which adds an additional delay on macOS after keyboard and mouse events, since the operating system appears to need a delay after PyAutoGUI issues these events. It is set to 0.01 by default, adding an additional hundredth-second delay. ... This documentation is still a work in progress.
🌐
Reddit
reddit.com › r/learnpython › pyautogui module problem... buttons pressed have no effect on single player video games!
r/learnpython on Reddit: PyAutoGui module problem... buttons pressed have no effect on single player video games!
December 25, 2015 -

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...

🌐
GitHub
github.com › asweigart › pyautogui › issues › 796
Really Strange Keyboard Issue on macOS · Issue #796 · asweigart/pyautogui
Everything works perfectly until I have an up/down/left/right press. I've made a small script to show what I am experiencing. import pyautogui import pyperclip import time time.sleep(3) # gives me 3 seconds to set cursor in notepad for i in range(1, 3): pyperclip.copy(i) time.sleep(1) # sleep for safety between copy and paste pyautogui.hotkey('command', 'v', interval=0.1) pyautogui.press('enter') time.sleep(1) # sleep for safety between iterations for i in range(1, 3): pyperclip.copy(i) time.sleep(1) # sleep for safety between copy and paste pyautogui.hotkey('command', 'v', interval=0.1) pyautogui.press('down') time.sleep(1) # sleep for safety between iterations
Author   ghost
🌐
PyAutoGUI
pyautogui.readthedocs.io › en › latest › quickstart.html
Cheat Sheet — PyAutoGUI documentation - Read the Docs
Key presses go to wherever the keyboard cursor is at function-calling time. >>> pyautogui.typewrite('Hello world!\n', interval=secs_between_keys) # useful for entering text, newline is Enter
🌐
Medium
medium.com › @dattanikaran25 › get-started-with-pyautogui-75962f3088ce
Get Started With PyAutoGUI 🐍. Python + PyAutoGUI | by Dattanikaran | Medium
October 15, 2023 - PyAutoGUI allows you to simulate keyboard input by typing text. You can use the typewrite() function. ... This simulates typing the specified text. ... You can also simulate individual keypresses. For example, to simulate pressing the “Enter” key, use the press() function:
🌐
Reddit
reddit.com › r/learnpython › pyautogui is pressing keys too fast/missing out some keys
r/learnpython on Reddit: PyAutoGUI is pressing keys too fast/missing out some keys
May 16, 2023 -

I'm writing a program that

  1. navigates to an open window

  2. clicks to input text into a box

  3. presses shift and then enter to load some information onto a page

  4. 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') # close
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › using the raspberry pi › troubleshooting
pyautogui to emulate mouse & keyboard on RPi 5 - Raspberry Pi Forums
import pyautogui as pygu from time ... 5:47 am · Sat Apr 20, 2024 6:59 am · Pyautogui does not work correctly with Wayland-> You can try to switch to x11 in the raspi config....
🌐
Reddit
reddit.com › r/learnpython › having trouble with pyautogui
r/learnpython on Reddit: having trouble with pyautogui
June 23, 2021 - So I can get it to work once, I just don't understand why it won't continue to perform the functions. Right in the documentation, there is this: For example, to press the left arrow key three times while holding down the Shift key, call the following: pyautogui.keyDown('shift') # hold down the shift key pyautogui.press('left') # press the left arrow key pyautogui.press('left') # press the left arrow key pyautogui.press('left') # press the left arrow key pyautogui.keyUp('shift') # release the shift key
🌐
GitHub
github.com › asweigart › pyautogui › issues › 687
hotkey not working on mac Monterey 12.2.1 · Issue #687 · asweigart/pyautogui
April 11, 2022 - import pyautogui pyautogui.hotkey('command', 'c') outputs a single 'c' being typed
Author   nerdielol
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 2e › chapter20
20 controlling the keyboard and mouse with gui automation
Not all keys are easy to represent with single text characters. For example, how do you represent SHIFT or the left arrow key as a single character? In PyAutoGUI, these keyboard keys are represented by short string values instead: 'esc' for the ESC key or 'enter' for the ENTER key. Instead of a single string argument, a list of these keyboard key strings can be passed to write(). For example, the following call presses the A key, then the B key, then the left arrow key twice, and finally the X and Y keys: