boy11-2 发表于 2011-02-09 16:28

Ruby 在 Windows 下对鼠标键盘的读取

1、Ruby 在 Windows 下读取键盘输入require 'Win32API'

def getch
@getch ||= Win32API.new('crtdll', '_getch', [], 'L')
@getch.call
end

while (c = getch) != ?\e
puts "You typed #{c.chr.inspect}"
end2、Ruby 在 Windows 下获取当前鼠标光标的位置result = "0"*8   # Eight bytes (enough for two longs)
getCursorXY = Win32API.new("user32","GetCursorPos",["P"],"V")
getCursorXY.call(result)
x, y = result.unpack("LL")# Two longs

2gua 发表于 2011-02-10 08:43

不错啊。
页: [1]
查看完整版本: Ruby 在 Windows 下对鼠标键盘的读取