Created
October 12, 2010 13:43
-
-
Save nzaillian/622181 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) |
keystroke uses a string of the pressed key as argument
osascript -e 'tell application "System Events" to keystroke "K" using command down'
sends CMD-K
osascript -e 'tell application "System Events" to key code 126 using command down'
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for 'up' & 'down' key what key value should be passed..?