是否有操作系统中立的方式让 Ruby 将键盘和鼠标事件发送到底层操作系统?
(对我而言)一个明显的方法是使用 Ruby/Java 绑定(bind)并使用 java.awt.Robot,但这看起来很愚蠢。
最佳答案
对于 Mac:
gem install rb-appscript
然后你可以用这样的脚本来测试它:
require "rubygems"
require "appscript"
include Appscript
app("TextEdit").activate
app("System Events").keystroke("Look Ma, keystrokes!")
对于 Windows:(未经测试,borrowed from this thread)
require "win32ole"
wsh = WIN32OLE.new("WScript.Shell")
wsh.Run("Notepad.exe")
while not wsh.AppActivate("Notepad")
sleep .1
end
wsh.SendKeys("Look Ma, keystrokes!")
关于ruby - 如何使用 Ruby 将键盘和鼠标命令发送到底层操作系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1446327/