VB 连续按空格键和数字1键2键
比如每隔200毫秒按一次空格键,同时每隔1000毫秒按一下数字1键,再每隔2000毫秒按一下数字2键我做游戏的辅助工具用!...
比如每隔200毫秒按一次空格键,同时每隔1000毫秒按一下数字1键,再每隔2000毫秒按一下数字2键
我做游戏的辅助工具用! 展开
我做游戏的辅助工具用! 展开
3个回答
展开全部
'在窗体上加入控件timer1,command1,command2,然后复制下面代码,运行,按提示按“开始”键即可
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Dim k1, k2, k3
Sub SendKeyToWnd(vbkey As KeyCodeConstants)
keybd_event vbkey, 0, KEYEVENTF_EXTENDEDKEY, 0
Sleep 100
keybd_event vbkey, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
End Sub
Private Sub Command1_Click()
k1 = Timer
k2 = Timer
k3 = Timer
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Command1.Caption = "开始"
Command2.Caption = "停止"
Timer1.Interval = 200
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
If Timer - k1 >= 0.2 Then '每隔200毫秒按一次空格键
SendKeyToWnd vbKeySpace
k1 = Timer
End If
If Timer - k2 >= 1 Then '每隔1000毫秒按一次数字1
SendKeyToWnd vbKey1
k2 = Timer
End If
If Timer - k3 >= 2 Then '每隔2000毫秒按一次数字2
SendKeyToWnd vbKey2
k3 = Timer
End If
End Sub
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Dim k1, k2, k3
Sub SendKeyToWnd(vbkey As KeyCodeConstants)
keybd_event vbkey, 0, KEYEVENTF_EXTENDEDKEY, 0
Sleep 100
keybd_event vbkey, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
End Sub
Private Sub Command1_Click()
k1 = Timer
k2 = Timer
k3 = Timer
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Command1.Caption = "开始"
Command2.Caption = "停止"
Timer1.Interval = 200
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
If Timer - k1 >= 0.2 Then '每隔200毫秒按一次空格键
SendKeyToWnd vbKeySpace
k1 = Timer
End If
If Timer - k2 >= 1 Then '每隔1000毫秒按一次数字1
SendKeyToWnd vbKey1
k2 = Timer
End If
If Timer - k3 >= 2 Then '每隔2000毫秒按一次数字2
SendKeyToWnd vbKey2
k3 = Timer
End If
End Sub
展开全部
需要在控件Timer的Inberval属性设置
例如:0.1秒频率就设置为100
例如:0.1秒频率就设置为100
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Sub SendAKey(KeyCode As Long)
Call keybd_event(KeyCode, 0, 0, 0)
Call keybd_event(KeyCode, 0, 2, 0)
End Sub
KeyCode 是键码
Public Sub SendAKey(KeyCode As Long)
Call keybd_event(KeyCode, 0, 0, 0)
Call keybd_event(KeyCode, 0, 2, 0)
End Sub
KeyCode 是键码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询