Ruby 在 Windows 下读取键盘输入

2670阅读 0评论2011-02-14 lijianweiabcde
分类:

1、RubyWindows 下读取键盘输入
  1. require 'Win32API'

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

  6. while (c = getch) != ?\e
  7.   puts "You typed #{c.chr.inspect}"
  8. end
复制代码
2、Ruby 在 Windows 下获取当前鼠标光标的位置
  1. result = "0"*8   # Eight bytes (enough for two longs)
  2. getCursorXY = Win32API.new("user32","GetCursorPos",["P"],"V")
  3. getCursorXY.call(result)
  4. x, y = result.unpack("LL")  # Two longs
复制代码
上一篇:ruby中如何大小字母互转
下一篇:'tcp' modifier applied to host