- Home /
Multiple Keys down event
I have a problem solving how to create an event, where I detect multiple keys pressed at once. I have tried some different approaches:
if ((Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.D)) || Input.GetKey(KeyCode.D) && Input.GetKeyDown(KeyCode.LeftControl))
{
Debug.Log("Debug");
}
This is another approach, but same:
if (Input.GetKeyDown(KeyCode.LeftControl))
{
_ctrlDown = true;
}
if (Input.GetKeyUp(KeyCode.LeftControl))
{
_ctrlDown = false;
}
if (Input.GetKeyDown(KeyCode.D))
{
if (_ctrlDown)
{
Debug.Log("Debug");
}
}
if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.D))
{
Debug.Log("Debug");
}
I have tried to solve this different ways, but without any luck. I now suspect that the issue is I can't detect multiple key down events, can this somehow be a setting in windows, or my keyboard is so old, it's only sending one key at once?
I have tried to search the forum before I ask, but none of the solutions works for me. That's why I suspect it's somehow related to my keyboard and/or windows.
Anyone who can help me identifying this?
Answer by GameVortex · Jan 12, 2015 at 08:39 AM
I get the same results. I expect this is how keyboards work. When holding the LeftCtrl and then pressing the D button the keyboard does not actually send the CTRL and D keycodes. It sends the Keycode for the CTRL-D combination which unity does not register at runtime. It does however work in editor mode with editor Events where you can query if the Control button is down and then query for the specific button you want.
Sorry for the long delay! The problem is that Unity is using the ctrl key, so it's actual working in a stand alone application. Thanks for the answer!
Answer by seejayjames · Jul 05, 2020 at 10:05 PM
Best to never use control or alt for any input, given that they are used by programs for other purposes. Shift should be fine. You can also use multiple key combinations if you track GetKey && GetKey, then use that to set a bool, then do your action and set the bool back to false.
Your answer
Follow this Question
Related Questions
Problem with pressing multiple keys at once? 2 Answers
Playing Animation When Two Keys Are Held Down To Play Run Animations 0 Answers
Double tap to dash (With Multiple keypress) 0 Answers
Barrel Roll on Double Key Press, right & left 2 Answers
How could i execute a command move for a fighting game? 3 Answers