G+_Cosmic Ray Posted February 24, 2014 Share Posted February 24, 2014 Padre, Where did Lou come up with key press "a" is 65, key press "b" is 66, etc. I know it's from Console.ReadKey().Key, but is there a table somewhere that shows all the equivalents to each key press? I tried Googling for it, and also looking on StackOverflow but couldn't find it. thanks Link to comment Share on other sites More sharing options...
G+_Chris Hightower Posted February 24, 2014 Share Posted February 24, 2014 www.asciitable.com Link to comment Share on other sites More sharing options...
G+_Cosmic Ray Posted February 24, 2014 Author Share Posted February 24, 2014 Hello Chris, Nice try, but from the table you linked to, "a" is 97, not 65. "A" is 65, so there must be more to it. In Lou's example, I can type either a or A and still get the same choice from the menu, but why? If the code is looking for 65, why does it accept 97 also? Link to comment Share on other sites More sharing options...
G+_Cosmic Ray Posted February 25, 2014 Author Share Posted February 25, 2014 Thanks, Neil. Odd that you found that in the Visual Basic section. As the example is for using C#, I would have never thought to look there! Yes, MSDN is a great source, if you know where to look. I notice in the tables you linked to that there's no distinction between capital and lower case letters, which also seems odd. Link to comment Share on other sites More sharing options...
G+_Volkan Paksoy Posted February 27, 2014 Share Posted February 27, 2014 Good point. Console.ReadKey() method returns a ConsoleKeyInfo struct and we access Key property which is an enumeration called ConsoleKey (http://msdn.microsoft.com/en-us/library/system.consolekey(v=vs.110).aspx). I think the main point is we don't actually get the raw key value and apparently it is implemented to return case-insensitive values. You can check the source code of the Console class and see how ReadKey() is implemented here: http://www.dotnetframework.org/default.aspx/DotNET/DotNET/8@0/untmp/whidbey/REDBITS/ndp/clr/src/BCL/System/Console@cs/2/Console@cs Or you can use a tool like JustDecompile from Telerik (which is free) just to play around and browse through the framework. Sometimes it helps to check out the actual implementation. Link to comment Share on other sites More sharing options...
G+_Joe Maruschek Posted February 27, 2014 Share Posted February 27, 2014 I wrote a short program that prints out all the key codes that are in the ConsoleKey enum: https://github.com/joemarus/Test1/blob/master/ListConsoleKey.cs I hope it helps! Link to comment Share on other sites More sharing options...
G+_Charles Kelly Posted March 6, 2014 Share Posted March 6, 2014 I modified the example to use a ConsoleKeyInfo variable for user input. That allows the use of ConsoleKey.A or ConsoleKey.Escape when comparing instead of the numbers. http://www.programming2dgames.com/files/Ep005rev2.cs Link to comment Share on other sites More sharing options...
Recommended Posts