我想做一个在游戏中自动按键的小东西,可是做出来游戏中不能用那个快捷键,就是不能自动打怪,点聊天框时却出现我想按的那个键,给截图
VB6.0写的这是源码
Private Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function SendMessageBynum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long '
Private Declare Function SetFocusAPI& Lib "user32" Alias "SetFocus" (ByVal hwnd As Long)
Private Declare Function SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
Private Const WM_CHAR = &H102
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 100
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim hwd As Long
Dim hwd1 As Long
hwd1 = Text1.Text 'txet1 中装着游戏的句柄
SendMessage hwd1, WM_CHAR, 49, 1 '模拟按键
End Sub
你在timer1可以用另一个函数
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Timer1_Timer()
Call keybd_event(49, 0, 0, 0) '模拟按下"1"键
End Sub
我试过可以的