AZERTY Keyboard and jMonkeyEngine Quick Tip

If you’ve ever created anything using jMonkeyEngine’s SimpleApplication and you use something other than the American standard QWERTY keyboard, you might have had the same frustration as me: Why isn’t there quick way to switch the keyboard layout? The SimpleApplication base class is supposed to make your life easier, yet there you are, completely stuck with that unnatural keyboard layout. Read on for a quick copy-and-paste solution.

The keyboard mapping that SimpleApplication uses for its camera movement is defined in the FlyByCamera. The mapping is hardcoded and the mapping names don’t even use constant strings. Clearly, no one ever thought about international users.

jMonkeyEngine does so many things right, yet on this one, it really misses the ball.

Luckily, with a little searching, it’s fairly easy to redefine the correct mappings. It’s something I now do in all my experiments.

I just copy and paste the following at the start of every simpleInitApp:

inputManager.deleteMapping("FLYCAM_Forward");
inputManager.deleteMapping("FLYCAM_Lower");
inputManager.deleteMapping("FLYCAM_StrafeLeft");
inputManager.deleteMapping("FLYCAM_Rise");
inputManager.addMapping("FLYCAM_Forward", new KeyTrigger(KeyInput.KEY_Z));
inputManager.addMapping("FLYCAM_Lower", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("FLYCAM_StrafeLeft", new KeyTrigger(KeyInput.KEY_Q));
inputManager.addMapping("FLYCAM_Rise", new KeyTrigger(KeyInput.KEY_A));
inputManager.addListener(flyCam, new String[] {"FLYCAM_Forward", "FLYCAM_Lower", "FLYCAM_StrafeLeft", "FLYCAM_Rise"});
flyCam.setMoveSpeed(10f);

(Note that I’ve also sped up the movement to more easily move around)