PostKeybdMessage
A version of this page is also available for
4/8/2010
This function posts a keyboard message to the specified window.
Syntax
BOOL PostKeybdMessage(
HWND hwnd,
UINT VKey,
KEY_STATE_FLAGS KeyStateFlags,
UINT cCharacters,
UINT* pShiftStateBuffer,
UINT* pCharacterBuffer
);
Parameters
- hwnd
[in] Handle to the window that receives the message. It must identify a window owned by the calling thread. If hwnd is NULL, then the keyboard message is sent to the active window or window with the focus of the calling thread. If hwnd is –1, then the keyboard message is sent to the active window or window with the focus of the system foreground thread.
- VKey
[in] Virtual key code. This parameter can be set to 0.
KeyStateFlags
[in] State of the key. The key states are described in the following table.Flag Description KeyStateToggledFlag
Key is toggled.
KeyStatePrevDownFlag
Key was previously down.
KeyStateDownFlag
Key is currently down.
KeyShiftAnyCtrlFlag
Left or right CTRL key is down.
KeyShiftAnyShiftFlag
Left or right SHIFT key is down.
KeyShiftAnyAltFlag
Left or right ALT key is down.
KeyShiftCapitalFlag
VK_CAPITAL is toggled.
KeyShiftLeftCtrlFlag
Left CTRL key is down.
KeyShiftLeftShiftFlag
Left SHIFT key is down.
KeyShiftLeftAltFlag
Left ALT key is down.
KeyShiftLeftWinFlag
Left Windows logo key is down.
KeyShiftRightCtrlFlag
Right CTRL key is down.
KeyShiftRightShiftFlag
Right SHIFT key is down.
KeyShiftRightAltFlag
Right ALT key is down.
KeyShiftRightWinFlag
Right Windows logo key is down
KeyShiftDeadFlag
Corresponding character is dead character.
KeyShiftNoCharacterFlag
No characters in pCharacterBuffer to translate.
- cCharacters
[in] Number of characters in the pCharacterBuffer array.
- pShiftStateBuffer
[in] Pointer to a buffer that contains a corresponding shift state entry for each character in the pCharacterBuffer array. The shift state for each character must be the same as the KeyStateFlags parameter. This parameter cannot be NULL.
- pCharacterBuffer
[in] Pointer to a buffer that contains the characters to send. This parameter cannot be NULL.
Return Value
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.
Remarks
The characters in pCharacterBuffer are the characters posted to the receiver's queue when TranslateMessage is called for the VK key event. Unlike the keybd_event function, PostKeybdMessage does not affect the global key state.
PostKeybdMessage does not support a different state for each translated character. If a different state is required for each character, then individual calls to PostKeybdMessage must be made.
If VKey is set to 0 when TranslateMessage is called, then the virtual key translation is also set to 0. Because 0 is not valid for virtual key, an application should ignore it.
Requirements
Header | winuser.h |
Library | Kbdui.lib |
Windows Embedded CE | Windows CE 2.0 and later |
Windows Mobile | Windows Mobile Version 5.0 and later |