
446
|
Chapter 12, Miscellany
#89 Fun with Keyboard Lights
HACK
And More...
The most obvious enhancement is to use real images for the cursor, as the
many cursor packs available on the Web can attest (type “free cursors” into
Google and see what you get). Animated cursors could also be used to indi-
cate other elements of program state, such as network traffic or the current
tool in use. With a few images and the help of the
setCursor( ) function, you
can do almost anything.
H A C K
#89
Fun with Keyboard Lights Hack #89
Flash the Caps Lock, Num Lock, and Scroll Lock keys for extra user
feedback.
The AWT and Swing APIs are huge and full of robust components and
frameworks for building big applications. They also have some dark corners
where the lesser-known functions live. While cruising through the JavaDoc
for
java.awt.Toolkit, I ran across a function I had never noticed before,
despite it being in the API for over four years. This hack explores building a
keyboard busy indicator using the
Toolkit.setLockingKeyState( ) function.
The root class of AWT,
Toolkit, has a very interesting little function:
setLockingKeyState( ). You pass it the KeyEvent for the key you want to lock
down and turn it on or off with the
boolean. For most keyboards, this means
the Caps Lock, Num Lock, and Scroll Lock keys (some keyboards may also
have a Kana lock for Kanji support). Now that you have this nifty little func-
tion, what should ...