Rediger

Del via


Keyboard Input

This section describes how the system generates keyboard input and how an application receives and processes that input.

In This Section

Name Description
About Keyboard Input Discusses keyboard input.
Using Keyboard Input Covers tasks that are associated with keyboard input.
Keyboard Input Reference Contains the API reference.

Functions

Name Description
ActivateKeyboardLayout Sets the input locale identifier (formerly called the keyboard layout handle) for the calling thread or the current process. The input locale identifier specifies a locale as well as the physical layout of the keyboard.
BlockInput Blocks keyboard and mouse input events from reaching applications.
EnableWindow Enables or disables mouse and keyboard input to the specified window or control. When input is disabled, the window does not receive input such as mouse clicks and key presses. When input is enabled, the window receives all input.
GetActiveWindow Retrieves the window handle to the active window attached to the calling thread's message queue.
GetAsyncKeyState Determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.
GetFocus Retrieves the handle to the window that has the keyboard focus, if the window is attached to the calling thread's message queue.
GetKeyboardLayout Retrieves the active input locale identifier (formerly called the keyboard layout) for the specified thread. If the idThread parameter is zero, the input locale identifier for the active thread is returned.
GetKeyboardLayoutList Retrieves the input locale identifiers (formerly called keyboard layout handles) corresponding to the current set of input locales in the system. The function copies the identifiers to the specified buffer.
GetKeyboardLayoutName Retrieves the name of the active input locale identifier (formerly called the keyboard layout).
GetKeyboardState Copies the status of the 256 virtual keys to the specified buffer.
GetKeyNameText Retrieves a string that represents the name of a key.
GetKeyState Retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off alternating each time the key is pressed).
GetLastInputInfo Retrieves the time of the last input event.
IsWindowEnabled Determines whether the specified window is enabled for mouse and keyboard input.
LoadKeyboardLayout Loads a new input locale identifier (formerly called the keyboard layout) into the system. Several input locale identifiers can be loaded at a time, but only one per process is active at a time. Loading multiple input locale identifiers makes it possible to rapidly switch between them.
MapVirtualKey Translates (maps) a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code.
To specify a handle to the keyboard layout to use for translating the specified code, use the MapVirtualKeyEx function.
MapVirtualKeyEx Maps a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code. The function translates the codes using the input language and an input locale identifier.
OemKeyScan Maps OEMASCII codes 0 through 0x0FF into the OEM scan codes and shift states. The function provides information that allows a program to send OEM text to another program by simulating keyboard input.
RegisterHotKey Defines a system-wide hot key.
SendInput Synthesizes keystrokes, mouse motions, and button clicks.
SetActiveWindow Activates a window. The window must be attached to the calling thread's message queue.
SetFocus Sets the keyboard focus to the specified window. The window must be attached to the calling thread's message queue.
SetKeyboardState Copies a 256-byte array of keyboard key states into the calling thread's keyboard input-state table. This is the same table accessed by the GetKeyboardState and GetKeyState functions. Changes made to this table do not affect keyboard input to any other thread.
ToAscii Translates the specified virtual-key code and keyboard state to the corresponding character or characters. The function translates the code using the input language and physical keyboard layout identified by the keyboard layout handle.
To specify a handle to the keyboard layout to use to translate the specified code, use the ToAsciiEx function.
ToAsciiEx Translates the specified virtual-key code and keyboard state to the corresponding character or characters. The function translates the code using the input language and physical keyboard layout identified by the input locale identifier.
ToUnicode Translates the specified virtual-key code and keyboard state to the corresponding Unicode character or characters.
To specify a handle to the keyboard layout to use to translate the specified code, use the ToUnicodeEx function.
ToUnicodeEx Translates the specified virtual-key code and keyboard state to the corresponding Unicode character or characters.
UnloadKeyboardLayout Unloads an input locale identifier (formerly called a keyboard layout).
UnregisterHotKey Frees a hot key previously registered by the calling thread.
VkKeyScanEx Translates a character to the corresponding virtual-key code and shift state. The function translates the character using the input language and physical keyboard layout identified by the input locale identifier.

The following functions are obsolete.

Function Description
GetKBCodePage Retrieves the current code page.
keybd_event Synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.
VkKeyScan Translates a character to the corresponding virtual-key code and shift state for the current keyboard.

Messages

Name Description
WM_GETHOTKEY Determines the hot key associated with a window.
WM_SETHOTKEY Associates a hot key with the window. When the user presses the hot key, the system activates the window.

Notifications

Name Description
WM_ACTIVATE Sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously, first to the window procedure of the top-level window being deactivated, then to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately.
WM_APPCOMMAND Notifies a window that the user generated an application command event, for example, by clicking an application command button using the mouse or typing an application command key on the keyboard.
WM_CHAR Posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. The WM_CHAR message contains the character code of the key that was pressed.
WM_DEADCHAR Posted to the window with the keyboard focus when a WM_KEYUP message is translated by the TranslateMessage function. WM_DEADCHAR specifies a character code generated by a dead key. A dead key is a key that generates a character, such as the umlaut (double-dot), that is combined with another character to form a composite character. For example, the umlaut-O character ( ) is generated by typing the dead key for the umlaut character, and then typing the O key.
WM_HOTKEY Posted when the user presses a hot key registered by the RegisterHotKey function. The message is placed at the top of the message queue associated with the thread that registered the hot key.
WM_KEYDOWN Posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.
WM_KEYUP Posted to the window with the keyboard focus when a nonsystem key is released. A nonsystem key is a key that is pressed when the ALT key is not pressed, or a keyboard key that is pressed when a window has the keyboard focus.
WM_KILLFOCUS Sent to a window immediately before it loses the keyboard focus.
WM_SETFOCUS Sent to a window after it has gained the keyboard focus.
WM_SYSDEADCHAR Sent to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. WM_SYSDEADCHAR specifies the character code of a system dead key that is, a dead key that is pressed while holding down the ALT key.
WM_SYSKEYDOWN Posted to the window with the keyboard focus when the user presses the F10 key (which activates the menu bar) or holds down the ALT key and then presses another key. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYDOWN message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter.
WM_SYSKEYUP Posted to the window with the keyboard focus when the user releases a key that was pressed while the ALT key was held down. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYUP message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter.
WM_UNICHAR Posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. The WM_UNICHAR message contains the character code of the key that was pressed.

Structures

Name Description
HARDWAREINPUT Contains information about a simulated message generated by an input device other than a keyboard or mouse.
INPUT Contains information used for synthesizing input events such as keystrokes, mouse movement, and mouse clicks.
KEYBDINPUT Contains information about a simulated keyboard event.
LASTINPUTINFO Contains the time of the last input.
MOUSEINPUT Contains information about a simulated mouse event.

Constants

Name Description
Virtual-Key Codes The symbolic constant names, hexadecimal values, and mouse or keyboard equivalents for the virtual-key codes used by the system. The codes are listed in numeric order.

See also