Originally published on: Sat, 09 May 2009 16:38:50 +0000
I often throw caution to the wind and change items in my startup scripts ... changes that could ( and do ) cause issues during my initialization process. I have many recovery options available, but I still use an old technique that allows me to alter the behavior of my scripts by using the Caps Lock or Scroll Lock keys.
Ages ago in the MS-DOS days, I wrote a little program that would check the state of the shift-keys ... the SHIFT, ALT, CTRL ...etc. keys. I don't believe that the task was terribly complex, but I may be remembering incorrectly.
If memory serves, I had simply cobbled together a little .COM file in DEBUG to check for the shift state of the Caps Lock key by looking at a flag in the BIOS Data Area at segment 40h. After performing the AND to determine if the key was on ... I would exit via INT 21h function 4C, passing back a zero if the key was off or a one if the key was on. This permitted me to call the .COM utility in a batch file so that I could then check the ERRORLEVEL flag for a one.
At the time I wrote this utility, part of my startup was on a page on a server, so I could not easily recover if the startup script managed to hang. I opted to check the Caps Lock key and would then bypass all of my custom startup commands if present.
This technique saved my bacon exactly once, but the time saved in being able to recover so quickly made the time I had spent writing the utility worthwhile.
I've created a Windows counterpart to the utility that now calls GetKeyState() to check for either Scroll Lock or Caps Lock ( depending on whether you've specified "-scroll" or "-caps" on the command-line. )
checklock.c
Here's a sample batch file that shows how to use the utilty:
The compiled EXE for checklock can be found here with the source code:
http://www.mailsend-online.com/wp/checklock.zip
Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless.
Save to del.icio.us
Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
Subscribe!
Auto Save Clipboard Images Redux
Extending SpiderMonkey JavaScript on Windows
Rhino JavaScript to EXE with launch4j
Compiling Rhino JavaScript to Java
Directory Traversal in Rhino JavaScript
A Command-Line MP3 Player for Windows
Auto Save Images from the Clipboard
Java in a Windows EXE with launch4j
An Interview with Tom Zimmer: Forth System Developer
Setting Windows Console Text Colors in C
Hiding Batch File Console Windows
Java in a Windows EXE with launch4j
Windows Text to Speech in WSH JavaScript
A Simple Parser for a Small Command Line Interface
Jim Butterfield : The Commodore Guru
MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer