Upgrade to KeyboardEvent.key

KeyboardEvent.keyCode is a pain as you have to keep looking up what the codes mean, which key they are pointed to. What keys are 62, 47, 39, 70?

I would like to upgrade to use KeyboardEvent.key so we can use strings that clearly show the name of every key. ‘A’ is A, ‘D’ is D, ‘Enter’ is the Enter key, ‘Space’ is the spacebar (though for IE, it is ‘Spacebar’).

My thought is that the key press function should be able to accept a number or a string, and use the correct property based on which is supplied.

Hello and welcome!

the KeyboardEvent is coming from HTML and you can use the key property on it if you want. Can you be more precise on where you are forced to use the keyCode?

Maybe a repro in the Playground?

Hi and welcome,

Not sure where you want to updated it at all? Babylon gives you the full event object, you can do whatever you want with it. Are you referring to the camera keyboard inputs?

Hi. Yes, the camera inputs, such as keysDown, keysLeft, etc. The current documentation says these functions take numbers.

Oh ok! Now I understand. This is why I always ask for a code example in the Playground. it saves a lot of time :slight_smile:

Yeah the camera inputs take the keyCode so we do not have to do a string comparison many times per frame. But it is easy to find them with sites like http://keycode.info/

Alright, fair point. I understand string comparison is much more demanding than numbers. I imagine, then, that we’d need a dictionary object to convert key to keyCode for rendering. And I understand not wanting to add that whole thing to every download/minified-file. Thank you guys. :+1:t3:


With pleasure!