changeset 2989:aba5a5cc2e63

Make the SDL keysyms that represent unprintable ASCII values actually have those values, for more intuitive use and better compatibility with SDL 1.2.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 04 Jan 2009 17:10:04 +0000
parents e7dd24f2f890
children 502adab079a4
files include/SDL_keysym.h src/events/SDL_keyboard.c
diffstat 2 files changed, 31 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_keysym.h	Sun Jan 04 17:04:29 2009 +0000
+++ b/include/SDL_keysym.h	Sun Jan 04 17:10:04 2009 +0000
@@ -49,11 +49,11 @@
 {
     SDLK_UNKNOWN = 0,
 
-    SDLK_RETURN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN),
-    SDLK_ESCAPE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ESCAPE),
-    SDLK_BACKSPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BACKSPACE),
-    SDLK_TAB = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_TAB),
-    SDLK_SPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SPACE),
+    SDLK_RETURN = '\r',
+    SDLK_ESCAPE = '\033',
+    SDLK_BACKSPACE = '\b',
+    SDLK_TAB = '\t',
+    SDLK_SPACE = ' ',
 
     SDLK_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK),
 
@@ -76,7 +76,7 @@
     SDLK_INSERT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT),
     SDLK_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME),
     SDLK_PAGEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP),
-    SDLK_DELETE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DELETE),
+    SDLK_DELETE = '\177',
     SDLK_END = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END),
     SDLK_PAGEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN),
     SDLK_RIGHT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT),
--- a/src/events/SDL_keyboard.c	Sun Jan 04 17:04:29 2009 +0000
+++ b/src/events/SDL_keyboard.c	Sun Jan 04 17:10:04 2009 +0000
@@ -973,17 +973,32 @@
             SDL_GetScancodeName((SDL_scancode) (key & ~SDLK_SCANCODE_MASK));
     }
 
-    /* Unaccented letter keys on latin keyboards are normally
-       labeled in upper case (and probably on others like Greek or
-       Cyrillic too, so if you happen to know for sure, please
-       adapt this). */
-    if (key >= 'a' && key <= 'z') {
-        key -= 32;
+    switch (key) {
+    case SDLK_RETURN:
+            return SDL_GetScancodeName(SDL_SCANCODE_RETURN);
+    case SDLK_ESCAPE:
+            return SDL_GetScancodeName(SDL_SCANCODE_ESCAPE);
+    case SDLK_BACKSPACE:
+            return SDL_GetScancodeName(SDL_SCANCODE_BACKSPACE);
+    case SDLK_TAB:
+            return SDL_GetScancodeName(SDL_SCANCODE_TAB);
+    case SDLK_SPACE:
+            return SDL_GetScancodeName(SDL_SCANCODE_SPACE);
+    case SDLK_DELETE:
+            return SDL_GetScancodeName(SDL_SCANCODE_DELETE);
+    default:
+        /* Unaccented letter keys on latin keyboards are normally
+           labeled in upper case (and probably on others like Greek or
+           Cyrillic too, so if you happen to know for sure, please
+           adapt this). */
+        if (key >= 'a' && key <= 'z') {
+            key -= 32;
+        }
+
+        end = SDL_UCS4ToUTF8((Uint32) key, name);
+        *end = '\0';
+        return name;
     }
-
-    end = SDL_UCS4ToUTF8((Uint32) key, name);
-    *end = '\0';
-    return name;
 }
 
 /* vi: set ts=4 sw=4 expandtab: */