[SDL] SDL 1.3 keyboard input on X11

Bob Pendleton bob at pendleton.com
Wed Dec 19 14:08:02 PST 2007


On Wed, 2007-12-19 at 07:27 +0100, Christian Walther wrote:
> Bob,
> 
> I have worked on X11 keyboard support some months ago. The problem about
> the physical key codes is solved in my code (using X-server-specific
> look-up tables), but I hit another road block later on, and since I
> haven't gotten a reply from Sam when I asked him for advice, that code
> is still sitting on my hard drive, and I kinda forgot about it.

Please send me those tables and your code. Please do not check it in.
That could mess me up and make it hard to get your code. 

I haven't looked at the higher level functions, but I have a pretty good
(table based) conversion from X11 keycodes to SDLK_*. The problem with
it is that it likely only works with X.org and Linux, and maybe only the
latest versions of both.

The following is more for everyone else than for you:

The latest Linux kernels convert keyboard scan codes to a fixed set of
keycodes. The result is that the physical location of the key is
preserved and nothing needs to care about the type of the keyboard.
Every application, including the X server, get the same kernel generated
keycodes. The X server then translates those keycodes to its own version
of keycodes and passes them along to X applications. There is not a 1:1
relationship between X server keycodes and kernel keycodes. 

To confuse things even more X wants you to convert the keycodes to
"keysyms". Keysyms are X specific and date back to the 1980s before
anyone ever heard of Unicode. The key to generating SDLKey values from
keycodes is to ignore the X keysyms and use the keycodes. The trouble
with that is that I only know what the keycodes are for the 2.5 kernel
and for the X.org server shipped with Ubuntu 7.10. 

The mod maps I asked for give me a real good idea of what X keycodes get
mapped to which keysyms so I can valid the table I am building. :-)

Personally, I believe the higher level SDL key functions should/must be
implemented strictly in terms of SDLKey values. How you do that, I have
no clue at this time. We may need to change the design.

		Bob Pendleton

> 
> Rather than trying to recollect the problem from memory, here's what I
> wrote to Sam at the time (2007-10-03):
> 
> > Status report: I'm somewhat stuck with the X11 keyboard
> > implementation. What I have now mostly works with the western
> > keyboard layouts I have tested, but most likely fails miserably as
> > soon as input methods are involved. I don't consider this ready to be
> > committed. Specifically, GetLayoutKey() turned out to be less
> > straightforward to implement than I had hoped. What I need there, for
> > character keys, is basically a static mapping from X11 KeySyms to
> > one-character (unicode) key names (static because KeySyms correspond
> > 1:1 to our concept of a "layout key code"). But I have been unable to
> > find an elegant way of doing this. Xutf8LookupString(), which I'm
> > using now, is inappropriate because it takes into account dead keys
> > and input methods (and probably messes up the XIC that I'm currently
> > borrowing from the first window). XLookupString() works, but only for
> > Latin-1 characters. XKeysymToString() produces ASCII strings, not
> > single characters. The only correct way I can imagine is to have a
> > giant look-up table containing all thousands of KeySyms. I'm hoping
> > some X11 expert (which I am not) has a better idea here... or perhaps
> > the API we designed is just unimplementable and needs to be revised.
> > 
> > Other unfinished or questionable points (might make more sense once
> > you see the code):
> > - I haven't implemented generation of text events because I don't
> > understand what's going on in the commented-out SDL 1.2 code with
> > saved_keysym.
> > - I've resurrected the X11_KeyRepeat() function from SDL 1.2. Was
> > there a particular reason why it was removed?
> > - Due to what I wrote in
> > <http://article.gmane.org/gmane.comp.lib.sdl/34610>, I can't use
> > SDL_iconv() for UTF-8/SDLKey conversions (it's probably a bit
> > heavy-weight anyway). Instead I've taken fragments of the integrated
> > SDL_iconv() implementation and put them into the functions
> > encodeUtf8() in SDL_keyboard.c and decodeUtf8() in SDL_x11keyboard.c.
> > This should probably be centralized somewhere.
> > 
> > So, I'm a bit unsure about how to proceed. Should I send you a patch
> > for you personally to have a look at? Should I put it into bugzilla
> > and ask for help on the mailing list? Should we commit it nonetheless
> > and hope for someone to fix it sooner or later?
> 
> I'll probably put a patch into Bugzilla just to get my code out there, 
> so you could have a look at it. I hope I'll have time for that tonight.
> 
>   -Christian
> 
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
> 
-- 
+--------------------------------------+
+ Bob Pendleton: writer and programmer +
+ email: Bob at Pendleton.com             +
+ web: www.GameProgrammer.com          +
+ www.Wise2Food.com                    +
+ nutrient info on 7,000+ common foods +
+--------------------------------------+





More information about the SDL mailing list