The Developer’s Cry

Yet another blog by a hobbyist programmer

Dvorak keyboard in SDL

A while back I wrote a blog entry about the dvorak keyboard on my laptop. Funnily enough, it won’t work for SDL programs. SDL is the Simple Directmedia Layer library that allows for portable game development. I’m a huge fan of the SDL because it is simple, and it is very powerful too. I’ve made some pretty cool stuff using SDL, that I could not have made otherwise. Unfortunately, the SDL does not behave in a portable way when it comes to alternative keyboard layouts.

My personal experience:

Google turns up this solution, which does not work—at least not on the Mac, where I tested it:

In your initialization:


and then when you get a keyboard event: (From 'man SDL_keysym')

if (!(event.key.keysym.unicode & 0xff80))
    ascii = event.key.keysym.unicode;
    <deal with international characters>;

This method actually *works*, even with weird keyboard layouts like my custom swedish Dvorak variant. :-)

Let me repeat that this does not work, no matter what he says.
I wrote a conversion routine that maps the SDLKey keysyms from qwerty to dvorak, but this is really no solution. SDL should be made to use the platform-specific keyboard routines so that it correctly uses the configured keyboard layout.

I submitted this as a bug in, now let’s see whether I got it all wrong or if someone is going to fix it.