使用箭头键在控制台中导航

Rei*_*awi -3 c# arrow-keys

我正在制作菜单.我想使用箭头键从我的列表中选择.

char move;

do
{
    move = (char)_getch();
    if (move == 38)
    {
         // Move Indicator Up   
    }
    else if (move == 40)
    {
         // Move Indicator Down
    }
}
while (move != 13);
Run Code Online (Sandbox Code Playgroud)

我是否使用上下键的错误ascii值?

解决了

我将(char)_getch()替换为(int)_getch()并将char移动到int然后移动38和40到?? 和80

K M*_*hta 6

好像你是DllImporting msvcrt.dll来使用_getch()

尝试使用Console.ReadKey()

ConsoleKeyInfo keyInfo = Console.ReadKey();
if (keyInfo.Key == ConsoleKey.UpArrow) {

} else if (keyInfo.Key == ConsoleKey.DownArrow) {

} ...
Run Code Online (Sandbox Code Playgroud)