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 7842469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:19:44+00:00 2026-06-02T16:19:44+00:00

Readed about 30 minutes, and didn’t found some specific for this in this site.

  • 0

Readed about 30 minutes, and didn’t found some specific for this in this site.

Suppose the following, in C#, console application:

ConsoleKeyInfo cki;
cki = Console.ReadKey(true);
Console.WriteLine(cki.KeyChar.ToString()); //Or Console.WriteLine(cki.KeyChar) as well
Console.ReadKey(true);

Now, let’s put ¿ in the console entry, and asign it to cki via a Console.ReadKey(true). What will be shown isn’t the ¿ symbol, the ¨ symbol is the one that’s shown instead. And the same happens with many other characters. Examples: ñ shows ¤, ¡ shows -, ´ shows ï.

Now, let’s take the same code snipplet and add some things for a more Console.ReadLine() like behavior:

string data = string.Empty;
ConsoleKeyInfo cki;
for (int i = 0; i < 10; i++)
{
    cki = Console.ReadKey(true);
    data += cki.KeyChar;
}
Console.WriteLine(data);
Console.ReadKey(true);

The question, how to handle this by the right way, end printing the right characters that should be stored on data, not things like ¨, ¤, -, ï, etc?

Please note that I want a solution that works with ConsoleKeyInfo and Console.ReadKey(), not use other variable types, or read methods.

EDIT:

Because ReadKey() method, that comes from Console namespace, depends on Kernel32.dll and it definetively bad handles the extended ASCII and unicode, it’s not an option anymore to just find a valid conversion for what it returns.

The only valid way to handle the bad behavior of ReadKey() is to use the cki.Key property that’s written in cki = Console.ReadKey(true) execution and apply a switch to it, then, return the right values on dependence of what key was pressed.

For example, to handle the Ñ key pressing:

string data = string.Empty;
ConsoleKeyInfo cki;
cki = Console.ReadKey(true);
switch (cki.Key)
{
    case ConsoleKey.Oem3:
        if (cki.Modifiers.ToString().Contains("Shift")) //Could added handlers for Alt and Control, but not putted in here to keep the code small and simple
            data += "Ñ";
        else
            data += "ñ";
        break;
}
Console.WriteLine(data);
Console.ReadKey(true);

So, now the question has a wider focus… Which others functions completes it’s execution with only one key pressed, and returns what’s pressed (a substitute of ReadKey())? I think that there’s not such substitutes, but a confirmed answer would be usefull.

  • 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-06-02T16:19:45+00:00Added an answer on June 2, 2026 at 4:19 pm

    ReadLine() reconfigures the codepage to use properly the extended ASCII and Unicode characters. ReadKey() leaves it in EN-US default (codepage 850).

    Just use a codepage that prints the characters you want, and that’s all. Refer to http://en.wikipedia.org/wiki/Code_page for some of them 🙂

    So, for the Ñ key press, the solution is this:

    Console.OutputEncoding = Encoding.GetEncoding(1252); //Also 28591 is valid for `Ñ` key, and others too
    string data = string.Empty;
    ConsoleKeyInfo cki;
    cki = Console.ReadKey(true);
    data += cki.KeyChar;
    Console.WriteLine(data);
    Console.ReadKey(true);
    

    Simple 🙂

    And a side note: in some cases it’s also necessary to reconfigure the Console.InputEncoding property!

    Also, note that if you select another font for the console (Lucida Console/Consolas), this trouble STILLS happen. Lotta thanks to user Abel for this, he appointed to the font changing for solution and made myself discover that this is false.

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

Sidebar

Related Questions

I have readed something about it i wanna to do some implementation using this.
I readed some tutorials about making droplets with apple script or with automator's help.
where i can found some good examples / tutorials about the usage ZXing (reader
I readed manu articles about this, but - still confused. from Form1 I open
I searched about this error and i found it usually happen when you try
I am doing some development about google reader on android platform. Using google reader
I didn't find anything about parsing HTML in the XML::LibXML::Reader documentation. And I tried
think about this: StreamReader reader = null; try { reader = new StreamReader(_fileName); }
We've just had a discussion with college about is the following style acceptable for
I readed State Machine Ruby README.md at github. I want to integrate SM with

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.