Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 201453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:12:01+00:00 2026-05-11T17:12:01+00:00

I want the user to be able to have some data already in the

  • 0

I want the user to be able to have some data already in the input stream that they can change. I looked into the below function, but I’m not sure how to get the Console handle from the Console class.

    [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern bool WriteConsoleInput(
        IntPtr hConsoleInput,
        [Out] INPUT_RECORD[] lpBuffer,
        int nLength,
        out int lpNumberOfEventsWritten);


    public static void WriteConsoleInput()
    {
        UInt32 STD_INPUT_HANDLE = 0xfffffff6;
        IntPtr hConsoleInput = GetStdHandle(STD_INPUT_HANDLE);


        INPUT_RECORD[] lpBuffer = new INPUT_RECORD[2];

        // I tried using uChar (short) as well. 
        lpBuffer[0].Event.KeyEvent.wVirtualKeyCode = 0x41; // A
        lpBuffer[1].Event.KeyEvent.wVirtualKeyCode = 0x5A; // Z

        int nLength = lpBuffer.Length;
        int lpNumberOfEventsWritten;
        if (!WriteConsoleInput(
            hConsoleInput,
            lpBuffer,
            nLength,
            out lpNumberOfEventsWritten))
        {
            // Don't get here.
            Console.WriteLine("Error: {0}", GetLastError());
        }
    } // A breakpoint here shows that lpNumberOfEventsWritten is 2

    ...
    ...
    ...

    Console.Write("Input something: ");
    WriteConsoleInput();
    String input = Console.ReadLine();
    Console.WriteLine("input = {0}", input);

I don’t see anything on the screen behind the “Input something: “. If I just hit enter, input is an empty string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:12:02+00:00Added an answer on May 11, 2026 at 5:12 pm

    Rather than mixing managed and unmanaged (which is likely to mess up assumptions System.Console makes) I would suggest just using P/Invoke the whole way.

    MSDN has an example: http://msdn.microsoft.com/library/ms685035

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some CSV data files that I want to import into mySQL. I
I have a MovieClip that I want the user to be able to drag
I have a dictionary of strings that i want the user to be able
I want to send some data to a user after they log in to
I want my user to be able to hit the submit button and have
I have an image carousel and shadowbox. I want the user to be able
I have a user database which I want the admin to be able view
I want the user to be able to make some preferences like colors, prefered
I want the user to be able to select an option, which would change
I am building my first chrome extension, for that I want to have some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.