方法多了
1.
sendkeys "{键的名字 }" '(比如回车 "{enter}")
2.
'按组合键 启动任务管理器
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^+{ESC}
3. api
'最好是api 模拟键盘, 游戏游戏你上面的模拟是无效的,只有api 有效
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_LWIN = &H5B
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_APPS = &H5D
Private Const VK_PLAY = &HFA
Private Sub DoAction(Index As Integer)
Dim VK_ACTION As Long
Select Case Index
Case 0: '打开资源管理器
VK_ACTION = &H45
Case 1: '查找文件
VK_ACTION = &H46
Case 2: '最小化所有窗口
VK_ACTION = &H4D
Case 3: '运行程序
VK_ACTION = &H52
Case 4: '弹出Win菜单
VK_ACTION = &H5B
Case 5: '将计算机转入睡眠状态
VK_ACTION = &H5E
Case 6: '执行Windows帮助
VK_ACTION = &H70
End Select
Call keybd_event(VK_LWIN, 0, 0, 0)
Call keybd_event(VK_ACTION, 0, 0, 0)
Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
End Sub
……
在窗体加COMMAND1、COMMAND2、Timer1控件。
Private Sub Command1_Click() ’开始循环按键
Timer1.Interval = 1000 '此处设循环时间.
Timer1.Enabled = True
End Sub
Private Sub Command2_Click() ’停止循环按键
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
SendKeys "{ENTER}"
SendKeys "{DOWN}"
SendKeys "{ENTER}"
End Sub
新建COMMAND1.Timer1控件.复制下面代码到代码窗口.
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000'此处设时间.
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
SendKeys "{ENTER}"
SendKeys "{DOWN}"
SendKeys "{ENTER}"
End Sub
测试OK
SendKeys "{enter}"
SendKeys "{down}"
编在timer里面