Is there a ruby ​​stone that allows cross-platform mouse manipulation?

I need the ability to programmatically trigger a mouse click at specific coordinates. I found AutoIt and auto_click gems, which both presumably provide this feature, but only on Windows. I also found the rautomation gem, which is designed to provide cross-platform capabilities, but which does not seem to support anything other than Windows at the moment.

Are there any other gems that allow you to automate mouse clicks at certain x / y coordinates directly from Ruby?

+4
source share
2 answers

I think this is a system-dependent task. You must provide your code with a way to download system-specific gems (AutoIt on Win, Automations on Linux). If you are targeting Mac OS, you can create your own lib by calling CGPostMouseEvent from CGRemoteOperation.h through the FFI library.

For instance:

'ffi' required

 module Mouse extend FFI::Library ffi_lib '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics' class CGPoint < FFI::Struct layout :x, :double, :y, :double end attach_function :CGPostMouseEvent, [ CGPoint, :bool, :int, :bool ], :void end point = Mouse::CGPoint.new point[:x] = 100 point[:y] = 100 Mouse::CGPostMouseEvent(point, true, 1, true) 
+2
source

Take a look at rumouse gem. It provides a simple API and supports linux, osx and windows.

+1
source

All Articles