Keypress Emulation

46 views
Skip to first unread message

Ale Muñoz

unread,
Jan 22, 2014, 12:01:29 PM1/22/14
to jstal...@googlegroups.com
Hi there,

I'm working on a script for an app, and at some point in the workflow I need to emulate a user's key presses.

Does JSTalk support that? How would I go about it?

I've checked the 'examples' folder in JSTalk but I've found nothing like it.

Thanks in advance!

Gus Mueller

unread,
Jan 22, 2014, 1:19:31 PM1/22/14
to jstal...@googlegroups.com
I've worked on a little bit of built in support for this in the past, but it's been unreliable for reasons that I have yet to figure out. You can get around that though, by using System Events and AppleScript though:

var s = 'tell application "System Events" to keystroke "q" using command down';
[[[NSAppleScript alloc] initWithSource:s] executeAndReturnError:nil];

-gus

Ale Muñoz

unread,
Jan 22, 2014, 1:56:43 PM1/22/14
to jstal...@googlegroups.com
Wow, thanks Gus!

How would that work for multiple modifier keys? I'm trying to send the Ctrl + Alt + Command + Down Arrow combination.

Thanks in advance!

Abhi Beckert

unread,
Jan 22, 2014, 2:09:11 PM1/22/14
to jstal...@googlegroups.com
You need to give it the key code number for left arrow, and a list of modifiers.

tell application "System Events" to key code 125 using {control down, option down, command down}

--
You received this message because you are subscribed to the Google Groups "JSTalk Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jstalk-dev+...@googlegroups.com.
To post to this group, send email to jstal...@googlegroups.com.
Visit this group at http://groups.google.com/group/jstalk-dev.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages