-1

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.

        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);
MaxCE
  • 7
  • 3
  • Hey! Could you add some code you wrote? In order to be able to help you it's important to see what you're actually trying to do. The minimal code needed to understand the flow in the specific code should be enough (the method, or the class if it's small). – Josef Ginerman Jan 11 '21 at 16:45
  • 1
    i don't think it's important but done – MaxCE Jan 11 '21 at 16:52
  • The arrow keys may require two reads. The first value read is an extended code, then the second key is the arrow key value. Depends on the OS. – Thomas Matthews Jan 11 '21 at 17:36
  • the os is windows 10 – MaxCE Jan 11 '21 at 17:37
  • if your call to _getch() or _getche() returns 0 or 0xE0 then the next call to _getch() will give you the special key-code. – engf-010 Jan 11 '21 at 18:30
  • You can find the solution [here](https://stackoverflow.com/questions/24708700/c-detect-when-user-presses-arrow-key). – Josef Ginerman Jan 11 '21 at 19:30

1 Answers1

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.

Josef Ginerman
  • 1,460
  • 13
  • 24