簡體   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

如果你們想知道,它是一個控制台應用程序,我真的沒有使用 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);

這是原始答案

檢查以下值:

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

喜歡

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

以及定義所有鍵盤值的文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM