Camera to support event.code instead of event.keyCode?

So when attaching controls to the camera it seems that the underlying class uses properties like
keysLeft, keysRight, keysForward etc. But these wont support different international layouts as it looks like they take keyCode (numbers) instead of strings.

According to documentation on keyboard events event.code is a physical location of the key even if its name is not the same for example: KeyW is “w” for QWERTY but for AZERTY its “z” and for DVORAK its “.”

Is there any way to support this with the camera movement so that you can set the keys once and it will work for most keyboard layouts?


TBH, I totally want to use code, instead of keyCode, as keyCode is currently deprecated. The only issue would be working around backwards compatibility. All of the inputs test against the keyCode values so I suppose the easiest workaround that I could think of would be to create a function that can somehow determine what layout you’re using and overwrite the values in the keys arrays (eg. camera.inputs.attached.keyboard.keysUp) of the keyboard input objects. Other than that, writing a custom input that uses code instead should do the trick. If I can get some cycles at some point to update the inputs to use code, I’d like to make the change but it might take a bit of time, as the change would affect a bunch of areas.

So do you think would it be better for me to just make an extension of the camera class for my project and just swap out the code responsible?

At least for the time being, I think that’d be a good idea.

1 Like

So I ended up making an International Keyboard Input class that extends ICameraInput<FreeCamera> and works swimmingly.

Maybe we could consider adding this to BJS codebase as well?

let s see first what @PolygonalSun can improve regarding this :slight_smile: We ll definitely ping you if needed.