用vbscript实现启用 Caps Lock (大写)键
用vbscript实现启用 Caps Lock (大写)键
发布时间:2016-12-28 来源:查字典编辑
摘要:问:嗨,ScriptingGuy!IhaveascriptwhereusersentersomeinformationinanInputbo...

问:

嗨,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.

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新vbs学习
热门vbs学习
脚本专栏子分类