Input.GetKey doesnt work even though the input is detected.

Ive successfully implemented Input.GetKey many times into my scripts, but for some reason it doesnt work for some keycodes.

I tried the KeyCodes for space, c and hash and it worked for everyone of them expect the hash. I dont think the problem has to do with my keyboard and to prove that, I used Input.inputString to see if my input is detected at all and as it turns out it is.

I have no clue why it doesnt work. The input is detected and it works fine for other keycodes, therefore it must be a bug or I am missing something. The code is inside a function that is called by Update.

void PlayerInput()
        Debug.Log(Input.GetKey(KeyCode.Hash)); //Returns false while hash is pressed
        Debug.Log(Input.GetKey("#")); //Returns false while hash is pressed
        Debug.Log(Input.inputString); //Returns "#" while hash is pressed
        Debug.Log(Input.GetKey(KeyCode.C)); //Returns true while hash is pressed
        Debug.Log(Input.GetKey("c")); //Returns true while hash is pressed
        Debug.Log(Input.inputString); //Returns "c" while space is pressed

I am using Unity 5.2.2f1. I dont think it is related to the version and I cant just simply update unity (256kb/s download speed), just thought I’d mention it anyways.

On all keyboards that I know about you must press Shift+3 to get #. Does your keyboard require using a modifier key (shift, control, alt, etc.) to get #? If so then Input.GetKey isn’t going to detect that since it only deals with single keys, not key combinations.

(I have no idea what keyboards @Dave-Carlile uses, but I’ve got three in front of me and they all have the # symbol right between the @ and the Enter key, no modifiers needed whatsoever)

Like you, I can’t work out how to get Keycode.Hash (or Keycode.At, for that matter) to be recognised by GetKey, despite the fact they both get printed by inputString just fine. I’d suggest you should report this as a bug to Unity using the Help → Report a Bug option as, while I understand the explanation that it is based on a US standard keyboard, it seems really peculiar that they apparently can’t use it either!

Incidentally, are the comments in your code listing definitely correct? I can recreate the first three conditions, but the last three work fine for me, and Debug.Log(Input.inputString); //Returns "c" while space is pressed definitely seems wrong…

To use any font of the keyboard is recommended to use “KeyCode”. With this you can use

Debug.log (Input.GetKey (KeyCode.C))

For more information about KeyCode visit this page:

I hope this has been helpful and it work. Will it work :slight_smile: