VBS中SendKeys的基本應用
2019-10-26 17:49:04
供稿:網友
ps:不知道有人還記得這個攻擊qq群的代碼?就是利用這個所寫的!
SendKeys
模擬鍵盤操作,將一個或多個按鍵指令發送到指定Windows窗口來控制應用程序運行,
其使用格式為:object.SendKeys string
“object”:表示WshShell對象
“string”:表示要發送的按鍵指令字符串,需要放在英文雙引號中。
1.基本鍵
一般來說,要發送的按鍵指令都可以直接用該按鍵字符本身來表示,例如要發送字母“x”,使用“WshShell.SendKeys "x"”即可。當然,也可直接發送多個按鍵指令,只需要將按鍵字符按順序排列在一起即可,例如,要發送按鍵“happy”,可以使用“WshShell.SendKeys "happy"”。
2.特殊功能鍵
對于需要與Shift、Ctrl、Alt三個控制鍵組合的按鍵,SendKeys使用特殊字符來表示:
Shift---------WshShell.SendKeys "+"
Ctrl---------WshShell.SendKeys "^"
Alt---------WshShell.SendKeys "%"
由于“+”、“^”這些字符用來表示特殊的控制按鍵了,如何表示這些按鍵呢?
只要用大括號括住這些字符即可。例如:
要發送加號“+”,可使用“WshShell.SendKeys "{+}"”
另外對于一些不會生成字符的控制功能按鍵,也同樣需要使用大括號括起來按鍵的名稱,例如要發送回車鍵,需要用“WshShell.SendKeys "{ENTER}"”表示,發送向下的方向鍵用“WshShell.SendKeys "{DOWN}"”表示。
Space---------WshShell.SendKeys " "
Enter---------WshShell.SendKeys "{ENTER}"
←---------WshShell.SendKeys "{RIGHT}"
↑---------WshShell.SendKeys "{UP}"
F1---------WshShell.SendKeys "{F1}"
Tips:如果需要發送多個重復的單字母按鍵,不必重復輸入該字母,SendKeys允許使用簡化格式進行描述,使用格式為“{按鍵 數字}”。例如要發送10個字母“x”,則輸入“WshShell.SendKeys "{x 10}"”即可。
實例:
----------------------------------------------------
按下F5刷新桌面
Dim WshShell,Path,i
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{F5}"
----------------------------------------------------
電腦的自動重啟
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^{ESC}u"
WshShell.SendKeys "R"
----------------------------------------------------
啟動任務管理器
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^+{ESC}"
----------------------------------------------------