Key presses are not consumed by InputText


I have not found the answer, if it is in here, sorry for that:
My Camera is controlled via the keyboard. So for example: pressing the W key moves the camera forward.
I have a save-dialog that contains am Input-Field, where you can enter the name. As soon as you hit one of the movement-keys, the character will appear in the Input-Field but also the camera will move.

For MouseClicks I could prevent this, by asking the EventSystem if the pointer is over a gameobject. I have not found a solution for it with the Key Inputs.
I tried (after searching) to use the GUI.GetNameOfFocusedControl function, but it seems to always return an empty string :frowning:

Thanks for your help!


GUIUtility.keyboardControl should do the trick, if it is -1 or 0 (don’t remember) you are free to process the input for camera movement. Not ideal though, i’d be best if the actual inputField consumed it…

As a workaround, you can just create a boolean check on your key press.

For example, when you have the text field up, you can set a boolean canMove (or whatever you’d like to call it) to false.

In your input code for moving the camera, you can wrap all of your code in an if statement

if(//key detection statement){
    if(canMove == true){
           // move the camera

And then when the text field is closed, you can set canMove back to true.

I haven’t tested it but the logic seems sound.