VB 对游戏后台鼠标单击问题
F1 取游戏里的绝对坐标F2 鼠标左击绝对坐标
问题鼠标是指虚假移动 人工动1下 鼠标还是老位置 并且只能在原来的位置点击
窗体:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201 '左键按下
Private Const WM_LBUTTONUP = &H202 '左键弹起
'Private Declare Sub mouse_event Lib "user32" (ByVal a As Long, ByVal b As Long, ByVal c As Long, ByVal d As Long, ByVal e As Long)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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)
Public a As New Class1
Private Sub Timer1_Timer()
Dim h As Long, xy As Long
h = FindWindow(vbNullString, "MapleStory")
If GetAsyncKeyState(vbKeyF1) Then
Text1.Text = a.getx
Text2.Text = a.gety
End If
If GetAsyncKeyState(vbKeyF2) Then
xy = Val(Text1.Text) + Val(Text2.Text) * &H10000
PostMessage h, WM_MOUSEMOVE, 0, ByVal xy
PostMessage h, WM_LBUTTONDOWN, 0, ByVal xy
PostMessage h, WM_LBUTTONUP, 0, ByVal xy
End If
End Sub
类模块
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Function getx()
Dim h As Long
h = FindWindow(vbNullString, "MapleStory")
Dim a As POINTAPI
GetCursorPos a
ScreenToClient h, a
getx = a.x
End Function
Public Function gety()
Dim h As Long
h = FindWindow(vbNullString, "MapleStory")
Dim a As POINTAPI
GetCursorPos a
ScreenToClient h, a
gety = a.y
End Function
我觉得 查找读取坐标应该没问题
就是不知道为什么在游戏内 点到设置的位置单击 --------------------编程问答-------------------- WM_MOUSEMOVE只是一个消息,收到这个消息并不一定代表鼠标就真的在动.
Private Function SendClick(hwnd As Long, mX As Long, mY As Long)
'发送点击消息
Dim I As Long
I = PostMessage(hwnd, WM_LBUTTONDOWN, 0, (mX And &HFFFF) + (mY And &HFFFF) * &H10000)
I = PostMessage(hwnd, WM_LBUTTONUP, 0, (mX And &HFFFF) + (mY And &HFFFF) * &H10000)
End Function
试试.
补充:VB , API