VBS 按键 SendKeys:启动应用,执行热键
生活随笔
收集整理的這篇文章主要介紹了
VBS 按键 SendKeys:启动应用,执行热键
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
備注
使用SendKeys方法將擊鍵發送到沒有自動化接口的應用程序。大多數鍵盤字符由一個按鍵表示。有些鍵盤字符是由按鍵組合組成的(例如 CTRL+SHIFT+HOME)。要發送單個鍵盤字符,請將字符本身作為字符串參數發送。例如:
- 要發送字母x,使用字符串參數"x";
- 要發送空格,使用參數" ";
- 要發送字符串abc,使用參數 "abc"
功能鍵
| SHIFT | + |
| CTRL | ^ |
| ALT | % |
- 要發送字符串Abc,使用參數 "+abc"
特殊字符
特殊字符需要使用花括號包起來轉義:{特殊字符}。
例子
不完美
WshShell.Run "Postman" '啟動 Postman' 判斷標題為 Postman 的窗口是否已經激活 While WshShell.AppActivate("Postman") = falsewscript.sleep 5000 Wend暫時沒能實現啟動 + 執行熱鍵。只好先打開Postman再執行下面
on error resume next Dim WshShell Set WshShell=WScript.CreateObject("WScript.Shell") wscript.sleep 1000 * 60 * 60 * 5 ' 5小時后執行 WshShell.AppActivate "Postman" wscript.sleep 3000 WshShell.SendKeys "^~" ' ctrl + enter dim wsh set wsh = createobject("wscript.shell") wsh.appactivate("無標題") wscript.sleep 700 wsh.SendKeys "+App9527" wsh.SendKeys "~"自動輸入(Abc@)520@qq.com
dim wsh,titleStr set wsh = createobject("wscript.shell") titleStr=InputBox("目標窗口titel:") if titleStr = "" thentitleStr = "aaa.txt" end if wsh.appactivate(titleStr) wscript.sleep 700 ' 輸入:(Abc@)520@qq.com wsh.SendKeys "{(}+Abc@{)}520@qq.com" wscript.sleep 200 wsh.SendKeys "{ENTER}" wscript.sleep 200 wsh.SendKeys "{ENTER}"問題
注意:編碼問題 ANSI 正常,UTF8 報錯
參考資料
MSDN WshShell.SendKeys()
總結
以上是生活随笔為你收集整理的VBS 按键 SendKeys:启动应用,执行热键的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1222_SCons单目录多文件的编译实
- 下一篇: 监考噩梦!!!(线上考试)