Getting key name based on current layout

For the keyboard settings menu in my game, I’d like to be able to show
the real names of the keys according to the current layout. For
example, if the current layout is AZERTY, then the scancode for the
key W should show up as “Z” on screen.

At first I thought about using SDL_GetScancodeName for the job, but a
quick look to the code and the wiki seems to indicate that the names
are fixed for each scancode regardless of layout. I’m using QWERTY so
I can’t tell if this is indeed the case.

Is there a way to retrieve the real name of a key, based on the
current layout? Or maybe just the Unicode codepoint it’d return under
normal circumstances, if any (in the case of dead keys it’d return
whatever character would be typed when a suitable letter isn’t
entered), though this second idea may lead to some people using that
for text entering instead of the proper API, which is bad.

Any suggestions? Am I overlooking something?

I think what you want is SDL_GetKeyName()On Mon, Oct 22, 2012 at 12:15 PM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

For the keyboard settings menu in my game, I’d like to be able to show
the real names of the keys according to the current layout. For
example, if the current layout is AZERTY, then the scancode for the
key W should show up as “Z” on screen.

At first I thought about using SDL_GetScancodeName for the job, but a
quick look to the code and the wiki seems to indicate that the names
are fixed for each scancode regardless of layout. I’m using QWERTY so
I can’t tell if this is indeed the case.

Is there a way to retrieve the real name of a key, based on the
current layout? Or maybe just the Unicode codepoint it’d return under
normal circumstances, if any (in the case of dead keys it’d return
whatever character would be typed when a suitable letter isn’t
entered), though this second idea may lead to some people using that
for text entering instead of the proper API, which is bad.

Any suggestions? Am I overlooking something?


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

Possibly in conjunction with SDL_GetKeyFromScancode()

One problem is that there are way more scancodes than real keys (usually)
so you don’t know if the keyboard has a particular key unless you build
your own keyboard database.On Mon, Oct 22, 2012 at 9:55 PM, Sam Lantinga <@slouken> wrote:

I think what you want is SDL_GetKeyName()

On Mon, Oct 22, 2012 at 12:15 PM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

For the keyboard settings menu in my game, I’d like to be able to show
the real names of the keys according to the current layout. For
example, if the current layout is AZERTY, then the scancode for the
key W should show up as “Z” on screen.

At first I thought about using SDL_GetScancodeName for the job, but a
quick look to the code and the wiki seems to indicate that the names
are fixed for each scancode regardless of layout. I’m using QWERTY so
I can’t tell if this is indeed the case.

Is there a way to retrieve the real name of a key, based on the
current layout? Or maybe just the Unicode codepoint it’d return under
normal circumstances, if any (in the case of dead keys it’d return
whatever character would be typed when a suitable letter isn’t
entered), though this second idea may lead to some people using that
for text entering instead of the proper API, which is bad.

Any suggestions? Am I overlooking something?


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

I just care about the name of the key the user pressed :stuck_out_tongue: And when I
can’t retrieve the name I’ll just show something else to identify it
(won’t look nice, but it’s better than nothing).

I didn’t test this yet (I need to program the menu still), but I was
wondering: when is the current layout detected? I looked through the
code but I have no idea where SDL_SetKeymap is called. I imagine it
isn’t in SDL_keyboard.c because retrieving it is an OS-dependent
function, but I got curious about it.

At least it does seem to be the function I need. Thanks!

2012/10/23 Sam Lantinga :> Possibly in conjunction with SDL_GetKeyFromScancode()

One problem is that there are way more scancodes than real keys (usually) so
you don’t know if the keyboard has a particular key unless you build your
own keyboard database.

On Mon, Oct 22, 2012 at 9:55 PM, Sam Lantinga wrote:

I think what you want is SDL_GetKeyName()

On Mon, Oct 22, 2012 at 12:15 PM, Sik the hedgehog <@Sik_the_hedgehog> wrote:

For the keyboard settings menu in my game, I’d like to be able to show
the real names of the keys according to the current layout. For
example, if the current layout is AZERTY, then the scancode for the
key W should show up as “Z” on screen.

At first I thought about using SDL_GetScancodeName for the job, but a
quick look to the code and the wiki seems to indicate that the names
are fixed for each scancode regardless of layout. I’m using QWERTY so
I can’t tell if this is indeed the case.

Is there a way to retrieve the real name of a key, based on the
current layout? Or maybe just the Unicode codepoint it’d return under
normal circumstances, if any (in the case of dead keys it’d return
whatever character would be typed when a suitable letter isn’t
entered), though this second idea may lead to some people using that
for text entering instead of the proper API, which is bad.

Any suggestions? Am I overlooking something?


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


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