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

  • Home
  • SEARCH
  • 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 896815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:47:24+00:00 2026-05-15T14:47:24+00:00

When using Console.Read(), the implementation seems to think that as soon as you push

  • 0

When using Console.Read(), the implementation seems to think that as soon as you push enter, you’ve entered enough bytes for an eternity of reads. For example, if Read is called twice in a row, you can’t enter one value on one line, push enter, and move to the next. Even if you only entered one character, Read just returns zero (Edit: Or one. I’m not too sure.). I’ve got this problem with ReadLine too. I’m trying to keep my console open for input after the program’s terminated (I have a WPF app and used AllocConsole manually) and/or prompt the user for each individual slice of input. But it worketh not. Is there some button to ask it to block if there’s no input available?

I wrote a Brainfuck interpreter, and the example programs from Wiki produce the intended result, if they don’t use input.

What I want to do is enter one character, push enter, get that character as a char, repeat.

  • 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-15T14:47:25+00:00Added an answer on May 15, 2026 at 2:47 pm

    After your last edit I expect the piece of code below might provide either what you want or point you in the right direction.

    public static int ReadLastKey()
    {
      int lastKey = -1;
      for(;;)
      {
        ConsoleKeyInfo ki = Console.ReadKey();
        if (ki.Key != ConsoleKey.Enter)
        {
          lastKey = (int)ki.KeyChar;          
        }
        else
        {
          return lastKey;
        }
      }       
    }
    

    The function ReadLastKey will read key strokes and return the last key pressed when you press enter.

    Of course if you do not want multiple key presses to be recorded you can remove the loop and just use Console.ReadKey twice, once to get the key press and then a second time to wait for the enter key. Or some permutation of one of these.

    Here is a simple version of the function that will allow only one key press and then wait for the enter key to be pressed. Note this is very simplistic, you might want to handle other exit conditions etc.

    public static int ReadLastKey()
    {
      int lastKey = -1;
      ConsoleKeyInfo ki;
    
      // Read initial key press
      ki = Console.ReadKey();
    
      // If it is enter then return -1
      if (ki.Key == ConsoleKey.Enter) return lastKey;
    
      lastKey = (int)ki.KeyChar;
    
      // Wait for the user to press enter before returning the last key presss,
      // and do not display key the errant key presses.
      do
      {
        ki = Console.ReadKey(true);
      } while (ki.Key != ConsoleKey.Enter);
    
      return lastKey;      
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a remote file using HttpWebRequest in a C# Console
I'm having some inexplicable behaviour using jQuery 1.4.2, and I'm beginning to think that
I'm using console.log(variable) and firebug to examine javascript code. Occasionally, I get [object][object] as
I am using .NET console application to gather performance data of the system. For
I am using the console application i used multi threading in the same. I
How can I execute a test case from Command Console using NUnit? I had
I would like to spawn a Windows form from the console using C#. Roughly
I am trying to upload my GAE app using the console in windows. I
I'm trying to debug tests from visual studio using nunit-console using a VS-macro, but
I would like to color format the text printed to the console using the

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.