How to output windows Alt keycodes in a C# console app

不羁岁月 提交于 2019-12-11 04:09:37

问题


How can I output Windows Alt key codes to the console in a C# console app using Console.WriteLine()?

I would like to output characters such as those used for creating boxes. I can do so manually in a command prompt by holding alt and typing in the appropriate number such as Alt+205, Alt+187, etc.

Thanks


回答1:


I suppose the easiest way would be to include them directly in your string literals within your source code:

Console.WriteLine("═╗");



回答2:


EDIT: I'm sorry - my answer is incorrect. ASCII.GetChars will not work for extended ASCII characters. Thanks to Douglas for correcting me.


I think Douglas's answer is the most direct, but you could also get the character based on the value directly using something like this:

char[] characters = System.Text.Encoding.ASCII.GetChars(new byte[] {65});

For whatever ASCII code you wanted.



来源:https://stackoverflow.com/questions/10870533/how-to-output-windows-alt-keycodes-in-a-c-sharp-console-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!