Make the SDL keysyms that represent unprintable ASCII values actually have
authorSam Lantinga <slouken@libsdl.org>
Sun, 04 Jan 2009 17:10:04 +0000
changeset 2989aba5a5cc2e63
parent 2988 e7dd24f2f890
child 2990 502adab079a4
Make the SDL keysyms that represent unprintable ASCII values actually have
those values, for more intuitive use and better compatibility with SDL 1.2.
include/SDL_keysym.h
src/events/SDL_keyboard.c
     1.1 --- a/include/SDL_keysym.h	Sun Jan 04 17:04:29 2009 +0000
     1.2 +++ b/include/SDL_keysym.h	Sun Jan 04 17:10:04 2009 +0000
     1.3 @@ -49,11 +49,11 @@
     1.4  {
     1.5      SDLK_UNKNOWN = 0,
     1.6  
     1.7 -    SDLK_RETURN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN),
     1.8 -    SDLK_ESCAPE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ESCAPE),
     1.9 -    SDLK_BACKSPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BACKSPACE),
    1.10 -    SDLK_TAB = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_TAB),
    1.11 -    SDLK_SPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SPACE),
    1.12 +    SDLK_RETURN = '\r',
    1.13 +    SDLK_ESCAPE = '\033',
    1.14 +    SDLK_BACKSPACE = '\b',
    1.15 +    SDLK_TAB = '\t',
    1.16 +    SDLK_SPACE = ' ',
    1.17  
    1.18      SDLK_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK),
    1.19  
    1.20 @@ -76,7 +76,7 @@
    1.21      SDLK_INSERT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT),
    1.22      SDLK_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME),
    1.23      SDLK_PAGEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP),
    1.24 -    SDLK_DELETE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DELETE),
    1.25 +    SDLK_DELETE = '\177',
    1.26      SDLK_END = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END),
    1.27      SDLK_PAGEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN),
    1.28      SDLK_RIGHT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT),
     2.1 --- a/src/events/SDL_keyboard.c	Sun Jan 04 17:04:29 2009 +0000
     2.2 +++ b/src/events/SDL_keyboard.c	Sun Jan 04 17:10:04 2009 +0000
     2.3 @@ -973,17 +973,32 @@
     2.4              SDL_GetScancodeName((SDL_scancode) (key & ~SDLK_SCANCODE_MASK));
     2.5      }
     2.6  
     2.7 -    /* Unaccented letter keys on latin keyboards are normally
     2.8 -       labeled in upper case (and probably on others like Greek or
     2.9 -       Cyrillic too, so if you happen to know for sure, please
    2.10 -       adapt this). */
    2.11 -    if (key >= 'a' && key <= 'z') {
    2.12 -        key -= 32;
    2.13 +    switch (key) {
    2.14 +    case SDLK_RETURN:
    2.15 +            return SDL_GetScancodeName(SDL_SCANCODE_RETURN);
    2.16 +    case SDLK_ESCAPE:
    2.17 +            return SDL_GetScancodeName(SDL_SCANCODE_ESCAPE);
    2.18 +    case SDLK_BACKSPACE:
    2.19 +            return SDL_GetScancodeName(SDL_SCANCODE_BACKSPACE);
    2.20 +    case SDLK_TAB:
    2.21 +            return SDL_GetScancodeName(SDL_SCANCODE_TAB);
    2.22 +    case SDLK_SPACE:
    2.23 +            return SDL_GetScancodeName(SDL_SCANCODE_SPACE);
    2.24 +    case SDLK_DELETE:
    2.25 +            return SDL_GetScancodeName(SDL_SCANCODE_DELETE);
    2.26 +    default:
    2.27 +        /* Unaccented letter keys on latin keyboards are normally
    2.28 +           labeled in upper case (and probably on others like Greek or
    2.29 +           Cyrillic too, so if you happen to know for sure, please
    2.30 +           adapt this). */
    2.31 +        if (key >= 'a' && key <= 'z') {
    2.32 +            key -= 32;
    2.33 +        }
    2.34 +
    2.35 +        end = SDL_UCS4ToUTF8((Uint32) key, name);
    2.36 +        *end = '\0';
    2.37 +        return name;
    2.38      }
    2.39 -
    2.40 -    end = SDL_UCS4ToUTF8((Uint32) key, name);
    2.41 -    *end = '\0';
    2.42 -    return name;
    2.43  }
    2.44  
    2.45  /* vi: set ts=4 sw=4 expandtab: */