rubymacososx-snow-leopardmacrubyruby-cocoa

Using Ruby on Mac OS X, how to programmatically click on the screen -- and mouse move, mouse down, and mouse up?


What are the best way(s) to do it? Can ffi, RubyCocoa, or MacRuby do it?

It seems like CGEventCreateMouseEvent or CGPostMouseEvent (deprecated) can be used.

Please give a working example. thanks.

Update: the title of this question updated...


Solution

  • In MacRuby your views can catch these events. Just look into the DotView example that comes with MacRuby.

    class MyView < NSView 
      def mouseUp event
        puts convertPoint(event.locationInWindow, fromView:nil)
      end
    end