我需要以编程方式触发特定坐标的鼠标点击的能力。我找到了AutoIt和auto_click gem,它们都应该提供这种功能,但只在windows上提供。我还发现了rautomation gem,它旨在提供跨平台功能,但目前似乎只支持Windows。
有没有其他的宝石可以直接在Ruby中自动点击特定x/y坐标的鼠标?
发布于 2011-09-29 17:08:50
我认为这是一个严重依赖于系统的任务。您应该为您的代码提供一种加载依赖于系统的gem的方法( Win上的AutoIt,Linux上的Automations )。如果您的目标是Mac,那么您可以通过FFI库从CGRemoteOperation.h调用CGPostMouseEvent来构建自己的库。
例如:
需要'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)发布于 2014-02-25 22:11:13
看看rumouse gem吧。它提供了简单的API,支持linux、osx和windows。
https://stackoverflow.com/questions/7558315
复制相似问题