Originally published on: Sat, 09 May 2009 16:38:50 +0000
Please note! If you're having difficulties compiling the C source code presented below, please see my post: Compiling C from the Command Line with Pelles C
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.
Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
Click **here**
A JavaScript REPL for Android Devices
A Review of Kevin Mitnick's Book Ghost in the Wires
Play MP3 Files with Python on Windows
An Interview with the Author of the French Silk Assembler
TAP : A Command Processor Library
An Interview with Game Developer James Hague
Why Some Web Sites will go Dark on Jan 18th
Book Review : Paull Allen - Idea Man
A 90's Experiment in Online Systems - The U.S. West CommunityLink Service