- Home /
Multiple key. Press order
I try to do my own key mapping. I store the keys to use in array.
KeyCode[] keys = {KeyCode.LeftControl, KeyCode.Pause}
And then I check if the keys are pressed down with this code.
public static bool GetKeys(KeyCode[] keys){
foreach (KeyCode k in keys) {
Debug.Log(k);
if(k != KeyCode.None){
if(!Input.GetKey(k)){
return false;
}
}
}
return true;
}
If I first pressed down left ctrl and then pause nothing happens but if I press down Pause first and then left ctrl all works.
Not entirely sure what you mean by works but Get$$anonymous$$eys returns false if either key is detected. If you press pause then lctrlthen Get$$anonymous$$eys will have a chance to check both keys. If you press lctrl then pause then Get$$anonymous$$eys will always return false before it checks pause.
I mean when I first press pause and then left ctrl the method returns true and if I first press left ctrk the method returns false.
Why will the method returns false if I press left ctrl? Input.Get$$anonymous$$ey(k)
should return true when left ctrl is down and with ! before it should be false result in that it will skip the return false. And go to next value in the foreach loop.
Your answer
Follow this Question
Related Questions
While a menu is open. witch is the better way to don't allow other scrips get key codes? 2 Answers
Write custom input manager 0 Answers
How to make 2 doors with 2 diffrent keys 2 Answers
Why is GetKeyDown / Up behaving erratically, only responding occasionally in build? 1 Answer
Open door with key 2 Answers