SDL 1.3: Keyboard layout handling

I converted some code from 1.2 to 1.3.

Now I am seeing some weird things in the keyboard keysyms and scancodes.

For example:
when I press a lowercase ‘g’ the event keysym shows an uppercase’G’.

Can anyone shed some light on SDL 1.3 keyboard handling differences?

.

When I press lowercase ‘g’ I see this:

Code:
Press:- Scancode: 0x0A, Name: G, Unicode: g (0x0067)
Modifers: None
Release:- Scancode: 0x0A, Name: G
Modifers: None

The keysym is uppercase ‘g’ and the Unicode is lowercase ‘g’. ???

When I press Return I see this:

Code:
(0x000D)cancode: 0x28, Name: Return, Unicode:
Modifers: None
Release:- Scancode: 0x28, Name: Return
Modifers: None

Also, whatever the Unicode string is for Return it is causing weirdness with printf.

.

The definition of the SDLK_xx constants have changed from 1.2 to 1.3.

Code:
$ grep -RHn SDLK_g /usr/local/include/SDL
/usr/local/include/SDL/SDL_keycode.h:103: SDLK_g = ‘g’,
$ grep -RHn SDLK_g /usr/include/SDL
/usr/include/SDL/SDL_keysym.h:89: SDLK_g = 103, /* ‘G’ */

SDLK_g went from being an uppercase ‘G’ to a lowercase ‘g’.

So it’s pretty difficult to use SDLK_g to compare to event->key.keysym.sym since in 1.3 SDLK_g is lowercase but keysym is uppercase.

.

Code:
$ grep -RHn SDLK_g /usr/local/include/SDL
/usr/local/include/SDL/SDL_keycode.h:103: SDLK_g = ‘g’,
$ grep -RHn SDLK_g /usr/include/SDL
/usr/include/SDL/SDL_keysym.h:89: SDLK_g = 103, /* ‘G’ */

SDLK_g went from being an uppercase ‘G’ to a lowercase ‘g’.

Look again. ASCII 103 is a lowercase G.

The comment is just to indicate that the value represents the ‘G’ key.
(You’ll note that the glyph painted on the keycap is usually an
uppercase letter.)

The actual value of SDLK_g is unimportant. If you want to know the
actual character generated, use the unicode field.

b

So it is.

I think the problem is that event->key.keysym.sym is uppercase now in 1.3.

I get these errors now when I compile files that have my mapping arrays:

Code:
warning: array subscript is above array bounds

the warnings occur on lines like this:

Code:
map[SDLK_LSHIFT] = MAP_LSHIFT;

Is it not possible to use these SDLK_xx defines in mapping arrays now?

.

#define SDLK_SCANCODE_MASK (1<<30)
#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)

SDLK_LSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT),

You’re just going to need a veeeeeeeeeeeeeeeeeeeeeerrrry large array :slight_smile:
Or you could use the scancode instead.

Frank.On 05/27/2011 05:35 PM, greno wrote:

I get these errors now when I compile files that have my mapping arrays:

Code:

warning: array subscript is above array bounds

the warnings occur on lines like this:

Code:

map[SDLK_LSHIFT] = MAP_LSHIFT;

Is it not possible to use these SDLK_xx defines in mapping arrays now?

From the header:

Yeah, I saw that.

This new shift over to USB HID scancodes is causing some headaches.

What would be great is if we could have something like SDL_GetHidScancode() and SDL_GetAtScancode() or some such thing.

.

That’s because 0x000D is carriage return (literally, the return character), this causes terminals to return to the beginning of the line and continue printing from there, overwriting the beginning of
whatever is already on that line, hence your (unicode) text appearing at the beginning of the line.

It is generally best not to print control characters directly when debugging :)On 05/27/2011 12:22 PM, greno wrote:

When I press Return I see this:

Code:

(0x000D)cancode: 0x28, Name: Return, Unicode:
Modifers: None
Release:- Scancode: 0x28, Name: Return
Modifers: None

Also, whatever the Unicode string is for Return it is causing weirdness with printf.


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

Well, I wasn’t expecting control characters.

I was running the PrintKeyInfo found on this page:

http://www.libsdl.org/docs/html/guideinputkeyboard.html