Question - can we use switch to get which key is pressed?

I have a question - Is it possible to solve discussed problem of getting which key is pressed by using switch operator? With something like this (It is not working, of course, but maybe some solution is possible?):

   switch (input.getkey())
        {
            case KeyCode.A:
                print("Rotate left");
                break;
            case KeyCode.D:
                print("rotate right");
                break;
            case KeyCode.D & KeyCode.A:
                print("Can't rotate in both directions");
                break;
            case KeyCode.Space:
                print("Space is pressed");
                break;
        }

Thanks!

The problem is that once a case is found the switch statement will break (exit). You could try putting the (D & A) as the first case, then if that is false it will look at the next case.

1 Like

Privacy & Terms