Is there a ruby gem that enables cross-platform mouse manipulation?
I need the ability to programmatically trigger a mouse click at specific coordinates. I've found AutoIt a开发者_StackOverflownd the auto_click gem which both supposedly provide this ability, but only on Windows. I've also found the rautomation gem which aims to provide cross-platform capabilities, but which doesn't seem to support anything other than Windows at the moment.
Are there any other gems out there that allow automating mouse clicks at specific x/y coordinates directly from Ruby?
I think it is a heavily system-dependent task. You should provide your code a way to load system-dependent gems (AutoIt on Win, Automations on Linux). If you are targeting Mac OS, you could build your own lib by calling CGPostMouseEvent
from the CGRemoteOperation.h
via the FFI library.
For example:
require 'ffi'
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)
Take a look at rumouse gem. It provides simple API and supports linux, osx and windows.
精彩评论