vb做一个自动按键的 比如按A 隔1秒按B在隔3秒按C 但是是用快捷键控制开始的!!比如F1开始F8结束! 10
vb做一个自动按键的比如按A隔1秒按B在隔3秒按C但是是用快捷键控制开始的!!比如F1开始F8结束!谁能给我个VB代码或者简单的叙述!...
vb做一个自动按键的 比如按A 隔1秒按B在隔3秒按C 但是是用快捷键控制开始的!!比如F1开始F8结束! 谁能给我个VB代码 或者简单的叙述!
展开
3个回答
展开全部
在窗体中添加2个按钮控件和3个Timer控件。
所有代码如下:
Private Declare Function GetKeyState 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 Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)
Dim xx As Integer
Private Sub Command1_Click() '激活快捷键
Timer2.Enabled = True
Timer3.Enabled = True
End Sub
Private Sub Command2_Click() '终止快捷键
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 100
Timer2.Enabled = False
Timer2.Interval = 50
Timer3.Enabled = False
Timer3.Interval = 50
Command1.Caption = "激活快捷键"
Command2.Caption = "终止快捷键"
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
DoEvents
Sleep (1000) '间隔1秒
DoEvents
keybd_event vbKeyA, 0, 0, 0 '按A
DoEvents
Sleep (1000) '间隔1秒
DoEvents
keybd_event vbKeyB, 0, 0, 0 '按B
DoEvents
Sleep (3000) '间隔3秒
DoEvents
keybd_event vbKeyC, 0, 0, 0 '按C
DoEvents
Timer1.Enabled = True
End Sub
Private Sub Timer2_Timer()
If GetKeyState(vbKeyF8) Then 'F8停止
Timer1.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()
If GetKeyState(vbKeyF1) Then 'F1开始
Timer1.Enabled = True
End If
End Sub
以上代码你按F8停止后,必须要等当前循环结束它才会停止。
所有代码如下:
Private Declare Function GetKeyState 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 Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)
Dim xx As Integer
Private Sub Command1_Click() '激活快捷键
Timer2.Enabled = True
Timer3.Enabled = True
End Sub
Private Sub Command2_Click() '终止快捷键
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 100
Timer2.Enabled = False
Timer2.Interval = 50
Timer3.Enabled = False
Timer3.Interval = 50
Command1.Caption = "激活快捷键"
Command2.Caption = "终止快捷键"
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
DoEvents
Sleep (1000) '间隔1秒
DoEvents
keybd_event vbKeyA, 0, 0, 0 '按A
DoEvents
Sleep (1000) '间隔1秒
DoEvents
keybd_event vbKeyB, 0, 0, 0 '按B
DoEvents
Sleep (3000) '间隔3秒
DoEvents
keybd_event vbKeyC, 0, 0, 0 '按C
DoEvents
Timer1.Enabled = True
End Sub
Private Sub Timer2_Timer()
If GetKeyState(vbKeyF8) Then 'F8停止
Timer1.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()
If GetKeyState(vbKeyF1) Then 'F1开始
Timer1.Enabled = True
End If
End Sub
以上代码你按F8停止后,必须要等当前循环结束它才会停止。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一看你的想法是想做个vb的小辅助工具吧!!!
不过不得不告诉你你的想法不大现实普通的按键模拟在大多数游戏里都是不好用滴!!!!!!
最好用驱动级的!!!一般用WINIO这个dll
鼠标倒是可以不过鼠标模拟的时候按下和抬起之间至少要有100毫秒的间隔否则会不好用,时间随游戏不同而不同你可以自己试试....
不过不得不告诉你你的想法不大现实普通的按键模拟在大多数游戏里都是不好用滴!!!!!!
最好用驱动级的!!!一般用WINIO这个dll
鼠标倒是可以不过鼠标模拟的时候按下和抬起之间至少要有100毫秒的间隔否则会不好用,时间随游戏不同而不同你可以自己试试....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
加两个timer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
Timer2.Interval = 500
End Sub
Private Sub Timer1_Timer()
Static i As Integer
i = i + 1
If i = 1 Then SendKeys "A"
If i = 2 Then SendKeys "B"
If i = 5 Then SendKeys "c"
If i = 5 Then i = 0
End Sub
Private Sub Timer2_Timer()
If GetAsyncKeyState(vbKeyF1) Then Timer1.Enabled = True
If GetAsyncKeyState(vbKeyF8) Then Timer1.Enabled = False
End Sub
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
Timer2.Interval = 500
End Sub
Private Sub Timer1_Timer()
Static i As Integer
i = i + 1
If i = 1 Then SendKeys "A"
If i = 2 Then SendKeys "B"
If i = 5 Then SendKeys "c"
If i = 5 Then i = 0
End Sub
Private Sub Timer2_Timer()
If GetAsyncKeyState(vbKeyF1) Then Timer1.Enabled = True
If GetAsyncKeyState(vbKeyF8) Then Timer1.Enabled = False
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询