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

933 Views Asked by At

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...

1

There are 1 best solutions below

2
On BEST ANSWER

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