- Home /
Problem with pressing multiple keys at once?
In my game I was going to implement the possibility of pressing forward and space at the same time. The only problem is if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.Space)) { } doesnt seem to work. If they are not together the keys work fine, but together it cant seem to work. Any ideas? Thanks!
Answer by save · May 31, 2011 at 07:41 PM
Try using Input.GetAxis or Input.GetKeyDown instead (and set them up in the input manager). In case there's no difference there's a big chance that the problem is within your actual keyboard. Different keyboards handles sending each- and multiple key press differently.
Thanks a ton! I figured out that you just need GetAxis and it seems to work so far!
Answer by DaveA · May 31, 2011 at 10:51 PM
You can keep tabs on those keys with some booleans (or array of them) and Input.GetKeyDown and Input.GetKeyUp. Or the Event class also can track these.
But that won't help is you press the wrong 3-key-combination ;) If you press 2 keys on the same scanline together with another one on the same column most keyboardcontrollers generates an error because it can't detect the actual key you've pressed.
See $$anonymous$$ey jam$$anonymous$$g : http://en.wikipedia.org/wiki/Rollover_%28key%29#$$anonymous$$ey_jam$$anonymous$$g_and_ghosting