gpt4 book ai didi

ruby - 是否有支持跨平台鼠标操作的 ruby​​ gem?

转载 作者:数据小太阳 更新时间:2023-10-29 07:34:53 25 4
gpt4 key购买 nike

我需要能够以编程方式在特定坐标处触发鼠标单击。我发现 AutoIt 和 auto_click gem 都应该提供这种能力,但仅限于 Windows。我还发现了 rautomation gem,它旨在提供跨平台功能,但目前似乎不支持 Windows 以外的任何东西。

是否有任何其他 gem 允许直接从 Ruby 自动点击特定 x/y 坐标的鼠标?

最佳答案

我认为这是一项严重依赖系统的任务。您应该为您的代码提供一种加载系统相关 gem 的方法(Win 上的 AutoIt,Linux 上的 Automations)。如果您的目标是 Mac OS,您可以通过 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)

关于ruby - 是否有支持跨平台鼠标操作的 ruby​​ gem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7558315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com