1 Keyboardd Basics
1) Ignoring the Keyboard
Your programm does not need to act on every keyboard message it received,Window handle many keyboard message function itself.
2)Who's Got thefocus
Though the keyboard is shared by all the window in the application ,The DispatchMessage send the message to the window procedure associated the window which message is intended.
The window that receives a particular keyboard event is the window has the input foucs.
Sometime no window has input foucs,this is the case if all your programs have been minmized,window continue send keyboard to the active window ,but it is send in the deffert form from sending to the input foucs.
A window procedure can be determine when its window has the input focus by trapping WM_SETFOCUS and WM_KILLFOCUS.
3) Queues and Synchronization
As the user presses and releases key on keyborad,Windows and keyboard device driver translate the hardware scan code into formatted message.Howerver the messages are not palced on the application queue right away,Instean Windows store these message in a system message queue .The System message queue is a single message maintained by windows specifically for the prelimary storage of user input from keyboard and the mouse. Window will take the next message from the system message queue and place it on the application message queue only when a window application has finished proecssing the previous user input message.
4) Keystorkes and Character
The message that an application receives from windows about keyboard events distingush between keystrokes and characters.
for instance The keysokes has only one key labbed 'A' ,and the character may be 'a' or 'ctr-a' etc.
2 Keystroke Message
1)Wirtual key Codes
The virtual key code is stored in the wParam parameter of WM_KEYDOWN,WM_KEYUP,the code identifies the key being pressed or release.
2)lParam Information
the wParam message parameter contain virtual key code and the lparam message parameter contains other information in understanding the keystoke.
3) Shift States
iState = GetKeyState (VK_SHIFT) ;
iState variable will be negative if the Shift key is donw
iState = GetKeyState (VK_CAPITAL) ;
4)Using Keystroke Messages
5)
case WM_KEYDOWN:
switch (wParam)
{
case VK_HOME:
SendMessage (hwnd, WM_VSCROLL, SB_TOP, 0) ;
break ;
case VK_END:
SendMessage (hwnd, WM_VSCROLL, SB_BOTTOM, 0) ;
break ;
case VK_PRIOR:
SendMessage (hwnd, WM_VSCROLL, SB_PAGEUP, 0) ;
break ;
3 Character Messages
Message Key or Code
WM_KEYDOWN Virtual key code for `A' (0x41)
WM_CHAR Character code for `a' (0x61)
WM_KEYUP Virtual key code for `A' (0x41)
Message Key or Code
WM_KEYDOWN Virtual key code VK_SHIFT (0x10)
WM_KEYDOWN Virtual key code for `A' (0x41)
WM_CHAR Character code for `A' (0x41)
WM_KEYUP Virtual key code for `A' (0x41)
WM_KEYUP Virtual key code VK_SHIFT (0x10)
Key Character Code Duplicated by ANSI C Escape
Backspace 0x08 Ctrl-H \b
Tab 0x09 Ctrl-I \t
Ctrl-Enter 0x0A Ctrl-J \n
Enter 0x0D Ctrl-M \r
Esc 0x1B Ctrl-[
case WM_CHAR:
[other program lines]
switch (wParam)
{
case `\b': // backspace
[other program line
break ;
case `\t': // tab
[other program lines]
break ;
case `\n': // linefeed
[other program lines]
break ;
case `\r': // carriage return
[other program lines]
break ;
default: // character codes
[other program lines]
break ;
}
return 0 ;