Ruby击键x次数 [英] Ruby hit a key x number of times
本文介绍了Ruby击键x次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个Ruby程序来按"a"键100次或无限次.任何帮助或技巧来编写这样的程序?我可以举个例子还是帮忙?
I want to write a Ruby program to hit the 'a' key 100 or infinite times. any help or tips to write a program like this? I could use an example or help?
我只想多次按一个键.
推荐答案
Ruby本身无法调度系统事件.对于OS X,您可以使用 AXElements gem:
Ruby can't dispatch system events itself. For OS X you could use the AXElements gem:
require 'AXElements'
100.times do
type 'a'
sleep 1
end
以上内容相当于击中 a 100次(每次击中之间等待一秒钟).
The above is equivalent to hitting a 100 times (waiting a second between each hit).
这篇关于Ruby击键x次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文