Keyboard Input Challenge

The keyboard has a physical limitation of accepting up to 3 key inputs. Example: Ctrl+Alt+Delete on a PC

I need code in Unity that will accept a 3 key input combination. The input combination MUST use [down arrow]+[left arrow]+[any other key].

I have code that will do any 3 key combos except for this challenge. I need to know if this is a bug in my code or Unity.

Thanks for taking a look.
Cheers,

The 3 key limit only applies to non-USB keyboards; USB keyboards do not have such a limit.

You could just check for the keys using if statements:

if (Input.GetButtonDown("Left")  Input.GetButtonDown("Down")  (Input.GetButtonDown("Other")) {
    // Do something when those keys are pressed
}

Replace “Left”, “Down” and “Other” as necessary.

You could nest the if statements as well:

if (Input.GetButtonDown("Left")) {
    if (Input.GetButtonDown("Down")) {
        if (Input.GetButtonDown("Other")) {
            // Do something
        }
    }
}

If you want the third key to be any key on the keyboard, I’m not sure how you would do that. I doubt that Input.anyKeyDown would ever work, since it would already be returning true since “Left” and “Down” were already pressed.

Not necessarily true… My Apple USB keyboard has a limit for the maximum number of concurrent keypresses, but the number varies depending on which keys you press. For example, if I hold multiple letters on the same row, I can get up to six to register. However, if I press certain clusters of keys, it can be as few as two. In particular, I can’t get all four arrow keys to register at once; only two or three register, depending on the combination (the assumption seems to be that you won’t want to press up and down simultaneously while pressing left or right).

You can check this out by adding the Keyboard Viewer palette to the Input Menu, then holding keys while watching the display (preferably while using an application which doesn’t mind random keypresses!).

The worst thing is that the precise behaviour of the keyboard is hardware specific, so some keyboards might work better than others in this respect.

Thanks for the replies.
It looks like it is the keyboard.
[down]++[alpha keys] DO NOT WORK
[down]++[ctrl or shift] WORKS

Cheers,
-VICTOM

I can apparently hold down, left and most alpha keys, except for a stripe in the middle of the keyboard. Looks like it’s not going to work reliably.

Incidentally, the modifier keys (shift, option, control, command and caps lock) are not subject to this limitation. They always work, even all at once in conjunction with any other keys. This makes them pretty good for use as action buttons in games.