keybd_event (user32)
Last changed: -

The keybd_event API

C# Signature:

static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
   UIntPtr dwExtraInfo);

User-Defined Types:




Tips & Tricks:

This function is usefull to simulate Key presses (for input use the virtual keycodes from (see also VkKeyScan):

    void PressKey( byte keyCode )
        const int KEYEVENTF_EXTENDEDKEY = 0x1;
        const int KEYEVENTF_KEYUP       = 0x2;
        keybd_event( keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0 );
        keybd_event( keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );

Sample Code:

Please add some!

Alternative Managed API: System.Windows.Forms.SendKeys

keybd_event on MSDN

PROBLEM: How do i use combination of shift and tab keys at the same time ?

Answer:posted by dokks

define the shift key as a const

    public const byte VK_LSHIFT= 0xA0; // left shift key
    public const byte VK_TAB = 0x09;
    public const int KEYEVENTF_EXTENDEDKEY = 0x01;
    public const int KEYEVENTF_KEYUP = 0x02;

    //press the alt key
    keybd_event(VK_LSHIFT, 0x45, 0, 0);

    //press the tab key
    keybd_event(VK_TAB, 0x45, 0, 0);

    //release the tab key
    keybd_event(VK_TAB, 0x45, KEYEVENTF_KEYUP, 0);

    //release the alt key
    keybd_event(VK_LSHIFT, 0x45, KEYEVENTF_KEYUP, 0);