OS independent SDL_keysym.scancode

Hi!

I have a question concerning SDL_KeyEvent. I thought this is a fairly
frequently asked question, but I found nothing about this problem in
documentation.

Let’s suppose I want to program a game where the keys that are covered
with the ‘[’ and ‘]’ characters on an american keyboard should have a
certain meaning. Now, I can either interpret the scancode field of
SDL_keysym struct, but this would make my program platform dependent (I
would have to “#ifdef WIN32” etc.). Or I can use the sym field,
which provide platform independent keys, but this makes my program
dependent on the selected “locale” of the user, i.e. a german user would
have to press AltGr+‘8’ or AltGr+‘9’ for the ‘[’ and ‘]’ keys
respectively. Of course the later option is completely useless if the
AltGr key had also a certain meaning.

The situation gets even worse when I want to assign meta-keys or dead
keys (e.g. on my current keyboard layout the spacebar is a modifier
key). Here I can only fallback to the scancode solution.

It’s not that the keyssyms are really bad, they are ok for text
input-lines etc, where the user expects his current locale, but useless
for “raw” keyboard accesses.

So, am I missing something, or am I really forced to use the platform
dependent solution for such things at the moment?

Sebastian

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to do
with the language / country / locale of the user, I am using a laptop
and plenty of keys that exist on a full keyboard are missing, or
require holding the dreaded Function key. This is generally not
suitable for games, but most tend to let me customize my controls, so
it’s not a problem any longer, you should probably do what they’re
doing.On Aug 17, 2004, at 5:14 PM, Sebastian Biallas wrote:

Hi!

I have a question concerning SDL_KeyEvent. I thought this is a fairly
frequently asked question, but I found nothing about this problem in
documentation.

Let’s suppose I want to program a game where the keys that are covered
with the ‘[’ and ‘]’ characters on an american keyboard should have a
certain meaning. Now, I can either interpret the scancode field of
SDL_keysym struct, but this would make my program platform dependent
(I would have to “#ifdef WIN32” etc.). Or I can use the sym field,
which provide platform independent keys, but this makes my program
dependent on the selected “locale” of the user, i.e. a german user
would have to press AltGr+‘8’ or AltGr+‘9’ for the ‘[’ and ‘]’ keys
respectively. Of course the later option is completely useless if the
AltGr key had also a certain meaning.

The situation gets even worse when I want to assign meta-keys or dead
keys (e.g. on my current keyboard layout the spacebar is a modifier
key). Here I can only fallback to the scancode solution.

It’s not that the keyssyms are really bad, they are ok for text
input-lines etc, where the user expects his current locale, but
useless for “raw” keyboard accesses.

So, am I missing something, or am I really forced to use the platform
dependent solution for such things at the moment?

Sebastian


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Donny Viszneki wrote:

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to do
with the language / country / locale of the user, I am using a laptop
and plenty of keys that exist on a full keyboard are missing, or require
holding the dreaded Function key. This is generally not suitable for
games, but most tend to let me customize my controls, so it’s not a
problem any longer, you should probably do what they’re doing.

While customization is in general a good idea[tm], it doesn’t really
help me in this topic. I’d still be forced to use scancodes instead of
the keysyms, since not all keys are reachable via the keysyms. E.g. on
my current locale[1], both the ESC and the ‘[’ key map to escape. While
this is good for programming / writing text, I’d prefer a raw keyboard
when playing games.

Sebastian

[1] http://plastictree.net/keyboard/

Donny Viszneki wrote:

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to do
with the language / country / locale of the user, I am using a laptop
and plenty of keys that exist on a full keyboard are missing, or
require holding the dreaded Function key. This is generally not
suitable for games, but most tend to let me customize my controls, so
it’s not a problem any longer, you should probably do what they’re
doing.

While customization is in general a good idea[tm], it doesn’t really
help me in this topic. I’d still be forced to use scancodes instead of
the keysyms, since not all keys are reachable via the keysyms. E.g. on
my current locale[1], both the ESC and the ‘[’ key map to escape.
While this is good for programming / writing text, I’d prefer a raw
keyboard when playing games.

Please help me understand. The reason you can’t use Keysyms is because
you have remapped your keyboard layout?On Aug 18, 2004, at 2:50 AM, Sebastian Biallas wrote:

Sebastian

[1] http://plastictree.net/keyboard/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Donny Viszneki wrote:

Donny Viszneki wrote:

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to
do with the language / country / locale of the user, I am using a
laptop and plenty of keys that exist on a full keyboard are missing,
or require holding the dreaded Function key. This is generally not
suitable for games, but most tend to let me customize my controls,
so it’s not a problem any longer, you should probably do what
they’re doing.

While customization is in general a good idea[tm], it doesn’t really
help me in this topic. I’d still be forced to use scancodes instead
of the keysyms, since not all keys are reachable via the keysyms.
E.g. on my current locale[1], both the ESC and the ‘[’ key map to
escape. While this is good for programming / writing text, I’d prefer
a raw keyboard when playing games.

Please help me understand. The reason you can’t use Keysyms is because
you have remapped your keyboard layout?

Well, I don’t know what his reason is. But here is mine : I’m working on
an emulator. Thus I need to associate keys from the original computer to
keys from the emulated computer (this is done with a keyboard
translation table). There are two solutions with SDL :

  • solution 1 : use the key symbol to do the translation. Since we’d like
    to keep the layout of the emulated computer (since it has nothing to do
    with current PC-like keyboards anyway) we have to build a table that
    associates each character to the good key. In this case what happens
    with international keyboards ? They don’t have the good mapping. For
    example the french keyboard (for example) doesn’t return some symbols
    the US keyboards do, and the opposite is also true (I’m thinking about
    the digits here, french keyboards have symbols, you have to shift to get
    the digits). Thus we have to create one keyboard translation table for
    each keyboard language.

  • solution 2 : use the scancode to do the translation. The scancodes for
    some keys are not the same from one platform to another. For example X11
    doesn’t have the same scancodes as windows (you have to add 8 to the
    scancode IIRC, and then the arrows and other keys are still not the
    same…). Thus we need one keyboard translation table for each supported
    platform.

Neither solution is good. Thus I would really benefit from OS
independent scancodes (what I usually call “portable keysyms”) in SDL.
If others are willing to undertake work in this direction, I’m willing
to help.

Stephane> On Aug 18, 2004, at 2:50 AM, Sebastian Biallas wrote:

Donny Viszneki wrote:

Donny Viszneki wrote:

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to do
with the language / country / locale of the user, I am using a laptop
and plenty of keys that exist on a full keyboard are missing, or
require holding the dreaded Function key. This is generally not
suitable for games, but most tend to let me customize my controls, so
it’s not a problem any longer, you should probably do what they’re
doing.

While customization is in general a good idea[tm], it doesn’t really
help me in this topic. I’d still be forced to use scancodes instead of
the keysyms, since not all keys are reachable via the keysyms. E.g. on
my current locale[1], both the ESC and the ‘[’ key map to escape.
While this is good for programming / writing text, I’d prefer a raw
keyboard when playing games.

Please help me understand. The reason you can’t use Keysyms is because
you have remapped your keyboard layout?

For example, yes. My keyboard layout is for writing text and
programming. It contains a lot of meta, compose etc. keys, that only
make sense while writing text. But when playing games I consider a
keyboard as an input device with 102+ buttons – not more. Why configure
the keyboard for every game when the programmer can provide sane
defaults independent of keyboard layout?

Let me elaborate a little bit more. I currently work on PearPC[1]. If I
would use keysyms, I’d force all users that don’t use the us keyboard
layout to configure the keyboard first; all 102+ keys! And for
configuring they had know how the keys are arranged on an us keyboard
(well I could provide a picture). And when the switch their layout
(there are a lot of people who switch regulary between german/us layout,
for writing text/programming), they had to configure again.

Note that this is not only a problem with PearPC: with my current
keyboard layout it’s almost impossible to use DOSBox.

My current solution is that I rely on the scancodes of SDL. A little bit
ugly, because I have to #ifdef for all platforms, but a lot better than
the keysyms, from a users perspective (i.e. everybody can
compile/install pearpc without have to configure anything and the
keyboard just works; they select whatever locale the like in the guest OS)

So, the nicest solution for me would be to have host indepedent
scancodes; something the same I currently provide in pearpc via #ifdefs.

Sebastian

[1] http://pearpc.sf.net> On Aug 18, 2004, at 2:50 AM, Sebastian Biallas wrote:

could you give an example of how you are using #ifdef?

Thank you!> ----- Original Message -----

From: sb@biallas.net (Sebastian Biallas)
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Thursday, August 19, 2004 10:43 AM
Subject: Re: [SDL] OS independent SDL_keysym.scancode

Donny Viszneki wrote:

On Aug 18, 2004, at 2:50 AM, Sebastian Biallas wrote:

Donny Viszneki wrote:

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to do
with the language / country / locale of the user, I am using a laptop
and plenty of keys that exist on a full keyboard are missing, or
require holding the dreaded Function key. This is generally not
suitable for games, but most tend to let me customize my controls, so
it’s not a problem any longer, you should probably do what they’re
doing.

While customization is in general a good idea[tm], it doesn’t really
help me in this topic. I’d still be forced to use scancodes instead of
the keysyms, since not all keys are reachable via the keysyms. E.g. on
my current locale[1], both the ESC and the ‘[’ key map to escape.
While this is good for programming / writing text, I’d prefer a raw
keyboard when playing games.

Please help me understand. The reason you can’t use Keysyms is because
you have remapped your keyboard layout?

For example, yes. My keyboard layout is for writing text and
programming. It contains a lot of meta, compose etc. keys, that only
make sense while writing text. But when playing games I consider a
keyboard as an input device with 102+ buttons – not more. Why configure
the keyboard for every game when the programmer can provide sane
defaults independent of keyboard layout?

Let me elaborate a little bit more. I currently work on PearPC[1]. If I
would use keysyms, I’d force all users that don’t use the us keyboard
layout to configure the keyboard first; all 102+ keys! And for
configuring they had know how the keys are arranged on an us keyboard
(well I could provide a picture). And when the switch their layout
(there are a lot of people who switch regulary between german/us layout,
for writing text/programming), they had to configure again.

Note that this is not only a problem with PearPC: with my current
keyboard layout it’s almost impossible to use DOSBox.

My current solution is that I rely on the scancodes of SDL. A little bit
ugly, because I have to #ifdef for all platforms, but a lot better than
the keysyms, from a users perspective (i.e. everybody can
compile/install pearpc without have to configure anything and the
keyboard just works; they select whatever locale the like in the guest OS)

So, the nicest solution for me would be to have host indepedent
scancodes; something the same I currently provide in pearpc via #ifdefs.

Sebastian

[1] http://pearpc.sf.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Alan Wolfe wrote:

could you give an example of how you are using #ifdef?

Of course:

#ifdef WIN32
static byte scancode_to_adb_key[] = {
0xff,0x35,0x12,0x13,0x14,0x15,0x17,0x16,0x1a,0x1c,0x19,0x1d,0x1b,0x18,0x33,0x30,
0x0c,0x0d,0x0e,0x0f,0x11,0x10,0x20,0x22,0x1f,0x23,0x21,0x1e,0x24,0x36,0x00,0x01,
0x02,0x03,0x05,0x04,0x26,0x28,0x25,0x29,0x27,0xff,0x38,0x2a,0x06,0x07,0x08,0x09,
0x0b,0x2d,0x2e,0x2b,0x2f,0x2c,0x38,0x43,0x37,0x31,0x39,0x7a,0x78,0x63,0x76,0x60,
0x61,0x62,0x64,0x65,0x6d,0xff,0xff,0x59,0x5b,0x5c,0x4e,0x56,0x57,0x58,0x45,0x53,
0x54,0x55,0x52,0x41,0xff,0xff,0x0a,0x67,0x6f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x36,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0x4b,0xff,0xff,0x3a,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0x71,0xff,0x73,0x3e,0x74,0xff,0x3b,0xff,0x3c,0xff,0x77,
0x3d,0x79,0x72,0x75,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
};
#else
static uint8 scancode_to_adb_key[] = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x35,0x12,0x13,0x14,0x15,0x17,0x16,

0x1a,0x1c,0x19,0x1d,0x1b,0x18,0x33,0x30,0x0c,0x0d,0x0e,0x0f,0x11,0x10,0x20,0x22,
0x1f,0x23,0x21,0x1e,0x24,0x36,0x00,0x01,0x02,0x03,0x05,0x04,0x26,0x28,0x25,0x29,
0x27,0x32,0x38,0x2a,0x06,0x07,0x08,0x09,0x0b,0x2d,0x2e,0x2b,0x2f,0x2c,0x38,0x43,
0x37,0x31,0xff,0x7a,0x78,0x63,0x76,0x60,0x61,0x62,0x64,0x65,0x6d,0x47,0xff,0x59,
0x5b,0x5c,0x4e,0x56,0x57,0x58,0x45,0x53,0x54,0x55,0x52,0x41,0xff,0xff,0x0a,0x67,
0x6f,0x73,0x3e,0x74,0x3b,0xff,0x3c,0x77,0x3d,0x79,0x72,0x75,0x4c,0x36,0xff,0xff,
0x4b,0x3a,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
};
#endif

Those are tables for translating win32/x11-scancodes to adb scancodes.
If SDL provided platform independent scancodes I only needed one such table.

I use them the following way:

case SDL_KEYUP:
ev.key.keycode = scancode_to_adb_key[event.key.keysym.scancode];
if ((ev.key.keycode & 0xff) == 0xff) break;
ev.type = sysevKey;
ev.key.pressed = false;
gKeyboard->handleEvent(ev);
return true;

Thank you!

Sebastian

Donny Viszneki wrote:

Donny Viszneki wrote:

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to
do with the language / country / locale of the user, I am using a
laptop and plenty of keys that exist on a full keyboard are
missing, or require holding the dreaded Function key. This is
generally not suitable for games, but most tend to let me customize
my controls, so it’s not a problem any longer, you should probably
do what they’re doing.

While customization is in general a good idea[tm], it doesn’t really
help me in this topic. I’d still be forced to use scancodes instead
of the keysyms, since not all keys are reachable via the keysyms.
E.g. on my current locale[1], both the ESC and the ‘[’ key map to
escape. While this is good for programming / writing text, I’d
prefer a raw keyboard when playing games.
Please help me understand. The reason you can’t use Keysyms is
because you have remapped your keyboard layout?

For example, yes. My keyboard layout is for writing text and
programming. It contains a lot of meta, compose etc. keys, that only
make sense while writing text. But when playing games I consider a
keyboard as an input device with 102+ buttons – not more. Why
configure the keyboard for every game when the programmer can provide
sane defaults independent of keyboard layout?

Let me elaborate a little bit more. I currently work on PearPC[1]. If
I would use keysyms, I’d force all users that don’t use the us
keyboard layout to configure the keyboard first; all 102+ keys! And
for configuring they had know how the keys are arranged on an us
keyboard (well I could provide a picture). And when the switch their
layout (there are a lot of people who switch regulary between
german/us layout, for writing text/programming), they had to configure
again.

Okay, here’s a question: what about your emulator requires keymapping?
I mean, if I plug a german keyboard into an iMac, shouldn’t it work?
How are you emulating your keyboard device? Do you know how to
correctly report the type of keyboard when the emulated OS probes for
that sort of information? (I have no idea what the standard is for
that.)On Aug 19, 2004, at 1:43 PM, Sebastian Biallas wrote:

On Aug 18, 2004, at 2:50 AM, Sebastian Biallas wrote:

Note that this is not only a problem with PearPC: with my current
keyboard layout it’s almost impossible to use DOSBox.

My current solution is that I rely on the scancodes of SDL. A little
bit ugly, because I have to #ifdef for all platforms, but a lot better
than the keysyms, from a users perspective (i.e. everybody can
compile/install pearpc without have to configure anything and the
keyboard just works; they select whatever locale the like in the guest
OS)

So, the nicest solution for me would be to have host indepedent
scancodes; something the same I currently provide in pearpc via
#ifdefs.

Sebastian

[1] http://pearpc.sf.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Donny Viszneki wrote:

Donny Viszneki wrote:

Donny Viszneki wrote:

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to
do with the language / country / locale of the user, I am using a
laptop and plenty of keys that exist on a full keyboard are
missing, or require holding the dreaded Function key. This is
generally not suitable for games, but most tend to let me customize
my controls, so it’s not a problem any longer, you should probably
do what they’re doing.

While customization is in general a good idea[tm], it doesn’t really
help me in this topic. I’d still be forced to use scancodes instead
of the keysyms, since not all keys are reachable via the keysyms.
E.g. on my current locale[1], both the ESC and the ‘[’ key map to
escape. While this is good for programming / writing text, I’d
prefer a raw keyboard when playing games.

Please help me understand. The reason you can’t use Keysyms is
because you have remapped your keyboard layout?

For example, yes. My keyboard layout is for writing text and
programming. It contains a lot of meta, compose etc. keys, that only
make sense while writing text. But when playing games I consider a
keyboard as an input device with 102+ buttons – not more. Why
configure the keyboard for every game when the programmer can provide
sane defaults independent of keyboard layout?

Let me elaborate a little bit more. I currently work on PearPC[1]. If
I would use keysyms, I’d force all users that don’t use the us
keyboard layout to configure the keyboard first; all 102+ keys! And
for configuring they had know how the keys are arranged on an us
keyboard (well I could provide a picture). And when the switch their
layout (there are a lot of people who switch regulary between
german/us layout, for writing text/programming), they had to configure
again.

Okay, here’s a question: what about your emulator requires keymapping?

If I’d emulate an USB/PC-Keyboard: Nothing. But I emulate an ADB
keyboard which has other scancodes.

I must confess that I’m not sure if my X11 keymapping is always right,
or just for PCs. Therefore I’d nice if I could delegate this problem to SDL.

I
mean, if I plug a german keyboard into an iMac, shouldn’t it work?

A german keyboard behaves exactly like an us keyboard. It just has other
pictures on the keys. You can’t decide which keyboard is in front of you
if someone removes all the decribtions on the keys (well, german
keyboards have one extra key, but let’s ignore this).

But I emulate an ADB keyboard with uses other scancodes, therefore I
need that mapping.

How
are you emulating your keyboard device?

Well, I do what I’m supposed to do. The guest ask for a key over the ADB
bus and I answer. And the guest expects a raw scancode, all the
localization stuff is beyond my scope because it’s done in the client OS.

BTW: This is the same VMWare does, I recently read their documentation
about it; so I think it’s somehow sane.

Do you know how to correctly
report the type of keyboard when the emulated OS probes for that sort of
information? (I have no idea what the standard is for that.)

Yes.

Sebastian> On Aug 19, 2004, at 1:43 PM, Sebastian Biallas wrote:

On Aug 18, 2004, at 2:50 AM, Sebastian Biallas wrote:

im not even remotely an expert in this subject but you were saying how all
keyboards are the same except the pictures on the keys (extra key aside), it
sounds alot like something that should be handled by the OS then> ----- Original Message -----

From: sb@biallas.net (Sebastian Biallas)
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Thursday, August 19, 2004 11:27 AM
Subject: Re: [SDL] OS independent SDL_keysym.scancode

Donny Viszneki wrote:

On Aug 19, 2004, at 1:43 PM, Sebastian Biallas wrote:

Donny Viszneki wrote:

On Aug 18, 2004, at 2:50 AM, Sebastian Biallas wrote:

Donny Viszneki wrote:

You could allow for keys to be customized, or use different keymaps
depending on the locale. But this problem has little or nothing to
do with the language / country / locale of the user, I am using a
laptop and plenty of keys that exist on a full keyboard are
missing, or require holding the dreaded Function key. This is
generally not suitable for games, but most tend to let me customize
my controls, so it’s not a problem any longer, you should probably
do what they’re doing.

While customization is in general a good idea[tm], it doesn’t really
help me in this topic. I’d still be forced to use scancodes instead
of the keysyms, since not all keys are reachable via the keysyms.
E.g. on my current locale[1], both the ESC and the ‘[’ key map to
escape. While this is good for programming / writing text, I’d
prefer a raw keyboard when playing games.

Please help me understand. The reason you can’t use Keysyms is
because you have remapped your keyboard layout?

For example, yes. My keyboard layout is for writing text and
programming. It contains a lot of meta, compose etc. keys, that only
make sense while writing text. But when playing games I consider a
keyboard as an input device with 102+ buttons – not more. Why
configure the keyboard for every game when the programmer can provide
sane defaults independent of keyboard layout?

Let me elaborate a little bit more. I currently work on PearPC[1]. If
I would use keysyms, I’d force all users that don’t use the us
keyboard layout to configure the keyboard first; all 102+ keys! And
for configuring they had know how the keys are arranged on an us
keyboard (well I could provide a picture). And when the switch their
layout (there are a lot of people who switch regulary between
german/us layout, for writing text/programming), they had to configure
again.

Okay, here’s a question: what about your emulator requires keymapping?

If I’d emulate an USB/PC-Keyboard: Nothing. But I emulate an ADB
keyboard which has other scancodes.

I must confess that I’m not sure if my X11 keymapping is always right,
or just for PCs. Therefore I’d nice if I could delegate this problem to
SDL.

I
mean, if I plug a german keyboard into an iMac, shouldn’t it work?

A german keyboard behaves exactly like an us keyboard. It just has other
pictures on the keys. You can’t decide which keyboard is in front of you
if someone removes all the decribtions on the keys (well, german
keyboards have one extra key, but let’s ignore this).

But I emulate an ADB keyboard with uses other scancodes, therefore I
need that mapping.

How
are you emulating your keyboard device?

Well, I do what I’m supposed to do. The guest ask for a key over the ADB
bus and I answer. And the guest expects a raw scancode, all the
localization stuff is beyond my scope because it’s done in the client OS.

BTW: This is the same VMWare does, I recently read their documentation
about it; so I think it’s somehow sane.

Do you know how to correctly
report the type of keyboard when the emulated OS probes for that sort of
information? (I have no idea what the standard is for that.)

Yes.

Sebastian


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Alan Wolfe wrote:

im not even remotely an expert in this subject but you were saying how all
keyboards are the same except the pictures on the keys (extra key aside), it
sounds alot like something that should be handled by the OS then

The keyboard mapping is done by the OS, yes. But it’s mainly done for
writing. Therefore all OSs I know of also provide scancodes – for
example for writing games or other things that normally require raw
keyboard access.

And those scancodes are completely independet of the describtion of the
keys or if you use an us or a german keyboard: They are just numbers for
the keys, independent of any locate.

And IMHO it’s better to use scancodes for game programming. Let’s
suppose someone has a german layout (there are the ‘z’ and ‘y’ keys
swapped), and configures a game with ‘z’ to move forward, ‘h’ to move
backwards, ‘g’ to move left, etc. Now our german keyboard users must get
to work, programming, and switches to his favorite us keyboard layout
for programming. Then again needs some recovery, and starts the game
again: Now his configuration is broken, which is an unnecessary annoyance.

This is because in games the keys normally should have meanings
completely indepedent of the locale. When a player presses the ‘z’ key
he expects to move forward and not a z to appear on screen. And when he
presses shift he most likely doesn’t want to capitalize anything but to
jump or something.

Sebastian

Sebastian Biallas wrote:

And IMHO it’s better to use scancodes for game programming. Let’s
suppose someone has a german layout (there are the ‘z’ and ‘y’ keys
swapped), and configures a game with ‘z’ to move forward, ‘h’ to move
backwards, ‘g’ to move left, etc. Now our german keyboard users must get
to work, programming, and switches to his favorite us keyboard layout
for programming. Then again needs some recovery, and starts the game
again: Now his configuration is broken, which is an unnecessary annoyance.

I must add here: His configuration is broken if the game used SDL
keysyms for keyboard handling. If the game used scancodes, the user
wouldn’t notice anything, because scancodes don’t change.>

This is because in games the keys normally should have meanings
completely indepedent of the locale. When a player presses the ‘z’ key
he expects to move forward and not a z to appear on screen. And when he
presses shift he most likely doesn’t want to capitalize anything but to
jump or something.

Sebastian

Sebastian Biallas wrote:

And IMHO it’s better to use scancodes for game programming. Let’s
suppose someone has a german layout (there are the ‘z’ and ‘y’ keys
swapped), and configures a game with ‘z’ to move forward, ‘h’ to move
backwards, ‘g’ to move left, etc. Now our german keyboard users must get
to work, programming, and switches to his favorite us keyboard layout
for programming. Then again needs some recovery, and starts the game
again: Now his configuration is broken, which is an unnecessary annoyance.

I must add here: His configuration is broken if the game used SDL
keysyms for keyboard handling. If the game used scancodes, the user
wouldn’t notice anything, because scancodes don’t change.

This is a little tricky. The SDL keysyms really are supposed to be
platform independent keys on the keyboard. Since there are many different
keyboards and keyboard-like input devices, SDL doesn’t try to hardcode
scancode mappings, and instead relies on the underlying OS to tell it
which key was pressed with each key event.

However, some platforms allow the user to remap which keysyms are
text input mappings, simply what virtual scancode is presented for each
real key.

So… you can rely on SDL, which can be fooled by the OS (problem? feature?)
or you can hardcode your mappings, which won’t work on different keyboards.
Neither solution is perfect, unfortunately.

BTW, I’m constantly updating the SDL keysym list. If your keyboard has a
key that isn’t recognized by SDL, please let me know what the key is and
the output of the checkkeys test program in the SDL source archive.

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainmentsent by each physical key. Note that I’m not talking about locale or