vb 自动按键

2025-12-18 10:08:53
推荐回答(6个)
回答1:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyW Then
Print "W"
End If
End Sub

Private Sub Form_Load()
Me.Show
Timer1.Interval = 1000'如果想每隔10秒 就把1000改成10000
End Sub

Private Sub Timer1_Timer()
SendKeys "W"
End Sub

回答2:

Dim i As Long
Private Sub Form_Load()
Hide
Timer1.Enabled =True
Timer1.Interval =500
i = Second(Now)
End Sub
Private Sub Timer1_Timer()
If Abs(Second(Now) - i) > 10 Then
Set ws = CreateObject("WScript.Shell")
ws.SendKeys "w"
End If
End Sub
当程序启动10秒后就一直像窗体发送字母w,这时你要是打开记事本的话会自动在里边输入w字母的,如果没有设置中断的话会影响其他程序的执行的哦

回答3:

Private Sub Timer1_Timer()
Set a = CreateObject("WScript.Shell")
'设置A为一个指定的对象(用于程序)
a.SendKeys "www"
'利用对象A发送www键,Enter键为"{Enter}"大括号只有在系统按键(Ctrl、Alt、Insert、Delete、Enter、F5等等)
End Sub

这是正规的方法!

QQ:240622780

回答4:

模块:
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Sub Timer1_Timer()
Call keybd_event(87, 0, 0, 0)
End Sub

回答5:

楼上的都好
不用Set a = CreateObject("WScript.Shell") ,太正规了^-^.
我觉得keybd_event 更好点

回答6:

d