This method is called by the input method (IM) to simulate a keystroke or a virtual key. The key event is sent to the window that currently has the focus; that is, the window that would have received keyboard input if a key had been pressed on an external keyboard.

HRESULT SendVirtualKey( 
BYTE bVk, 
DWORD dwFlags);


  • bVk
    Byte containing the virtual key code of the key to simulate.
  • dwFlags
    Specifies the state of the key. It is any combination of the following values:
    Value Description
    KEYEVENTF_KEYUP If this flag is set, a call to SendVirtualKey generates a WM_KEYUP message. If this flag is not set, a call to SendVirtualKey generates a WM_KEYDOWN message.
    KEYEVENTF_SILENT If this flag is set, the key the user pressed to activate SendVirtualKey does not make a keyboard click sound, even if clicks are enabled on the device.

Return Values

An appropriate HRESULT value is returned.


This function modifies the global key state for the virtual key sent in bVk. For example, an IM can use this method to send SHIFT, CTRL, and ALT key up and down events. These events are retrieved when an application calls the GetKeyState function. This method should send virtual key events that do not have associated characters; that is, it should not send VK_* messages that cause a WM_CHAR message to be sent in the TranslateMessage function. If a character-producing virtual key is sent by this method, the key is modified by the global key state. For example, an application can use this method to send a VK_5 message to the current application. If the SHIFT global key is currently down, the application receives the "%" character message, depending on the computer's keyboard driver. You can also send character messages and strings using the IIMCallback::SendCharEvents and IIMCallback::SendString methods. Call the SendCharEvents and SendString methods instead of the keybd_event function while programming an IM.


Runs On Versions Defined in Include Link to
Windows CE OS 2.01 and later Sip.h    

Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

keybd_event, GetKeyState, WM_CHAR, WM_KEYDOWN, WM_KEYUP, IIMCallback::SendCharEvents, IIMCallback::SendString

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.