Question about Key down

Is there a way I can check if any key is held down and return the key that’s held down?

switch (GetKeyDown())
        {
        // UP
        case KEY_W:
        case KEY_UP:
            verticalInput = -1;
            break;

        // RIGHT
        case KEY_D:
        case KEY_RIGHT:
            horizontalInput = 1;
            break;

        // DOWN
        case KEY_S:
        case KEY_DOWN:
            verticalInput = 1;
            break;

        // LEFT
        case KEY_A:
        case KEY_LEFT:
            horizontalInput = -1;
            break;

        default:
            horizontalInput = 0;
            verticalInput = 0;
            break;
        }

By design, Raylib is very limited in its capabilities. You would need to come up with the system yourself in this case but here are a few of hints.

  1. Create a bool that indicates if a button is being held down.
  2. Store the key that’s being held down in a variable (you can probably do something like int keyHeld = GetKeyPressed())
  3. Then, you can test if that key has been released using IsKeyUp(keyHeld)
1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms