Fix for the Non-English keyboard layouts bug

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tobias
    Adept
    • Dec 2009
    • 172

    Fix for the Non-English keyboard layouts bug

    Bug http://trac.rephial.org/ticket/1460 has been getting on my nerves again. I think I found the problem.

    The problem is that SDL seems to use the Keycode of the pressed key instead of the modified key, when the modifier is Alt-Gr (SDL calls it Mode).


    So here key_code still contains the correct symbol (which is why it sometimes works).
    key_sym does contain the wrong key.
    Angband uses key_sym instead of key_code for some keys (no idea why).

    I added a conditional to skip use of key_sym for the number keys if Alt-Gr is pressed.
    It might be better to skip the whole case-block if Alt-Gr is pressed. But I have no idea if this might break something else.

    The diff is vs. V4 from last week btw.
    Code:
    diff --git a/src/main-sdl.c b/src/main-sdl.c
    index 74ddc9e..c9b9378 100644
    --- a/src/main-sdl.c
    +++ b/src/main-sdl.c
    @@ -2386,6 +2386,7 @@ static void sdl_keypress(SDL_keysym keysym)
            bool ms = (keysym.mod & KMOD_SHIFT) > 0;
            bool ma = (keysym.mod & KMOD_ALT) > 0;
            bool mm = (keysym.mod & KMOD_META) > 0;
    +        bool mg = (keysym.mod & KMOD_MODE) > 0;
            bool kp = FALSE;
     
            byte mods = (ma ? KC_MOD_ALT : 0) | (mm ? KC_MOD_META : 0);
    @@ -2415,16 +2416,16 @@ static void sdl_keypress(SDL_keysym keysym)
                    case SDLK_KP_EQUALS: ch = '='; kp = TRUE; break;
     
                    /* have have these to get consistent ctrl-shift behaviour */
    -               case SDLK_0: if (!ms || mc || ma) ch = '0'; break;
    -               case SDLK_1: if (!ms || mc || ma) ch = '1'; break;
    -               case SDLK_2: if (!ms || mc || ma) ch = '2'; break;
    -               case SDLK_3: if (!ms || mc || ma) ch = '3'; break;
    -               case SDLK_4: if (!ms || mc || ma) ch = '4'; break;
    -               case SDLK_5: if (!ms || mc || ma) ch = '5'; break;
    -               case SDLK_6: if (!ms || mc || ma) ch = '6'; break;
    -               case SDLK_7: if (!ms || mc || ma) ch = '7'; break;
    -               case SDLK_8: if (!ms || mc || ma) ch = '8'; break;
    -               case SDLK_9: if (!ms || mc || ma) ch = '9'; break;
    +               case SDLK_0: if ((!ms || mc || ma) && !mg) ch = '0'; break;
    +               case SDLK_1: if ((!ms || mc || ma) && !mg) ch = '1'; break;
    +               case SDLK_2: if ((!ms || mc || ma) && !mg) ch = '2'; break;
    +               case SDLK_3: if ((!ms || mc || ma) && !mg) ch = '3'; break;
    +               case SDLK_4: if ((!ms || mc || ma) && !mg) ch = '4'; break;
    +               case SDLK_5: if ((!ms || mc || ma) && !mg) ch = '5'; break;
    +               case SDLK_6: if ((!ms || mc || ma) && !mg) ch = '6'; break;
    +                case SDLK_7: if ((!ms || mc || ma) && !mg) ch = '7'; break;
    +                case SDLK_8: if ((!ms || mc || ma) && !mg) ch = '8'; break;
    +               case SDLK_9: if ((!ms || mc || ma) && !mg) ch = '9'; break;
     
                    case SDLK_UP: ch = ARROW_UP; break;
                    case SDLK_DOWN: ch = ARROW_DOWN; break;
    My Angband videos : http://www.youtube.com/view_play_lis...385E85F31166B2
  • Magnate
    Angband Devteam member
    • May 2007
    • 5110

    #2
    Brilliant - thank you. That's so straightforward that even I could commit it. I've updated the ticket.
    "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

    Comment

    • Tobias
      Adept
      • Dec 2009
      • 172

      #3
      Originally posted by Magnate
      Brilliant - thank you. That's so straightforward that even I could commit it. I've updated the ticket.
      It IS possible that it will need some more lines of skips. I only tested this for german keyboard layout.
      If the bug also hits some non-number keys on other keyboards it might have to be expanded.
      My Angband videos : http://www.youtube.com/view_play_lis...385E85F31166B2

      Comment

      • Magnate
        Angband Devteam member
        • May 2007
        • 5110

        #4
        Originally posted by Tobias
        It IS possible that it will need some more lines of skips. I only tested this for german keyboard layout.
        If the bug also hits some non-number keys on other keyboards it might have to be expanded.
        Sure, but the important thing is that you've added the mg bool to test for the ALT_MODE. This is the key thing that was missing.
        "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

        Comment

        • PowerWyrm
          Prophet
          • Apr 2008
          • 2986

          #5
          Doesn't work for me

          I'm using a french keyboard and pressing Alt-Gr + "0" to get "@" is interpreted by SDL as SDLK_0 with mods = KMOD_NUM | KMOD_RALT | KMOD_LCTRL.

          Moreover, when I change KMOD_MODE to KMOD_RALT | KMOD_LCTRL in the proposed fix, it works for keys like "~", "[" or "@" as intended, but now the keys mapped to SDLK_0-9 with only mods = KMOD_NUM don't work anymore: "&" acts like "1", "(" like "5"...

          The only way I found to remove the bug completely is to remove the case SDLK_ lines like it was done in main-win.
          Last edited by PowerWyrm; May 11, 2012, 15:39.
          PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!

          Comment

          • PowerWyrm
            Prophet
            • Apr 2008
            • 2986

            #6
            Another related problem on SDL: with an AZERTY keyboard, keys '0' (0x30) to '9' (0x39) are accessed using SHIFT + key; with the current code, these keys are not processed because MODS_INCLUDE_SHIFT() in ui-event.h reports them as requiring SHIFT. To fix that, MODS_INCLUDE_SHIFT() should include range 0x30 to 0x39:

            Code:
            #define MODS_INCLUDE_SHIFT(v) \
                (((((v) >= 0x21) && ((v) <= 0x60)) || \
                    (((v) >= 0x7B) && ((v) <= 0x7E)))? FALSE: TRUE)
            PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!

            Comment

            Working...
            😀
            😂
            🥰
            😘
            🤢
            😎
            😞
            😡
            👍
            👎