今天有人問(wèn)我如何向APPlication 發(fā)送雙引號(hào),分號(hào)等,我在這里做一個(gè)總結(jié),方便你使用參考
代碼如下:
' ======================================
' VBS 中 SendKeys 模擬鍵盤(pán)擊鍵
' 2009-07-26
' 劉林
' ======================================
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd"
' 讓腳本等待1000毫秒,也就是1秒再執(zhí)行下一條語(yǔ)句
WScript.Sleep 1000
' -- 發(fā)送字符時(shí),輸入法一定要在英文件狀態(tài)下
' 發(fā)送分號(hào)
WshShell.SendKeys ";"
WScript.Sleep 1000
' 發(fā)送冒號(hào)
WshShell.SendKeys ":"
WScript.Sleep 1000
' 發(fā)送雙引號(hào) -- 利用chr把雙引號(hào)轉(zhuǎn)換出來(lái)
WshShell.SendKeys Chr(34)
WScript.Sleep 1000
' 發(fā)送帶有雙引號(hào)的字符串
WshShell.SendKeys Chr(34)&"this is a string"&Chr(34)
WScript.Sleep 1000
' -- 切記,這里是模擬的擊鍵操作,所以不能發(fā)送中文
'WshShell.SendKeys Chr(34)&"這是一個(gè)字符串"&Chr(34)
WScript.Sleep 1000
' ================================================
' -- 如何模擬回車(chē),上檔鍵,Alt鍵喃?
' ================================================
' -- 如何模擬回車(chē), -- {enter}這就代表是發(fā)送回車(chē)
WshShell.SendKeys "this is a enter!{enter}"
WScript.Sleep 1000
' -- 如何模擬上檔鍵Shift, -- +這就代表是發(fā)送shift
WshShell.SendKeys "this is +a" ' 結(jié)果為 this is A
WScript.Sleep 1000
' -- 如何模擬Alt, -- %這就代表是發(fā)送Alt
WshShell.SendKeys "this is %{TAB}" ' 結(jié)果為 切換窗口
WScript.Sleep 1000
' ===========================================================
' -- 那么如何發(fā)送%, + ^ 喃
WshShell.SendKeys "this is {+}{^}{%}" ' 結(jié)果為 切換窗口
WScript.Sleep 1000
' -- 這里你可能已經(jīng)明白了,發(fā)送送特殊字符時(shí),請(qǐng)放到 {} 中
' ===========================================================
' ======================================
' 更多信息請(qǐng)看VBS幫助文檔 2009-07-26
' ======================================