- Home /
Control key + A/D not working
I am working on a 2D game in Unity and one of the control schemes for the game involves holding down the left control key to start crouching and then when A or D is pressed the character begins to move. The problem is when using the A and D keys in addition to holding control, the character doesn't move. However, it does seem to work while using the arrows keys left and right. Any advice or tricks to fix this?
Answer by Bunny83 · May 01, 2015 at 05:42 PM
I don't think that's ghosting. CTRL is a pure combination key, so pressing it together with another key is how it's ment to be used.
The problem is that are all hotkeys which are recognised by the Unity Editor itself. In a build it will work as expected. For testing i recommend to not use the CTRL key in the editor. You can setup another alternate key for crouching. Try press CTRL and S and you will actually get a notification that you can't save the scene while in run-mode.
CTRL + D is "duplicate" in the editor
CTRL + A is "select all"
Unity uses a lot CTRL key ombinations. So avoid modifier keys (CTRL / ALT) completely if possible.
Again: In a build all those problems are gone.
Even though this makes sense I have not encountered this issue before. When in the in-editor game view it loses focuses of the editor.
@cdrandin: No, you're still in the editor ^^. Some hotkeys wouldn't do anything while inside the gameview, but there are even some which still works inside the game view. Like CTRL+P (Start / Stop playmode) and CTRL+SHIFT+P (Pause - for debugging i always wished there was a simpler hotkey ^^)
$$anonymous$$ost of the CTRL hotkeys (if not all) still work in the game view. Even CTRL+0..9
If you haven't had any problems yet just means you rarely use CTRL in-game ^^. I'm not a friend of CTRL for game controls anyways.
Answer by Landern · May 01, 2015 at 05:30 PM
This may be an issue with Keyboard Ghosting, this can be specific to your hardware.
You should go read about it as Microsoft covers this well here as well as a demo to see if your current keyboard is affected by ghosting.
Answer by cdrandin · May 01, 2015 at 05:33 PM
This would be the case if you are strictly moving your character when using the if statements for Keycode.A and D. You should rather have these if statement assign movement modifier. Then on a LateUpdate depending after input, take the modified movement and apply that to your movement function. This way it accounts for all movements based on input.