Created
October 12, 2010 13:43
-
-
Save nzaillian/622181 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Found myself needing to emulate key presses in an application on OS X. The solution was the following:""" | |
import os | |
def press_key(key): | |
cmd = "osascript -e 'tell application \"System Events\" to keystroke \"" + key + "\"'" | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
keystroke uses a string of the pressed key as argument
sends CMD-K
sends CMD-Cursor Up Code key (lang independent: 123 cursor left , 124 cursor right, 125 cursor down, 126 cursor up)
here a nice reference i found:
https://eastmanreference.com/complete-list-of-applescript-key-codes