vb向目标游戏窗口发送按键消息!
帮我看下,我哪个地方错了?PrivateDeclareFunctionSendMessageLib"user32"Alias"SendMessageA"(ByValhwn...
帮我看下,我哪个地方错了?
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CHAR = &H100
Const VK_F1 As Long = &H70
Private Sub Form_Load()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "123")
If (hwnd = 0) Then
MsgBox "游戏未加载"
Else: Text1.Text = "游戏正在运行!"
End If
If HotKey(vbKeyControl) = True And HotKey(vbKey1) = True Then
SendMessage Me.hwnd, WM_CHAR, vbKeyF1, ByVal 0&
END IF
END SUB 展开
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CHAR = &H100
Const VK_F1 As Long = &H70
Private Sub Form_Load()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "123")
If (hwnd = 0) Then
MsgBox "游戏未加载"
Else: Text1.Text = "游戏正在运行!"
End If
If HotKey(vbKeyControl) = True And HotKey(vbKey1) = True Then
SendMessage Me.hwnd, WM_CHAR, vbKeyF1, ByVal 0&
END IF
END SUB 展开
4个回答
展开全部
你到底能不能找到游戏窗口?
用这个吧 多送个鼠标移动点击的
先打开任务管理器最小化 再按Command1
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim a As Long
a = FindWindow(vbNullString, "Windows 任务管理器")
If a = 0 Then MsgBox "游戏未运行": Exit Sub
ShowWindow a, 0
ShowWindow a, 1
'Call SetCursorPos(512, 384) '移动
'mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '点击
End Sub
用这个吧 多送个鼠标移动点击的
先打开任务管理器最小化 再按Command1
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim a As Long
a = FindWindow(vbNullString, "Windows 任务管理器")
If a = 0 Then MsgBox "游戏未运行": Exit Sub
ShowWindow a, 0
ShowWindow a, 1
'Call SetCursorPos(512, 384) '移动
'mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '点击
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
w15828584183 说的对
而且最好用POSTMESSAGE
再不行就用钩子试试
而且最好用POSTMESSAGE
再不行就用钩子试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有的游戏用direct可能不会处理窗口消息。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询