5

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?

Roger
  • 131
  • 1
  • 2
  • 4

3 Answers3

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.

zeekay
  • 49,858
  • 13
  • 107
  • 105
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,258
  • 13
  • 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,417
  • 3
  • 20
  • 29