Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
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 hwndis NULL, then the keyboard message is sent to the active window or window with the focus of the calling thread. If hwndis –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 pCharacterBufferto translate.

cCharacters

[in] Number of characters in the pCharacterBufferarray.

pShiftStateBuffer

[in] Pointer to a buffer that contains a corresponding shift state entry for each character in the pCharacterBufferarray. The shift state for each character must be the same as the KeyStateFlagsparameter. 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 pCharacterBufferare the characters posted to the receiver's queue when TranslateMessageis called for the VK key event. Unlike the keybd_eventfunction, PostKeybdMessagedoes not affect the global key state.

PostKeybdMessagedoes not support a different state for each translated character. If a different state is required for each character, then individual calls to PostKeybdMessagemust be made.

If VKeyis set to 0 when TranslateMessageis 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

See Also