Sunday, November 6, 2011

Communication with Keyboard of Interaction With Hardware in C programming

Like mouse messages there also exist messages for keyboard. These are WM_KEYDOWN, WM_KEYUP and WM_CHAR. Of these, WM_KEYDOWN and WM_KEYUP are sent to an application (which has the input focus) whenever the key is pressed and released respectively. The additional information in case of these messages is the code of the key being pressed or released. When we tackle WM_KEYDOWN or WM_KEYUP we need to ourselves check the status of toggle keys like NumLock and CapsLock and shift keys like Ctrl, Alt and Shift. If we wish to avoid all this checking we can tackle the WM_CHAR message instead.

What is mentioned above is the normal procedure followed by most Windows applications. However, if we wish to go a step further and deal with the keyboard we need to tackle it differently. For example, suppose we are to perform one of the following jobs:

(a) Once you hit any key CapsLock should become on. Once it becomes on it should remain permanently on.

(b) If we hit a key once it should appear twice on the screen.

(c) If we hit a key A then B should appear on the screen, if we hit a B then C should occur and so on.
Note that all these effects should work on a system-wide basis for all Win32 applications. To be able to achieve these effect we need understand two important mechanisms—‘Dynamic Linking’ and ‘Windows Hooks’. Let us understand these mechanisms one by one.

No comments:

Post a Comment