还可以这样- Randomize
- Set ws = CreateObject("Wscript.Shell")
- ws.Run "notepad" '打开记事本
- do while ws.appactivate("无标题 - 记事本")=false '聚焦到当前记事本窗口
- WScript.Sleep 200
- loop
- ws.SendKeys "^ " '模拟Ctrl + Space
- WScript.Sleep 500
- str = "这是一行演示中文输入的字符串无言独上西楼月如钩寂寞梧桐深院锁清秋剪不断理还乱是离愁别是一般滋味在心头"
- Sub CopyString(s) '设置函数
- Set forms=WScript.CreateObject("forms.form.1")
- Set textbox=forms.Controls.Add("forms.textbox.1").Object
- With textbox
- .multiline=True
- .text=s
- .selstart=0
- .sellength=Len(.text)
- .copy
- End With
- End Sub
- Num = Int((len(str)-1) * Rnd + 1) '随机获取字符个数
- For i=0 to Num
- a=mid(str,Int(len(str) * Rnd + 1),1) '随机输出某个字符
- CopyString a '调用函数
- WScript.Sleep 100
- ws.SendKeys "^v" '模拟Ctrl + V
- WScript.Sleep 100 '数值越小打字速度越快
- Next
- ws.SendKeys " " '模拟Space
- WScript.Sleep 100
- save=0 '如想保存则写1
- If save=1 Then
- 'ws.sendkeys "^ "
- '解释上一行:关闭中文输入法。如果是中文,则必须去掉上一行的注释。
- ws.sendkeys "^s"
- WScript.Sleep 1000
- ws.sendkeys "c:\test.txt" '文件名(可写路径),必须是全英文
- WScript.Sleep 1000
- ws.sendkeys "{Enter}"
- End If
- ws.SendKeys "%{F4}" '模拟Alt + F4,关闭当前记事本窗口
- WScript.Sleep 500
- If save=0 Then
- ws.SendKeys "N"
- End If
- WScript.quit
复制代码
|