简单点的可以用sendkeys,要模拟按键可以keybd_event,高级点的可以用sendmessage或者postmessage,我做了个自动喊话的,用的是sendkeys,下面是代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '
Private Declare Function GetForegroundWindow Lib "user32" () As Long '获得前台窗口的句柄
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer '
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim a, b As Long
Static t As Integer
a = FindWindow(vbNullString, "地下城与勇士")
b = GetForegroundWindow
If a = b Then
t = t + 1
If t = 1 Then
SendKeys "{ENTER}"
ElseIf t = 2 Then
SendKeys "{/}"
ElseIf t = 3 Then
SendKeys "{r}"
ElseIf t = 4 Then
SendKeys "{e}"
ElseIf t = 5 Then
SendKeys "{ENTER}"
t = 0
End If
End If
End Sub
Private Sub Timer2_Timer()
If GetAsyncKeyState(vbKeyF9) Then
Timer1.Enabled = True
ElseIf GetAsyncKeyState(vbKeyF10) Then
Timer1.Enabled = False
a = 0
End If
End Sub
升级了标题发生了变化