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
WriteConsoleInput (kernel32)
 
.
Summary

C# Signature:

    /* Writes data directly to the console input buffer. */
    [DllImport("kernel32.dll", EntryPoint = "WriteConsoleInputW", CharSet = CharSet.Unicode, SetLastError = true)]
    internal static extern bool WriteConsoleInput(
        IntPtr hConsoleInput,
        INPUT_RECORD[] lpBuffer,
        uint nLength,
        out uint lpNumberOfEventsWritten);

User-Defined Types:

Notes:

The only practical usage for this i've found is for debugging code reliant on ReadConsoleInput.

Please add if you've found something else that's useful

Tips & Tricks:

Please add some!

Sample Code:

    [DllImport("kernel32")]
    public static extern IntPtr GetStdHandle(StdHandle index);

    public enum StdHandle
    {
    OutputHandle = -11,
    InputHandle = -10,
    ErrorHandle = -12
    }

    static void Main(string[] args)
    {
    INPUT_RECORD[] record = new INPUT_RECORD[1];

    record[0].EventType = INPUT_RECORD.KEY_EVENT;

    record[0].KeyEvent = new KEY_EVENT_RECORD();
    record[0].KeyEvent.UnicodeChar = 'a';
    record[0].KeyEvent.AsciiChar = (byte)'a';
    record[0].KeyEvent.bKeyDown = true;

    uint recordsWritten = 0;
    bool boi = WriteConsoleInput(GetStdHandle(StdHandle.InputHandle), record, 1, out recordsWritten);
    }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

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