Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a very old program that needs the commands to be all caps. when I exit this program I often forget to put the Caps Lock off (very annoying). I had a batch program in XP that did this but can't find a way to do it in Win 7.

share|improve this question

2 Answers 2

The only way I know from cmd.exe is by spawning powershell or vbs.

Drop this at the end of your batch, it toggles CAPSLOCK

start /b /wait powershell.exe -nologo -WindowStyle Hidden -sta -command "$wsh = New-Object -ComObject WScript.Shell;$wsh.SendKeys('{CAPSLOCK}')"

That calls out to powershell via command line and invokes the sendkeys, the alternative method is to echo similar commands into a %temp% file and then wscript %temp%\my.vbs.

EDIT: Here is the IF statement to ensure it only turns capslock OFF

start /b /wait powershell.exe -nologo -WindowStyle Hidden -sta -command "IF ([console]::CapsLock -eq 'True'){$wsh = New-Object -ComObject WScript.Shell;$wsh.SendKeys('{CAPSLOCK}')}"
share|improve this answer
    
note: [console]::CapsLock displays current status $true or $false combined with an IF statement, you could ensure it doesn't run if capslock is already off. –  Knuckle-Dragger Jan 3 at 11:22
    
Thanks knuckle-dragger. how would I incorporate the [console] line into the if statement in the batch file (I know some Basic but not much else!)? Also, how do I get the batch file to process commands after execution of the powershell line? –  Fly Right Jan 3 at 15:33
    
added example IF statement. After the caplsock is toggled the start /wait will return focus to the batch script and run any further commands it finds. –  Knuckle-Dragger Jan 4 at 1:23
    
This is GREAT Knuckle-dragger. I have been trying to do this for years. The only problem I have is the batch file dumps out after the first line even though I have the /wait in the start commands you have indicated. What do I need to change in the following to get it to execute the second line? –  Fly Right Jan 4 at 21:39
    
start /b /wait powershell.exe -nologo -WindowStyle Hidden -sta -command "IF ([console]::CapsLock -ne 'True'){$wsh = New-Object -ComObject WScript.Shell;$wsh.SendKeys('{CAPSLOCK}')}" <<new line>> net use lpt1: \\downstairs\LaserJet /persistent:yes <<new line>> basic mainmenu <<new line>> net use lpt1: /delete <<new line>> start /b /wait powershell.exe -nologo -WindowStyle Hidden -sta -command "IF ([console]::CapsLock -eq 'True'){$wsh = New-Object -ComObject WScript.Shell;$wsh.SendKeys('{CAPSLOCK}')}" –  Fly Right Jan 4 at 21:52

Using JP Software's TCC/LE, which can run batch scripts of course, it's as simple as the built-in KEYBD command. So your wrapper script that you run with TCC/LE would be:

@echo off
:: Force CAPS LOCK on beforehand.
keybd /c1
call very-old-program
:: Force CAPS LOCK off afterwards.
keybd /c0
share|improve this answer
    
Have downloaded TCC/LE and this solves the problem perfectly. Thanks! –  Fly Right Jan 9 at 10:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.