I have been trying to figure this out for a while now and was wondering if you could help.
With AppleScript, there are two hidden functions available in the System Events application which allow you to push a key down (keeping it down while other actions, like clicking are done), and then bringing the key back up again.
e.g. see the answer here Applescript to run Detect Displays whereby "key up" and "key down" are used while a click is being performed.
But for the sake of this example, let's use something very simple, a Save shortcut.
The AppleScript looks like this:
tell application "System Events"
key down command
keystroke "s"
key up command
end tell
The closest I've gotten to this in JXA is as follows, but no matter what I pass to keyDown, it sends the letter "a":
events = Application("System Events")
events.keyDown("command")
events.keystroke("s")
events.keyUp("command")
Any ideas?
Thanks!
Fotis