ruby使用Win32API操作鼠标

2015-10-05 0 322
ruby使用Win32API操作鼠标
#要求ruby1.8.x
require 'Win32API'

#定义API GetCursorPos和SetCursorPos的接口
get_cursor_pos = Win32API.new("user32","GetCursorPos",['p'],'v')
$set_cursor_pos = Win32API.new("user32","SetCursorPos",['i']*2,'v')

#获取鼠标位置
lpPoint =" " * 8    #初始化存储位置信息的变量
get_cursor_pos.Call(lpPoint)        #调用API
x, y = lpPoint.unpack("LL")        #将传回的参数转换为两个无符号的长整数
puts "当前鼠标的坐标为: #{x}, #{y}"

#设置鼠标位置
def setm(new_xy)
  $set_cursor_pos.Call(new_xy[0], new_xy[1])
end

100.times{
  setm([rand*800,rand*600])
  sleep 0.01
}

遇见资源网 ruby ruby使用Win32API操作鼠标 http://www.ox520.com/16495.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务