I'm creating test automation for an application. I am using a testing tool to do most of the testing, but in order to get to that point I first need to automate one 'enter' key click in Python. I am using a mac, so pywin32 is not available. Any suggestions?
Asked
Active
Viewed 4,938 times
4 Answers
1
Appscript makes this pretty easy:
from appscript import app
app('System Events').keystroke('\r')
This will send the keystroke to whichever application is in front.

Zach Kelling
- 52,505
- 13
- 109
- 108
-
1Doesn't OSX also use `\n` nowadays? – ThiefMaster Jun 17 '11 at 23:47
-
1Behavior might vary, but I just tested \n with this comment submission, and only \r worked. – Zach Kelling Jun 18 '11 at 00:02
0
import time
from pynput.keyboard import Key, Controller
keyboard = Controller()
# Press and release space
keyboard.press(Key.space)
keyboard.release(Key.space)

Pegasus
- 1,398
- 15
- 20
0
By looking around, I found the answer to your question in another question similar to yours.
You're going to have to change up the code a little bit so that it's 'Enter' not Ctrl-r, but it should be easy.
Hope this helps!

Community
- 1
- 1

Jeff Gortmaker
- 4,607
- 3
- 22
- 29
0
import atomacos
def send_multiple_keys(app,keychr):
"""Send multiple key character(Keyboard Key) with no modifiers."""
""" app here is the bundle id of the application being used"""
application=atomacos.getAppRefByBundleId(app)
application.activate()
application.sendKeys(keychr)
atomacos can be used for automation on mac OS https://pypi.org/project/atomacos/

ravi kumar
- 1
- 2