手机
当前位置:查字典教程网 >脚本专栏 >vbs >用vbscript实现启用 Caps Lock (大写)键
用vbscript实现启用 Caps Lock (大写)键
摘要:问:嗨,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.

【用vbscript实现启用 Caps Lock (大写)键】相关文章:

用vbscript脚本实现返回 IP 配置数据的代码

vbscript实现的根据不同时间段显示不同的欢迎语

用vbs将名称转换为正确的大小写的代码

vbs+hta中实现在单个 onClick 参数中包括多个子例程的代码

用vbscript实现在文本文件中搜索两个项

vbscript的骨灰级写法计算1到100的和

用VBScript实现压缩目录中的所有文件(Zip)

用vbscript实现在消息框中显示一个超链接

用vbs实现的exe2swf工具脚本代码

vbscript include的办法实现代码第1/2页

精品推荐
分类导航