vb 模拟点击鼠标-实现按z则模拟点击某个游戏界面的那个位置。
展开全部
你好,你的问题要用API函数来实现。
首先,实现按Z的,你自己去实现,或者在窗体的KeyPress里边检测KeyAscii是否等于vbKeyZ。
其次,要实现点击游戏界面的位置,可以用下列函数:
'-------------函数声明部分,照复制就是了,加到所有函数开头
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetMessageExtraInfo Lib "user32" () As Long
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0 'X Size of screen
Const SM_CYSCREEN = 1 'Y Size of Screen
'----------这里是具体实现代码,在需要的地方添加:
mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, 特殊X坐标, 特殊Y坐标, 0, GetMessageExtraInfo()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()
注意那两个坐标值是特殊的,自己添加进去,即可实现鼠标点击了。其余部分保持不变!只是改那两个坐标就行了!
特殊坐标算法如下:
特殊X坐标 = 游戏中的那个点X坐标相对屏幕坐标 * (&HFFFF& / GetSystemMetrics(SM_CXSCREEN))
特殊Y坐标 = 游戏中的那个点Y坐标相对屏幕坐标 * (&HFFFF& / GetSystemMetrics(SM_CYSCREEN))
还有不懂的请再补充提出!比如游戏中的点是(80,60),那么代码是:
Dim X as Long, Y as Long
X = 80 * (&HFFFF& / GetSystemMetrics(SM_CXSCREEN))
Y = 60 * (&HFFFF& / GetSystemMetrics(SM_CYSCREEN))
mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, X, Y, 0, GetMessageExtraInfo()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()
首先,实现按Z的,你自己去实现,或者在窗体的KeyPress里边检测KeyAscii是否等于vbKeyZ。
其次,要实现点击游戏界面的位置,可以用下列函数:
'-------------函数声明部分,照复制就是了,加到所有函数开头
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetMessageExtraInfo Lib "user32" () As Long
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0 'X Size of screen
Const SM_CYSCREEN = 1 'Y Size of Screen
'----------这里是具体实现代码,在需要的地方添加:
mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, 特殊X坐标, 特殊Y坐标, 0, GetMessageExtraInfo()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()
注意那两个坐标值是特殊的,自己添加进去,即可实现鼠标点击了。其余部分保持不变!只是改那两个坐标就行了!
特殊坐标算法如下:
特殊X坐标 = 游戏中的那个点X坐标相对屏幕坐标 * (&HFFFF& / GetSystemMetrics(SM_CXSCREEN))
特殊Y坐标 = 游戏中的那个点Y坐标相对屏幕坐标 * (&HFFFF& / GetSystemMetrics(SM_CYSCREEN))
还有不懂的请再补充提出!比如游戏中的点是(80,60),那么代码是:
Dim X as Long, Y as Long
X = 80 * (&HFFFF& / GetSystemMetrics(SM_CXSCREEN))
Y = 60 * (&HFFFF& / GetSystemMetrics(SM_CYSCREEN))
mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, X, Y, 0, GetMessageExtraInfo()
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询