次の方法で共有


PostKeybdMessageEx (Compact 2013)

3/28/2014

This function posts a keyboard message to the specified window. It is similar to PostKeybdMessage, except that it allows you to specify which keyboard produced the key event.

Syntax

BOOL PostKeybdMessageEx( 
  HWND hwnd, 
  UINT VKey, 
  KEY_STATE_FLAGS KeyStateFlags, 
  UINT cCharacters, 
  UINT* pShiftStateBuffer, 
  UINT* pCharacterBuffer, 
  GUID *pguidKeyboard 
);

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.
  • pguidKeyboard
    [in] Specifies a keyboard based on the ID in the HKEY_CURRENT_USER\Keyboard Layout\Preload registry key.

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 (deprecated) function, PostKeybdMessageEx does not affect the global key state.

PostKeybdMessageEx does not support a different state for each translated character. If a different state is required for each character, then individual calls to PostKeybdMessageEx 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.

PostKeybdMessageEx checks the HKEY_CURRENT_USER\Keyboard Layout\Preload registry key for the current active IME/Keyboard layout and determines whether to switch to the IME/Keyboard layout defined by pguidKeyboard. If it is necessary to switch, PostKeybdMessageEx calls ActivateKeyboardLayout to set the layout defined in the registry. Finally, it calls PostKeybdMessage to post the keyboard event to the system in the same way that keyboard messages are posted on single keyboard devices.

Requirements

Header

winuser.h

Library

Kbdui.lib

See Also

Reference

Keyboard Functions
keybd_event (deprecated)
TranslateMessage