'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?
Solution 1:[1]
Short answer
pyautogui.press('enter')
or
pyautogui.write('\n')
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
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jarinlima |
| Solution 2 |
