How to Use Key Combinations with the Control-Key?

In the Unity 5 editor, when I try to give input in Update with a control-key mod, the key-press of another key is not rightly registered.

If I have:

void Update()
{
        if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) &&          
             Input.GetKey(KeyCode.X)) Debug.Log(true);
}

And my input is: Left-Ctrl + X, nothing is printed. Same with Right-Ctrl + X.

However, if I have Shift + Ctrl + X, then “true” is printed! By not specifying “right” or “left,” I mean to imply it does not matter which is the case.

And Alt + Ctrl + X also prints “true”

This is true for all the letters on a standard keyboard in-place of X, it would seem after testing a few.

However, if I have

void Update()
{
        if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) &&                             Input.GetKeyDown(KeyCode.Alpha1))) Debug.Log(true);
}

By pressing a Ctrl-Key alone will solicit the output: “true”

I have no problem integrating the control-keys with mouse clicks nor shift or alt with other keys, so what is happening here that is messing with the input so?

Edit: I want to clarify that it works when I build the project, but as noted at the beginning this weird, and I hesitate to call it a bug, “bug” only exists in the editor. I’m trying to find a way around it.

1 Like

There are some answers over here - https://answers.unity.com/questions/49285/how-can-i-get-a-combination-of-keys-pressed.html?_ga=2.23479418.1148461192.1613246522-1228664066.1589857462

@zckhyt

Try this

if (Input.GetKey(KeyCode.RightControl)
{
if (Input.GetKey(KeyCode.LeftControl)
{
Debug.Log(true);
}