VB自动按键

来源:百度知道 编辑:UC知道 时间:2024/07/02 02:15:57
写个VB程序,每2秒时间按A键,再2秒时间按B键,不断的重复直到10分钟后。还有就是直到把程序关闭。
netbartp 你写的程序好象是能自动按键了,但动行的时候鼠标不能动了。。

用sleep函数是有你说的这个问题.我给你重新修改一下:我自定义了一个延迟函数,过程里调用这个函数就不会出现鼠标不能动的这个情况了

Private Function Delay(sSeconds As Long)
Dim BeginTime As Date
BeginTime = Time
Do
DoEvents
If DateDiff("s", BeginTime, Time) >= sSeconds Then Exit Do
Loop
End Function

Private Sub Command1_Click()
Dim b As Date
b = Time
Do
DoEvents
SendKeys "A" '发送A键
Delay (2) '等待2秒钟
SendKeys "B" '发送B键
Delay (2) '等待2秒钟
If DateDiff("n", b, Time) = 10 Then '如果超过10分钟就退出循环并结束程序
Exit Do
Unload Me
End If
Loop
End Sub

sendkeys "a"
用TIMER做循环,多说了对你学习无益