# Unity 3d 4 players Only 4 buttons can be pressed at a time

Only 4 buttons can be pressed at a time, so players cant move sometimes

Each Player Has their own Controls

i Change, Up Arrow and the other ones for each player---v

InputsV-V-V

public string UpArrow;
public string DownArrow;
public string LeftArrow;
public string RightArrow;

if(Input.GetButton(UpArrow))
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

if(Input.GetButton(DownArrow))
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);

if(Input.GetButton(LeftArrow))
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);

if(Input.GetButton(RightArrow))
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);

• Great question! Learned a lot on this one
– Evorlor
Jan 24 '15 at 14:11
• Cheap keyboards won't even recognize many 3 key combinations. Jan 25 '15 at 12:45
• Here's an explanation of this problem by Microsoft. Jan 28 '15 at 19:47

Keyboards have hardware limitations on how many keys can be pressed and recognized at the same time.

Your code is not the problem here, it's most likely the design of the keyboard.

• This is why FPS PC games leverage Shift, CTRL, and Alt keys -- they don't count towards that 4 key limit. Jan 24 '15 at 5:58
• Ps. The trick for enabling a decent multiplayer experience on a single computer is to support multiple keyboards. They're cheap enough, and with a simple USB hub or two you can easily have dozens of them connected at the same time. Plus, it frees your players from having to all huddle around a single keyboard. Jan 24 '15 at 16:13
• Also, any branded gamer keyboard (even the cheapest logitech one) supports pressing at least 4 keys simultaneously. Mechanical ones generally works like a piano so you can use all your fingers. gaming.stackexchange.com/questions/6669/… Jan 24 '15 at 21:01
• However the default USB protocol only allows for 6 keys (plus the meta keys), so if you want a keyboard with more than that it needs to supply its own driver. Jan 25 '15 at 14:15

Keyboards have a key matrix, where the buttons have been arranged into something roughly square, with the keyswitches each being tied to one row and one column. The keyboard activates each row and then reads the columns. If you sketch this out you will see that some button combinations must activate "phantom" keys. You can fix this with one diode per button (which is a substantial cost for a keyboard) and have full rollover. To avoid the phantoms, a keyboard without full rollover will ignore key combinations which are ambiguous.

Modifier keys are always designed so that they can be chorded.

Once the keyboard has a set of keys to report, it has to pack it into the USB HID report, which has one byte that's a bitmask of modifiers, and 6 bytes for other scancodes. So even with full rollover you're not likely to see more than 8 modifiers and 6 scancodes simultaneously.

(the keyboard report also has one byte that's always 0, making 8 total bytes)

• It is likely worth noting that some keyboards (particularly razer ones) use a non HID compliant extension in order to enable true full key rollover even over usb. Additionally, ps2 ports did not have this restriction either and could perform n key rollover. Jan 25 '15 at 1:28
• Technically there's nothing non compliant about having as large a keyboard HID report as you want. However, there is a USB boot HID standard which works as I described. This limited format was specified so that simple code in BIOS could understand USB keyboards. It's just more work to design a keyboard which switches out of that mode when the real OS launches. It's quite likely that Windows generic HID drivers would support as many scancodes as you like if your device has the right descriptors. Jan 25 '15 at 1:53
• Excellent, thank you for letting me know. Perhaps you could put that in the answer as it is valuable information. Jan 25 '15 at 1:56
• Another name is n-key rollover. Somewhat tangential: I do have such a keyboard that works with Windows drivers loaded and in the UEFI firmware, but trips up the Windows bootloader and some bootable media - it actually freezes them. Traditionally, PS/2 connections were used for n-key rollover with USB limited to ~6, though that seems to be rarer recently.
– Bob
Jan 25 '15 at 15:26