- Home /
KeyCode.LeftControl ignored with other keys?
I'm finding that the LeftControl KeyCode is ignored in certain combinations with other keys. I'm using the typical FPS controls for testing just to be 100% sure that my keyboard supports all the combinations I'm using, and I'm finding that supported combinations like (LeftControl and S) or (LeftControl and D) are ignored while combinations like (LeftControl and W) work fine.
In fact, it's slightly weirder than that. If I hold S or D down first and then hold LeftControl down, both register with Input.GetKey() but if I hold LeftControl down first and then hold down either S or D, S and/or D are ignored.
I wrote a quick test application in another game engine to confirm that this precise behaviour is supported by my keyboard and it is, but it doesn't work in Unity. All works fine with LeftShift but not with LeftControl. So I wondered if LeftControl is bound in the editor itself somehow and is prevented from working the same way as other keys. Or whether it's just a bug or what.
Oh, I'm on Windows, if that makes a difference.
Answer by jashan · Dec 07, 2009 at 03:47 PM
One possible solution might be trying different methods within Unity to check for the keyboard events. I remember one case where using Event.keyCode yielded different results from Event.character (on PC, worked fine on Mac), so I ended up doing a manual conversion from Event.current.character to the KeyCodes that I had trouble with (numbers 0-9 and quite a few of the alphabetical characters). I think Input was a bit more reliable on that end.
Anyways, this looks very much like a Unity bug to me and the above is just a hint for a potential workaround. I've seen a couple of issues regarding keyboard input in the past (both on Mac and Windows, usually more related to international keyboard issues, though) and it seems to me that implementing low-level keyboard input is far from trivial. I've seen different behaviors between Mac vs. Windows and even standalones vs. editor vs. Web player (standalones vs. editor being different might also be a fault in my bio-memory ;-) ). Obviously, when the behavior is different between systems that is considered a bug.
So, my recommendation would be sending a detailed bug report to UT using the bug reporter: menu Help / Report a problem.
It certainly helps if you can send them a simple project with which they can reproduce the behavior (kind of like what you created in the other game engine). It might help to even include your keyboard.
Just kidding ;-) ... I mean the brand and model information of your keyboard. While somewhat unlikely, I think it may be possible that this is related even though it works with the other game engine (might be the other game engine is accessing the keyboard in a different way which is one possible explanation for the different behavior).
Actually, it might be a consideration to post the test-project to the forums so other users can try to reproduce the issue (I certainly would give it a try if you post a link to the test-project / forum posting in a comment here). When a couple of users can reproduce it, that kind of adds "weight" to the bug report ;-)
PS [EDIT]: I thought it might be helpful to post my workaround. That was for an older version of Unity, though, and it might be they've already fixed that issue - but maybe you're lucky and it turns out to be the same or a similar issue (this is inside an OnGUI() method and I'm previously checking Event.current.type == EventType.KeyDown, so it only gets executed on KeyDown):
KeyCode lastKeyCode = Event.current.keyCode; // hack for Windows Web players (they won't recognize Event.current.keyCode in all those cases) if (lastKeyCode == 0) { switch (Event.current.character) { case '1': lastKeyCode = KeyCode.Alpha1; break; case '2': lastKeyCode = KeyCode.Alpha2; break; case '3': lastKeyCode = KeyCode.Alpha3; break; case '4': lastKeyCode = KeyCode.Alpha4; break; case '5': lastKeyCode = KeyCode.Alpha5; break; case '6': lastKeyCode = KeyCode.Alpha6; break; case '7': lastKeyCode = KeyCode.Alpha7; break; case '8': lastKeyCode = KeyCode.Alpha8; break; case '9': lastKeyCode = KeyCode.Alpha9; break; case '0': lastKeyCode = KeyCode.Alpha0; break;
case 'a': lastKeyCode = KeyCode.A; break;
case 'd': lastKeyCode = KeyCode.D; break;
case 'q': lastKeyCode = KeyCode.Q; break;
case 'e': lastKeyCode = KeyCode.E; break;
case 'y': lastKeyCode = KeyCode.Y; break;
case 'z': lastKeyCode = KeyCode.Z; break;
case 'm': lastKeyCode = KeyCode.M; break;
case 'f': lastKeyCode = KeyCode.F; break;
case 'r': lastKeyCode = KeyCode.R; break;
case 's': lastKeyCode = KeyCode.S; break;
case 'w': lastKeyCode = KeyCode.W; break;
case 'x': lastKeyCode = KeyCode.X; break;
case 't': lastKeyCode = KeyCode.T; break;
case ' ': lastKeyCode = KeyCode.Space; break;
case '\n': lastKeyCode = KeyCode.Return; break;
case '\t': lastKeyCode = KeyCode.Return; break;
}
}
Thanks Jashan. I created a quick test project which demonstrates the issue and submitted it with a bug report. It's a virtually empty project but it's still 15mb+ so I won't bother uploading for anyone unless UT tell me that they cannot reproduce it. I suspect they will reproduce it because I had my sound on last night and noticed that there is a Windows "SystemAlert" sound which definitely makes it sound as though the editor is trapping the keys. Hopefully they can have this temporarily halted during playback.
Your workaround looks like it might well be a clever solution in the meantime. Thanks very much for taking the time to offer that.
Your answer
Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Determining GUI button pressed 2 Answers
How to alter input to continuous rather than tap? 0 Answers
Input.GetTouch(0).tapCount question 2 Answers
Character Zoom in and out 1 Answer