VB sendkey可以向指定窗口发送消息吗?
1个回答
展开全部
Private Sub Form_Load()
Dim x
x = Shell("Notepad.exe", vbNormalFocus)
SendKeys "这是一个文本文件的测试程序.", True ' 模拟输入英文字符串
SendKeys "{Enter}{Enter}", True ' 两次回车
waittime (2) ' 延时 2 秒
SendKeys "自动输入文字", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "既不是病毒,也不是木马!", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "开始退出... 看菜单项{(}F{)}...", True
SendKeys "%", True 'Alt 键激活菜单条
waittime (1)
SendKeys "(F)", True '按字母 "F",选择"文件(F)"菜单
waittime (1)
SendKeys "(X)", True '按字母 "X", 选择"退出(X)"
waittime (2)
SendKeys "(N)", True '弹出一个对话框,询问文件是否存盘,按 "N" 不存盘
End '结束本模拟程序
End Sub
Private Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
Loop
End Sub
Dim x
x = Shell("Notepad.exe", vbNormalFocus)
SendKeys "这是一个文本文件的测试程序.", True ' 模拟输入英文字符串
SendKeys "{Enter}{Enter}", True ' 两次回车
waittime (2) ' 延时 2 秒
SendKeys "自动输入文字", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "既不是病毒,也不是木马!", True
SendKeys "{Enter}{Enter}", True
waittime (2)
SendKeys "开始退出... 看菜单项{(}F{)}...", True
SendKeys "%", True 'Alt 键激活菜单条
waittime (1)
SendKeys "(F)", True '按字母 "F",选择"文件(F)"菜单
waittime (1)
SendKeys "(X)", True '按字母 "X", 选择"退出(X)"
waittime (2)
SendKeys "(N)", True '弹出一个对话框,询问文件是否存盘,按 "N" 不存盘
End '结束本模拟程序
End Sub
Private Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
Loop
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询