- Home /
How can I make it so more than two or three buttons can be pressed at a time?
I'm making a First Person Shooter and I want the Up arrow to make the character walk forward, the Up arrow and Shift combined to make the character run, and finally for the Up arrow and Shift and Control combined to make the character slide. I have already confirmed that the error has to do with Unity setting the maximum inputs to 2 or 3 keys at a time. I just wanted to know if I can get around that issue another way besides changing my inputs to use capslock or tab. Thank you in Advance
Answer by DerDerErIst · Dec 12, 2017 at 10:17 PM
u try to archive this with Buttons (UI Elements) or Keys (Keyboard)?
Unity can handle alot more Input than just 3 Keys from ur Keyboard. Just try following:
int KeyOne = 1;
int KeyTwo = 2;
int KeyThree = 3;
int KeyFour = 4;
int KeyFive = 5;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.Alpha1))
Debug.Log("Key " + KeyOne);
if (Input.GetKey(KeyCode.Alpha2))
Debug.Log("Key " + KeyTwo);
if (Input.GetKey(KeyCode.Alpha3))
Debug.Log("Key " + KeyThree);
if (Input.GetKey(KeyCode.Alpha4))
Debug.Log("Key " + KeyFour);
if (Input.GetKey(KeyCode.Alpha5))
Debug.Log("Key " + KeyFive);
}
u can make this List longer and try to figure out how much Keys Unity can handle. I used orginal Setup from unity Project and just added this Test Script to an Empty GameObject now i press every 5 Keys at the same time and see there it handles every Frame all my 5 Inputs.
Perhaps its ur Keyboard i know from older Keyboards special Old Mechanical Keyboards that they cant handle more then 2 to 3 Keys at the same time, when i was young i had alot of trouble when i writing big textes very fast that the old keyboards wasnt able to handle my fast Input.
But also Cheap NoName Keyboards for some $ or € cant handle more then 2 or 3 Keys.
The only Problem is when u Press Control first its a Control Key for Unity himself. So when u make an Example of
if (Input.GetKey(KeyCode.Alpha1))
Debug.Log("Key 1 ");
if (Input.GetKey(KeyCode.LeftControl))
Debug.Log("Control");
When u press Control + 1 he change the Tabs in Unity. Just as Example so if u want use something with Control first you have to Change the Settings of Unity that Unity not calls this Control Group of himself. But im now not sure if this is possible i not find the Setting.
But if u Build and Run ur Project it should work. U can try alternative until u make a Build to Set the Control Key to something else close to the Shift Button.
Answer by Buckslice · Dec 12, 2017 at 10:55 PM
I tried this code which worked fine, maybe you were using GetKeyDown instead of GetKey?
if(Input.GetKey(KeyCode.LeftControl)&&
Input.GetKey(KeyCode.LeftShift) &&
Input.GetKey(KeyCode.UpArrow)) {
Debug.Log(Time.time);
// do the slide
}
However note that the number of keys Unity can detect at once actually depends on your physical keyboard's rollover ability. For example I added additional checks for left arrow and right arrow in my sample code and it worked with 4 but not with all 5 checks. So my keyboard seems to have around 4 key rollover, however this also can vary with certain key combinations depending on how your keyboard is wired. So it may that your keyboard has low rollover.
Answer by JoniD89 · May 24, 2020 at 08:05 AM
I had this problem and it was the keyboard. I was using a wireless keyboard, but when I tried it on my laptops keyboard it works.