Ruby 是否有一种与操作系统无关的方式将键盘和鼠标事件发送到底层操作系统?
一种明显的(对我来说)方法是使用 Ruby/Java 绑定并使用 java.awt.Robot,但这看起来很愚蠢。
For Mac:
gem install rb-appscript
然后您可以使用如下脚本对其进行测试:
require "rubygems"
require "appscript"
include Appscript
app("TextEdit").activate
app("System Events").keystroke("Look Ma, keystrokes!")
对于 Windows:(未经测试,借用了这个线程 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/84964)
require "win32ole"
wsh = WIN32OLE.new("WScript.Shell")
wsh.Run("Notepad.exe")
while not wsh.AppActivate("Notepad")
sleep .1
end
wsh.SendKeys("Look Ma, keystrokes!")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)