求个VB按键代码
来源:百度知道 编辑:UC知道 时间:2024/05/14 10:35:34
还有每900毫秒按一下Y键
F5启动 F8停止
高手指点下
v
按Q执行↑↓←→键每个按一下
按F5开始F8停止Y键的按下
如果是我说这样,那代码如下:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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 Timer3_Timer()
If GetAsyncKeyState(vbKeyQ) Then '按下Q执行上下左右各按一次
Timer1.Enabled = True
End If
If GetAsyncKeyState(vbKeyF5) Then '按下F5执行每900毫秒按一下Y键
Timer2.Enabled = True
End If
If GetAsyncKeyState(vbKeyF8) Then '按下F8执行停止按Y键
Timer2.Enabled = False
End If
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000 '1000大约为一秒,最大60000(1分钟),最小1
Timer2.Interval = 900 '900毫秒
Timer3.Interval = 10 '此处最好不要修改,是检测你是否按下快捷键
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = True
End Sub
Private Sub Timer2_Time