Keyboard codes portability

I suppose it has already been answered tons of time, but I was unable to find
a clear answer.
So suppose I want to create an application using the keyboard that needs to
be portable. Should I detect the keys using their keysyms (SDLK_xxx) ?
Because some people told me they were not constant from system to system (for
example, SDLK_y could be bound to the ‘z’ key and not on the ‘y’ key. Does
anyone have an explanation/solution for this ?

Chachkoff Yann.

Because some people told me they were not constant from system to system (for
example, SDLK_y could be bound to the ‘z’ key and not on the ‘y’ key.

if that is ever the case (SDLK_y not bound to the key with “y” printed
on it), it’s either an SDL driver bug or a user having remapped his
keyboard in some way that confuses SDL (a “user bug”). Reports are welcome,
so are patches

I suppose it has already been answered tons of time, but I was unable
to find a clear answer.
So suppose I want to create an application using the keyboard that
needs to be portable. Should I detect the keys using their keysyms
(SDLK_xxx) ? Because some people told me they were not constant from
system to system (for example, SDLK_y could be bound to the ‘z’ key and
not on the ‘y’ key.

Yeah, and on my keyboard, the SDLK_y key would actually read ‘F’ on the
keycap… (Dvorak layout.)

Does anyone have an explanation/solution for this ?

Every key has it’s own “scan code”, which is only related to the physical
location of the key; not whatever might be printed on the key. The actual
meaning of each key is determined by the OS, using files like *.KDB
(Win95/98), some keymap DLL (WinNT/2k), .Xmodmap (X), *.[k]map (Linux
console), and is often configurable per user.

To get the ASCII that the current user expects from a certain key, use
the unicode field of the keyboard event struct. First, you must enable
unicode translation with

SDL_EnableUNICODE(1);

as it’s disabled by default.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Thursday 26 July 2001 23:03, Chachkoff Yann wrote:

Sorry! I’m confusing the “scancode” and “sym” fields here. heh

AFAIK, unicode should only be required for decoding characters that
don’t have any SDLkey keysyms. (Does it actually work like that under all
circumstances?)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Thursday 26 July 2001 17:25, Mattias Engdeg?rd wrote:

Because some people told me they were not constant from system to
system (for example, SDLK_y could be bound to the ‘z’ key and not on
the ‘y’ key.

if that is ever the case (SDLK_y not bound to the key with “y” printed
on it), it’s either an SDL driver bug or a user having remapped his
keyboard in some way that confuses SDL (a “user bug”). Reports are
welcome, so are patches

Chachkoff Yann wrote:

I suppose it has already been answered tons of time, but I was unable to find
a clear answer.
So suppose I want to create an application using the keyboard that needs to
be portable. Should I detect the keys using their keysyms (SDLK_xxx) ?
Because some people told me they were not constant from system to system (for
example, SDLK_y could be bound to the ‘z’ key and not on the ‘y’ key. Does
anyone have an explanation/solution for this ?

If y and z are switched - it sounds like german keyboard layout or
something like that.

As David just wrote - use:

SDL_EnableUNICODE(1)

to enable unicode translation and read the unicode field
of the key events for a portable (Unicode) representation.
Then you will get the correct mapping from the user’s
keyboard layout…

Cheers–
http://www.HardcoreProcessing.com