Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AltGr generates invalid keycode under Linux #2083

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

AltGr generates invalid keycode under Linux #2083

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 11, 2021

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.4
Reported for operating system, platform: Linux, x86

Comments on the original bug report:

On 2016-01-20 16:27:36 +0000, Pedro Gimeno wrote:

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.

On 2016-01-31 01:04:33 +0000, Thomas Huth wrote:

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 },

On 2016-01-31 04:56:58 +0000, Pedro Gimeno wrote:

I confirm that the patch in Comment # 1 solves the issue for me. Thanks, Thomas.

On 2016-01-31 13:41:03 +0000, Alex Szpakowski wrote:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant