Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
sendinput (coredll)
 

coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for sendinput in other DLLs exists, click on Find References to the right.

.
Summary
TODO - a short description

C# Signature:

[DllImport("coredll.dll", SetLastError=true)]
static extern uint SendInput(uint cInputs, /* [MarshalAs(UnmanagedType.LPArray)] */ KEYBOARDINPUT[] inputs, int cbSize);

VB Signature:

Declare Function SendInput Lib "coredll.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

public class cTabControl

    {

    // The unused private fields below are required to match the native structure layout.
    #pragma warning disable 0169
        public struct KEYBOARDINPUT
        {
            public uint type;
            public ushort wVk;
            ushort wScan;
            public uint dwFlags;
            uint time;
            uint dwExtraInfo;
            uint unused1;
            uint unused2;
        }
    #pragma warning restore 0169

        public const uint INPUT_KEYBOARD = 1;
        public const uint KEYEVENTF_KEYUP = 2;
        public const ushort VK_TAB = 0x0009;
        public const ushort VK_SHIFT = 0x0010;
        public const ushort VK_CTRL = 0x0011;

        [DllImport("coredll.dll", SetLastError = true)]
        public static extern uint SendInput(uint cInputs, /* [MarshalAs(UnmanagedType.LPArray)] */ KEYBOARDINPUT[] inputs, int cbSize);

    #region SetTab
    /// <summary>
    /// Force the system to react, as if the Tab-key was pressed
    /// </summary>
    public static void SetTab()
    {
        KEYBOARDINPUT[] inputs;
        uint retVal;
        int error;
        inputs = new cTabControl.KEYBOARDINPUT[2];
        inputs[0].type = inputs[1].type = cTabControl.INPUT_KEYBOARD;
        inputs[0].wVk = inputs[1].wVk = cTabControl.VK_TAB;
        inputs[1].dwFlags = cTabControl.KEYEVENTF_KEYUP;
        retVal = cTabControl.SendInput(2, inputs, 0x001C);
        if (retVal != 2)
        {
        error = Marshal.GetLastWin32Error();
        throw new Exception(string.Format("SendInput() returned {0}.", error));
        }
    }
    #endregion

    #region SetShiftTab
    /// <summary>
    /// Force the system to react, as if the Shift- and Tab-key was pressed
    /// </summary>
    public static void SetShiftTab()
    {
        KEYBOARDINPUT[] inputs;
        uint retVal;
        int error;
        inputs = new cTabControl.KEYBOARDINPUT[4];
        inputs[0].type = inputs[1].type = inputs[2].type = inputs[3].type = cTabControl.INPUT_KEYBOARD;
        inputs[0].wVk = inputs[3].wVk = cTabControl.VK_SHIFT;
        inputs[1].wVk = inputs[2].wVk = cTabControl.VK_TAB;
        inputs[2].dwFlags = inputs[3].dwFlags = cTabControl.KEYEVENTF_KEYUP;
        retVal = cTabControl.SendInput(4, inputs, 0x001C);
        if (retVal != 4)
        {
        error = Marshal.GetLastWin32Error();
        throw new Exception(string.Format("SendInput() returned {0}.", error));
        }
    }
    #endregion

    #region SetCtrlTab
    /// <summary>
    /// Force the system to react, as if the Ctrl- and Tab-key was pressed
    /// </summary>
    public static void SetCtrlTab()
    {
        KEYBOARDINPUT[] inputs;
        uint retVal;
        int error;
        inputs = new cTabControl.KEYBOARDINPUT[4];
        inputs[0].type = inputs[1].type = inputs[2].type = inputs[3].type = cTabControl.INPUT_KEYBOARD;
        inputs[0].wVk = inputs[3].wVk = cTabControl.VK_CTRL;
        inputs[1].wVk = inputs[2].wVk = cTabControl.VK_TAB;
        inputs[2].dwFlags = inputs[3].dwFlags = cTabControl.KEYEVENTF_KEYUP;
        retVal = cTabControl.SendInput(4, inputs, 0x001C);
        if (retVal != 4)
        {
        error = Marshal.GetLastWin32Error();
        throw new Exception(string.Format("SendInput() returned {0}.", error));
        }
    }
    #endregion

    #region SetCtrlShiftTab
    /// <summary>
    /// Force the system to react, as if the Ctrl-, Shift- and Tab-key was pressed
    /// </summary>
    public static void SetCtrlShiftTab()
    {
        KEYBOARDINPUT[] inputs;
        uint retVal;
        int error;
        inputs = new cTabControl.KEYBOARDINPUT[6];
        inputs[0].type = inputs[1].type = inputs[2].type = inputs[3].type = inputs[4].type = inputs[5].type = cTabControl.INPUT_KEYBOARD;
        inputs[0].wVk = inputs[5].wVk = cTabControl.VK_CTRL;
        inputs[1].wVk = inputs[4].wVk = cTabControl.VK_SHIFT;
        inputs[2].wVk = inputs[3].wVk = cTabControl.VK_TAB;
        inputs[2].dwFlags = inputs[5].dwFlags = cTabControl.KEYEVENTF_KEYUP;
        retVal = cTabControl.SendInput(6, inputs, 0x001C);
        if (retVal != 6)
        {
        error = Marshal.GetLastWin32Error();
        throw new Exception(string.Format("SendInput() returned {0}.", error));
        }
    }
    #endregion

    }

Documentation
SendInput on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions