We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3244 - AltGr generates invalid keycode under Linux
Summary: AltGr generates invalid keycode under Linux
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.4
Hardware: x86 Linux
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-20 16:27 UTC by Pedro Gimeno
Modified: 2016-01-31 13:41 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro Gimeno 2016-01-20 16:27:36 UTC
I wasn't sure if the correct component was 'event' or 'video', since the commit that broke this behaviour affects both.

I use SDL with X11 under Linux (Debian Wheezy with some packages from Jessie, Stretch and Experimental). When I compile and run this bare bones program:

#include <stdio.h>
#include "SDL.h"
int main()
{
    SDL_bool done = SDL_FALSE;
    SDL_Init(0);
    SDL_CreateWindow("Window Title", 0, 0, 640, 480, SDL_WINDOW_SHOWN);
    while (!done) {
        SDL_Event event;
        if (SDL_PollEvent(&event)) {
            switch (event.type) {
                case SDL_QUIT:
                    done = SDL_TRUE;
                    break;
                case SDL_KEYDOWN:
                    printf("0x%X", event.key.keysym.sym);
                    printf(" %d\n", event.key.keysym.sym == SDLK_RALT);
            }
        }
    }
    SDL_Quit();
    return 0;
}

and press AltGr, with SDL 2.0.3 it displays:

0x400000E6 1

which means that the keysym is SDLK_RALT. This is OK. However, when I run it with SDL 2.0.4, it displays:

0x40000000 0

Given that 0x40000000 is not associated to any SDLK_xxx constant, I believe that this is a bug.

By bisecting I've found that the problem was introduced in this commit: http://hg.libsdl.org/SDL/rev/9e8323b058d6

The other keys seem to work fine. In particular, RSHIFT, RCTRL, LSHIFT, LCTRL, LALT all generate the expected keysym.sym value.

In case it's important, my keyboard layout is Spanish, and to my recollection (which isn't that good) I have only remapped Scroll Lock and no other key.
Comment 1 Thomas Huth 2016-01-31 01:04:33 UTC
We've hit the same problem with the SDL-based emulator "Hatari", see the mail thread here: http://listengine.tuxfamily.org/lists.tuxfamily.org/hatari-devel/2016/01/msg00046.html

I've already had a closer look at the problem, and I think it is due to AltGr being reported as "ISO_Level3_Shift" on certain european keyboards (mine is German, and the person who reported the problem for Hatari uses a French keyboard). However, SDL2 currently only supports the "Alt_R" keycode in SDL_x11keyboard.c.

The following patch fixes this issue for me:

diff -r 9e8323b058d6 src/video/x11/SDL_x11keyboard.c
--- a/src/video/x11/SDL_x11keyboard.c	Thu May 28 12:48:20 2015 -0700
+++ b/src/video/x11/SDL_x11keyboard.c	Sun Jan 31 02:03:39 2016 +0100
@@ -128,6 +128,7 @@
     { XK_Control_R, SDL_SCANCODE_RCTRL },
     { XK_Shift_R, SDL_SCANCODE_RSHIFT },
     { XK_Alt_R, SDL_SCANCODE_RALT },
+    { XK_ISO_Level3_Shift, SDL_SCANCODE_RALT },
     { XK_Meta_R, SDL_SCANCODE_RGUI },
     { XK_Super_R, SDL_SCANCODE_RGUI },
     { XK_Mode_switch, SDL_SCANCODE_MODE },
Comment 2 Pedro Gimeno 2016-01-31 04:56:58 UTC
I confirm that the patch in Comment #1 solves the issue for me. Thanks, Thomas.
Comment 3 Alex Szpakowski 2016-01-31 13:41:03 UTC
I pushed the fix: https://hg.libsdl.org/SDL/rev/25f67a2e77a0

Let me know if it doesn't work out – I also looked at some other open source projects which have the same fix.