il16ya
il16ya

Reputation: 31

How to press Enter using PyAutoGUI

please tell me how to press the Enter button using the PyAutoGUI library. I've tried everything, but nothing is pressed. Can you suggest how to do it?

Upvotes: 3

Views: 33858

Answers (5)

Oblivion
Oblivion

Reputation: 1

I had a similar problem.

This wasn't working: pyautogui.write('enter')

But this worked: pyautogui.write(['enter'])

I'm using VS Code on Windows 10.

Cheers.

Upvotes: 0

hilon jionh
hilon jionh

Reputation: 1

I had a problem like you,but i solved it by turning the keyboard language from Chinese to English ,so the enter_press is useful to send message but not write message

Upvotes: 0

Chris J
Chris J

Reputation: 461

on windows I could never get Pyautogui key presses to work. I had to use pywinauto instead. I would still use pyautogui for finding images and typing our characters but used pywinauto to press keys.

from pywinauto.keyboard import send_keys
send_keys('{ENTER}')

https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html

Upvotes: 0

user18627525
user18627525

Reputation:

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

Upvotes: 4

jarinlima
jarinlima

Reputation: 86

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

Upvotes: 5

Related Questions