- Home /
The question is answered, right answer was accepted
Seven key press
Does unity3d has ability to detect seven key press?
I tried but i could'nt. I control key presses with GetButton or GetButtonDown six key works but seven doesn't.
I mean pressing seven button at the same time.
Is there a way to solve this?
Answer by RashidBekar · Oct 12, 2012 at 06:53 AM
Ok now, i did it just by the change of g-h-j keys to j-k-l keys
Sorry for opening a question and answering it myself, this is the second one i answered me.
But until i open the question i really can't do it.
Before i changed g-h-j keys to other keys they didn't work, why would jkl works?
This is maybe a keyboard issue. Maybe i solved it only for me, or others may not have any problem with the previous one.
It sounds like a hardware thing. Depends on how the keys are wired and polled. I recall such an issue many years ago when I was doing such a thing using AS$$anonymous$$. Not even C. AS$$anonymous$$!
Answer by sparkzbarca · Oct 11, 2012 at 11:38 PM
So I checked it out for you.
Basically the problem is the frames the keys are registering is different.
when you press a key its only down for that frame after so many keys are involved they span multiple frames and keys go on and off. What you need to do is store the state of the key and check against that
for example
bool A_state; bool B_state; //use a a list not 40 variables this is just an example
if(input.getkeydown(keycode.A)
{
A_state = true;
}
if(input.getkeyup(kecode.A)
{
A_state = false;
}
if (A_state && B_state && C_state.. Z_state)
{
Do Something....
}
That will prevent the difference between which frame you pressed from mattering, holding down all 7 keys should work correctly.
Answer by DaveA · Oct 12, 2012 at 06:44 AM
It may be a hardware limitation. I haven't tried this myself, but maybe. You could use GetKey for each key, as that will be true in every frame when the key is down, and see if you can find it that way. You can iterate through all key codes and count the ones that are currently true.
You are correct, it is a hardware limitation. $$anonymous$$ost keyboards don't have each key wired independently, but rather use some form of matrix layout. Certain combinations of simultaneously pressed keys (usually >=3) will then be incorrectly recognized, or produce additional "ghost" key events. See for example http://ga$$anonymous$$g.stackexchange.com/questions/6669/how-do-i-remove-the-limit-on-pc-keyboard-button-presses or http://en.wikipedia.org/wiki/Rollover_(key)
You might be lucky to resolve the problem by using a high-end keyboard, but just becaouse a keyboards is expensive, doesn't mean it uses a non-matrix layout.
Follow this Question
Related Questions
Press Any Key To Continue 0 Answers
How would I detect if key get pressed 2 times 2 Answers