The Keyboard Object

Visual Basic used to come with a handy Key State control for displaying or changing the state of control keys such as Caps Lock, Num Lock, and Insert. For compatibility, KEYSTA32.OCX is still shipped in the \Tools\Controls directory of the Visual Basic CD. My advice is to leave it there and to delete any stray copies you might have on your disk. Why pay a heavy cost in disk space and Windows resources when you can roll your own in Visual Basic for almost nothing? Besides, the fonts and colors in the predefined buttons are a little garish for my taste.

Edwina achieves a more subtle look (similar to that of the status bar in Word for Windows) by displaying the key state in gray or black in status bar panels. You could use an invisible Key State control to achieve this effect, but the code required to do the same thing in Windows is so simple that the control isn’t worth the trouble. Instead, I’ll wrap up everything in the CKeyboard class, and then create a single Keyboard object that represents the one and only system keyboard.

When I say KEYSTA32.OCX has a heavy cost, I’m not just talking about its 116 KB size. The real problem is that it requires MFC42.DLL (988 KB) and MSVCRT40.DLL (319 KB), which the intrinsic Visual Basic controls no longer require. You don’t know if your customers already have those DLLs on their disk, so you have to ship them with any application that uses Key State. The same limitation applies to the other controls that are provided, but not installed, by Visual Basic—Animated Button, Gauge, Graph, Grid, Outline, Spin, and Three D. One of the important behind-the-scenes achievements of Visual Basic version 5 was
to eliminate the MFC dependency from the language library and the primary controls. A few controls didn’t make the grade for conversion because they duplicated other controls or had functionality that could be achieved without controls. If at all possible, you should change to one of the new controls. This
is going to bite a few users the way it bit me. The original Win-Watch displayed the window hierarchy using the Outline control. It worked fine, and I didn’t want to do the extra work to change to TreeView. But I also didn’t want to ship 1.4 megabytes of MFC DLLs with my book. So I changed. If you have MFC DLLs on your disk, don’t blame me.