使用Win32API操作鼠标

2015-03-04 0 995
使用Win32API操作鼠标
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}"

#设置鼠标位置为(100, 100)
new_xy = [100, 100]
set_cursor_pos.Call(new_xy[0], new_xy[1])

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

常见问题

相关文章

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

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