[MacRuby-devel] send keystrokes with system.events?

stephen horne fatste at gmail.com
Thu Jul 4 03:26:56 PDT 2013


Hi Bryan,

I've done this in the past using quick and dirty NSApplescript:

def applescript_exec(script_string)
   pnt = Pointer.new_with_type("@")
   as = NSAppleScript.alloc.initWithSource(script_string)
   as.executeAndReturnError(pnt)
end

script_string = %{
   tell application "System Events"
     keystroke "h" using shift down
   end tell
}

applescript_exec(script_string) # results in 'H'

You can send special keystrokes using this method also, see 
https://discussions.apple.com/thread/660394?start=0&tstart=0

I think that the 'proper' way would be the Quartz method, but I've never 
delved into that:

http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventCreateKeyboardEvent

fb
> bryan rasmussen <mailto:rasmussen.bryan at gmail.com>
> 04/07/2013 11:09
> Hi,
>
> I've been looking for examples as to how I might send keystrokes using
> system.events from macruby, but not finding anything.
>
> Anyone know of any, or can give me an example script so I can get a start.
>
> Thanks,
> Bryan Rasmussen
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> https://lists.macosforge.org/mailman/listinfo/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20130704/964d4262/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postbox-contact.jpg
Type: image/jpeg
Size: 1385 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20130704/964d4262/attachment-0001.jpg>


More information about the MacRuby-devel mailing list