问:
嗨,ScriptingGuy!IhaveascriptwhereusersentersomeinformationinanInputbox.Theinformationneedstobeenteredinall-capitalletters,somyinstructionssay,“PleasemakesuretheCapsLockkeyisonbeforeenteringtheinformation.”Theydon'talwaysdothat,however.IsthereawaytoturntheCapsLockkeyonandoffusingascript?
--BW,Medford,OR
答:
Hey,BW.Wedon'tknowofawaytoturntheCapsLockkeyonandoff,butwedoknowawaytomimictheeffectofhavingtheCapsLockkeyon.Afterall,thewholepointoftheCapsLockkeyistoturneverythingyoutypeintouppercaseletters.Forexample,youmighttypethis:
thisismysentence.
ButCapsLockwillmakeitappearonscreenlikethis:
THISISMYSENTENCE.
Sohowcanweachievethesameaffectinascript?简单:wejustusetheVBScriptfunctionUCase,whichswitchesallthelettersinastringtotheiruppercaseequivalent.Forexample,here'sasimpletwo-linescriptthatgathersinformationfromauserandthenusestheUCasefunctiontoswitchalltheletterstouppercasewhenechoingthevaluetothescreen:
strMessage=InputBox("Pleaseenteryourmessage:")Wscript.EchoUCase(strMessage)
Incidentally,theabovescriptdoesn'tactuallychangethecaseofthelettersinthestringstrMessage;itjustdisplaystheminuppercase.Ifyoureallywantallthelettersconvertedtouppercase,trythisscriptinstead:
strMessage=UCase(InputBox("Pleaseenteryourmessage:"))Wscript.EchostrMessage
Lookscrazy,butitworks.
FormoreinformationabouttheUCasefunction,seetheVBScript文档onMSDN.
【用vbscript实现启用 Caps Lock (大写)键】相关文章:
★ vbs+hta中实现在单个 onClick 参数中包括多个子例程的代码
★ vbscript include的办法实现代码第1/2页