The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL Keyboard Layout Handling
Simone Manganelli
Guest

Accounting for the keyboard layout while using SDL on Mac OS X seems
to be an exercise in frustration, and I wonder if anybody else has
been encountering the problems that I've been having.

My system language is set to Italian, while my keyboard layout is set
to U.S. Dvorak. The problem I'm having is that the key syms that SDL
generates for keyboard events seem to be dependent upon the system
language that you've chosen.

Typically, when using a QWERTY keyboard, pressing Q on the keyboard
will generate an SDL event with the key sym SDLK_q, pressing R will
give the sym SDLK_r, etc. On my system, however, this is slightly
different. SDL seems to assume I am using the Italian QZERTY keyboard
layout, and so when I press the w key, I get an SDLK_z key sym instead!

So, assuming that the key syms that SDL generates are under the QWERTY
keyboard layout is a bad assumption, and therefore we can't translate
keys based solely on the key syms.

We tried using the Unicode keys, but this runs into a different
problem; unicode variables are not sent along with keyboard events
that signal a key has been unpressed, only the key syms! And since
the key syms aren't reliable, there seems to be no reliable way to
figure out exactly which key has been unpressed (which is crucial,
since this is a game that is using SDL, and movement needs to stop as
soon as a key is unpressed).

What's the solution to this problem? Is there a way to get stable key
syms that don't change based on the system language setting?

Even better, is there a way for SDL to automatically take into account
the keyboard layout of the system and generate the appropriate key
syms automatically without my own code having to translate between
QWERTY and the selected keyboard layout?

Any help would be greatly appreciated.

-- Simone
SDL Keyboard Layout Handling
Jonathan Dearborn
Guest

As an ad hoc fix, how about looking for the unicode on keydown, then
recording the corresponding keysym from the event? Then you can check the
keyup events for the list of keysyms that you have saved.

Jonny D


On Thu, Mar 19, 2009 at 11:39 PM, Simone Manganelli <simX_other at mac.com>wrote:

Quote:
Accounting for the keyboard layout while using SDL on Mac OS X seems to be
an exercise in frustration, and I wonder if anybody else has been
encountering the problems that I've been having.

My system language is set to Italian, while my keyboard layout is set to
U.S. Dvorak. The problem I'm having is that the key syms that SDL generates
for keyboard events seem to be dependent upon the system language that
you've chosen.

Typically, when using a QWERTY keyboard, pressing Q on the keyboard will
generate an SDL event with the key sym SDLK_q, pressing R will give the sym
SDLK_r, etc. On my system, however, this is slightly different. SDL seems
to assume I am using the Italian QZERTY keyboard layout, and so when I press
the w key, I get an SDLK_z key sym instead!

So, assuming that the key syms that SDL generates are under the QWERTY
keyboard layout is a bad assumption, and therefore we can't translate keys
based solely on the key syms.

We tried using the Unicode keys, but this runs into a different problem;
unicode variables are not sent along with keyboard events that signal a key
has been unpressed, only the key syms! And since the key syms aren't
reliable, there seems to be no reliable way to figure out exactly which key
has been unpressed (which is crucial, since this is a game that is using
SDL, and movement needs to stop as soon as a key is unpressed).

What's the solution to this problem? Is there a way to get stable key syms
that don't change based on the system language setting?

Even better, is there a way for SDL to automatically take into account the
keyboard layout of the system and generate the appropriate key syms
automatically without my own code having to translate between QWERTY and the
selected keyboard layout?

Any help would be greatly appreciated.

-- Simone
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090320/364490af/attachment.htm>
SDL Keyboard Layout Handling
Sam Lantinga
Guest

Quote:
My system language is set to Italian, while my keyboard layout is set
to U.S. Dvorak. The problem I'm having is that the key syms that SDL
generates for keyboard events seem to be dependent upon the system
language that you've chosen.

Does this happen using SDL 1.3?

Try test/checkkeys in the SDL 1.3 source archive:
http://www.libsdl.org/tmp/SDL-1.3.zip

See ya,
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC