GetKeyNameText

  int GetKeyNameText(lParam, lpszBuffer, cchMaxKey)    
  LONG lParam; /* second parameter of keyboard message */
  LPTSTR lpszBuffer; /* address of buffer for key name */
  int cchMaxKey; /* maximum key string length */

The GetKeyNameText function retrieves a string that represents the name of a key.

Parameters

lParam

Specifies the second parameter of the keyboard message (such as WM_KEYDOWN) to be processed. The function interprets the following portions of lParam:

Bits Meaning

16–23 Scan code.
24 Extended-key flag. Distinguishes some keys on an enhanced keyboard.
25 “Don't care” bit. The application calling this function sets this bit to indicate that the function should not distinguish between left and right CTRL and SHIFT keys, for example.

lpszBuffer

Points to a buffer that will receive the key name.

cchMaxKey

Specifies the maximum length, in characters, of the key name, not including the terminating null character (this parameter should be one less than the size of the buffer pointed to by the lpszBuffer parameter).

Return Value

The return value is the length ,in characters, of the string copied to the specified buffer, if the function is successful. Otherwise, it is zero.

Comments

The GetKeyNameText function may be used as either a wide-character function (where text arguments must use Unicode) or an ANSI function (where text arguments must use characters from the Windows 3.x character set).

The format of the key-name string depends on the current keyboard driver. The keyboard driver maintains a list of names in the form of character strings for keys with names longer than a single character. The key name is translated, according to the layout of the currently installed keyboard, into the principal language supported by the keyboard driver.