I wish to send keystrokes, including shift,ctrl,cmd,opt combinations, to OSX. Basically anything that I can do on the keyboard.
How do I accomplish this?
I would also like to send mouse clicks. Is this a separate enquiry?
You can use the CGEvent
APIs, such as CGEventCreateKeyboardEvent
followed by CGEventPost
.
Using applescript you can send any key you want. Here is an example of using various methods of sending keys :
tell application "System Events"
keystroke "h"
keystroke (ASCII character 63)
key code 38 -- Applescript's reference to keys
keystroke "k" using {command down, control down}
end tell
With GUI scripting you can also send mouse clicks. These tend to be a little more involved. The following is an applescript I wrote to disable an option in System Preferences related to the Trackpad and three finger double tap.
tell application "System Preferences"
set current pane to pane "Trackpad"
tell application "System Events"
tell process "System Preferences"
if window 1's tab group 1's checkbox 3's value is 1 then
tell window 1's tab group 1's checkbox 3 to click
end if
end tell
end tell
quit
end tell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With