简体   繁体   English

我在 C++ 中使用 _getch() 并且我想知道它是否可以检测到箭头键而不是其他键

[英]I'm using _getch() in C++ and i want to know if it can detect the arrow keys instead of the other keys

it's a console application if you guys wonder, i don't really have a problem with just using WASD instead but i wouldn't mind being able to use the arrow keys.如果你们想知道,它是一个控制台应用程序,我真的没有使用 WASD 的问题,但我不介意能够使用箭头键。

        char _input = 0;
        char _up = 'Z';
        char _down = 'S';
        char _left = 'Q';
        char _right = 'D';
        do
        {
            _input = _getch();

            switch (_input)
            {
                case 'Z':
                case 'z':
                    _input = _up;
                    break;
                case 'Q':
                case 'q':
                    _input = _left;
                    break;
                case 'S':
                case 's':
                    _input = _down;
                    break;
                case 'D':
                case 'd':
                    _input = _right;
                    break;
            }
        } while (_input == 0);

Here is the original answer :这是原始答案

Check for the following values:检查以下值:

KEY_UP = 72
KEY_DOWN = 80
KEY_LEFT = 75
KEY_RIGHT = 77

like喜欢

#define KEY_UP  72
...
...
do
{
    _value= _getch();
    switch(_value) {
        case KEY_UP: {...}
        ...
    }
} while (...);
...

and the docs defining all the keyboard values.以及定义所有键盘值的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM