試著模擬開啟筆記本,在裡面輸入:
hi
hello WORD
輸入完成後存檔並關閉檔案,
藉以練習如何模擬開檔、鍵盤輸入等功能
測試程式碼:
Dim ws
Set ws = CreateObject("WScript.Shell") '模擬鍵盤用
ws.Run("""D:\vbsTest.txt""") '開啟檔案
WScript.Sleep 1000 '延遲1000毫秒 = 1秒
ws.SendKeys "h" '鍵盤"h"
WScript.Sleep 200
ws.SendKeys "i"
WScript.Sleep 200
ws.SendKeys "~" '鍵盤"enter"
WScript.Sleep 200
ws.SendKeys "h"
WScript.Sleep 200
ws.SendKeys "e"
WScript.Sleep 200
ws.SendKeys "l"
WScript.Sleep 200
ws.SendKeys "l"
WScript.Sleep 200
ws.SendKeys "o"
WScript.Sleep 200
ws.SendKeys " "
WScript.Sleep 200
ws.SendKeys "+w" '鍵盤"shift"+ "s"
WScript.Sleep 200
ws.SendKeys "+o"
WScript.Sleep 200
ws.SendKeys "+r"
WScript.Sleep 200
ws.SendKeys "+l"
WScript.Sleep 200
ws.SendKeys "+d"
WScript.Sleep 1000
ws.SendKeys "^s" '鍵盤"ctrl"+ "s"
ws.SendKeys "%{F4}" '鍵盤"alt" + "F4"
沒有留言:
張貼留言