changeset 2303:d87417504c75

First pass implementation of new SDL scancode concept, as discussed with Christian Walther. Currently only implemented on Mac OS X for sanity checking purposes.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 05 Feb 2008 07:19:23 +0000
parents 7ae1c419b626
children 50f58ce12497
files Makefile.in include/SDL_compat.h include/SDL_keyboard.h include/SDL_keysym.h include/SDL_scancode.h src/SDL_compat.c src/events/SDL_keyboard.c src/events/SDL_keyboard_c.h src/events/SDL_keynames.h src/video/SDL_sysvideo.h src/video/cocoa/SDL_cocoakeyboard.h src/video/cocoa/SDL_cocoakeyboard.m src/video/cocoa/SDL_cocoakeys.h src/video/cocoa/SDL_cocoavideo.h src/video/cocoa/SDL_cocoavideo.m test/checkkeys.c
diffstat 16 files changed, 1581 insertions(+), 1341 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.in	Mon Feb 04 17:25:33 2008 +0000
+++ b/Makefile.in	Tue Feb 05 07:19:23 2008 +0000
@@ -42,7 +42,7 @@
 
 DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS docs docs.html include INSTALL Makefile.dc Makefile.minimal Makefile.in README* sdl-config.in sdl.m4 sdl.pc.in SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualC.html VisualC VisualCE Watcom-OS2.zip Watcom-Win32.zip WhatsNew Xcode
 
-HDRS = SDL.h SDL_audio.h SDL_cdrom.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_pixels.h SDL_platform.h SDL_quit.h SDL_rect.h SDL_rwops.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h
+HDRS = SDL.h SDL_audio.h SDL_cdrom.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_pixels.h SDL_platform.h SDL_quit.h SDL_rect.h SDL_rwops.h SDL_scancode.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h
 
 LT_AGE      = @LT_AGE@
 LT_CURRENT  = @LT_CURRENT@
--- a/include/SDL_compat.h	Mon Feb 04 17:25:33 2008 +0000
+++ b/include/SDL_compat.h	Tue Feb 05 07:19:23 2008 +0000
@@ -130,47 +130,54 @@
 
 struct SDL_SysWMinfo;
 
-/* Key codes
-   Note that the correspondences defined here are approximate at best because
-   the meaning of the event structure field that carries these values has
-   changed: in SDL 1.2, it referred to the key's label in the current keyboard
-   layout, whereas now it refers to a specific physical key on the keyboard,
-   regardless of the keyboard layout setting.
-   To get comparable behavior to SDL 1.2, code that uses any of the codes below
-   in ways like "if (somekey == SDLK_EXCLAIM)" should be changed to the
-   equivalent of "if (SDL_GetLayoutKey(somekey) == '!')".
- */
+/* Obsolete or renamed key codes */
 
-/* These key constants were renamed for clarity or consistence. */
-#define SDLK_QUOTE SDLK_APOSTROPHE
-#define SDLK_MINUS SDLK_HYPHENMINUS
-#define SDLK_BACKQUOTE SDLK_GRAVE
-#define SDLK_a SDLK_A
-#define SDLK_b SDLK_B
-#define SDLK_c SDLK_C
-#define SDLK_d SDLK_D
-#define SDLK_e SDLK_E
-#define SDLK_f SDLK_F
-#define SDLK_g SDLK_G
-#define SDLK_h SDLK_H
-#define SDLK_i SDLK_I
-#define SDLK_j SDLK_J
-#define SDLK_k SDLK_K
-#define SDLK_l SDLK_L
-#define SDLK_m SDLK_M
-#define SDLK_n SDLK_N
-#define SDLK_o SDLK_O
-#define SDLK_p SDLK_P
-#define SDLK_q SDLK_Q
-#define SDLK_r SDLK_R
-#define SDLK_s SDLK_S
-#define SDLK_t SDLK_T
-#define SDLK_u SDLK_U
-#define SDLK_v SDLK_V
-#define SDLK_w SDLK_W
-#define SDLK_x SDLK_X
-#define SDLK_y SDLK_Y
-#define SDLK_z SDLK_Z
+/* These key constants were renamed for clarity or consistency. */
+#define SDLK_a  'a'
+#define SDLK_b  'b'
+#define SDLK_c  'c'
+#define SDLK_d  'd'
+#define SDLK_e  'e'
+#define SDLK_f  'f'
+#define SDLK_g  'g'
+#define SDLK_h  'h'
+#define SDLK_i  'i'
+#define SDLK_j  'j'
+#define SDLK_k  'k'
+#define SDLK_l  'l'
+#define SDLK_m  'm'
+#define SDLK_n  'n'
+#define SDLK_o  'o'
+#define SDLK_p  'p'
+#define SDLK_q  'q'
+#define SDLK_r  'r'
+#define SDLK_s  's'
+#define SDLK_t  't'
+#define SDLK_u  'u'
+#define SDLK_v  'v'
+#define SDLK_w  'w'
+#define SDLK_x  'x'
+#define SDLK_y  'y'
+#define SDLK_z  'z'
+#define SDLK_QUOTE      '\''
+#define SDLK_MINUS      '-'
+#define SDLK_BACKQUOTE  '`'
+#define SDLK_EXCLAIM    '!'
+#define SDLK_QUOTEDBL   '"'
+#define SDLK_HASH       '#'
+#define SDLK_DOLLAR     '$'
+#define SDLK_AMPERSAND  '&'
+#define SDLK_LEFTPAREN  '('
+#define SDLK_RIGHTPAREN ')'
+#define SDLK_ASTERISK   '*'
+#define SDLK_PLUS       '+'
+#define SDLK_COLON      ':'
+#define SDLK_LESS       '<'
+#define SDLK_GREATER    '>'
+#define SDLK_QUESTION   '?'
+#define SDLK_AT         '@'
+#define SDLK_CARET      '^'
+#define SDLK_UNDERSCORE '_'
 #define SDLK_KP0 SDLK_KP_0
 #define SDLK_KP1 SDLK_KP_1
 #define SDLK_KP2 SDLK_KP_2
@@ -181,30 +188,14 @@
 #define SDLK_KP7 SDLK_KP_7
 #define SDLK_KP8 SDLK_KP_8
 #define SDLK_KP9 SDLK_KP_9
-#define SDLK_NUMLOCK SDLK_KP_NUMLOCKCLEAR
+#define SDLK_NUMLOCK SDLK_NUMLOCKCLEAR
 #define SDLK_SCROLLOCK SDLK_SCROLLLOCK
 #define SDLK_PRINT SDLK_PRINTSCREEN
 
-/* These key constants are obsoleted by the new keyboard handling,
-   their definitions here correspond to how they appear on a US
-   keyboard. */
-
-#define SDLK_EXCLAIM SDLK_1
-#define SDLK_QUOTEDBL SDLK_APOSTROPHE
-#define SDLK_HASH SDLK_3
-#define SDLK_DOLLAR SDLK_4
-#define SDLK_AMPERSAND SDLK_7
-#define SDLK_LEFTPAREN SDLK_9
-#define SDLK_RIGHTPAREN SDLK_0
-#define SDLK_ASTERISK SDLK_8
-#define SDLK_PLUS SDLK_EQUALS
-#define SDLK_COLON SDLK_SEMICOLON
-#define SDLK_LESS SDLK_COMMA
-#define SDLK_GREATER SDLK_PERIOD
-#define SDLK_QUESTION SDLK_SLASH
-#define SDLK_AT SDLK_2
-#define SDLK_CARET SDLK_6
-#define SDLK_UNDERSCORE SDLK_HYPHENMINUS
+/* The META modifier is equivalent to the GUI modifier from the USB standard */
+#define KMOD_LMETA KMOD_LGUI
+#define KMOD_RMETA KMOD_RGUI
+#define KMOD_META KMOD_GUI
 
 /* These keys don't appear in the USB specification (or at least not under those names). I'm unsure if the following assignments make sense or if these codes should be defined as actual additional SDLK_ constants. */
 #define SDLK_LSUPER SDLK_LMETA
@@ -268,6 +259,7 @@
 extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
 extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
 extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
+extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
 
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
--- a/include/SDL_keyboard.h	Mon Feb 04 17:25:33 2008 +0000
+++ b/include/SDL_keyboard.h	Tue Feb 05 07:19:23 2008 +0000
@@ -48,8 +48,7 @@
  */
 typedef struct SDL_keysym
 {
-    Uint8 scancode;             /**< keyboard specific scancode */
-    Uint8 padding[3];           /**< alignment padding */
+    SDL_scancode scancode;      /**< SDL physical key code - see ::SDL_scancode for details */
     SDLKey sym;                 /**< SDL virtual key code - see ::SDLKey for details */
     Uint16 mod;                 /**< current key modifiers */
     Uint32 unicode;             /**< OBSOLETE, use SDL_TextInputEvent instead */
@@ -80,32 +79,19 @@
 extern DECLSPEC int SDLCALL SDL_SelectKeyboard(int index);
 
 /**
- * \fn int SDL_EnableUNICODE(int enable)
- *
- * \brief Enable/Disable UNICODE translation of keyboard input.
- *
- * \param enable 1 to enable translation, 0 to disable translation, -1 to query translation
- *
- * \return The previous state of keyboard translation
- *
- * \note This translation has some overhead, so translation defaults off.
- */
-extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
-
-/**
- * \fn Uint8 *SDL_GetKeyState(int *numkeys)
+ * \fn Uint8 *SDL_GetKeyboardState(int *numkeys)
  *
  * \brief Get a snapshot of the current state of the selected keyboard.
  *
  * \param numkeys if non-NULL, receives the length of the returned array.
  *
- * \return An array of key states. Indexes into this array are obtained by using the SDLK_INDEX() macro on the \link ::SDLPhysicalKey SDLK_* \endlink syms.
+ * \return An array of key states. Indexes into this array are obtained by using ::SDL_scancode values.
  *
  * Example:
- * 	Uint8 *keystate = SDL_GetKeyState(NULL);
- *	if ( keystate[SDLK_INDEX(SDLK_RETURN)] ) ... <RETURN> is pressed.
+ * 	Uint8 *state = SDL_GetKeyboardState(NULL);
+ *	if ( state[SDL_SCANCODE_RETURN)] ) ... <RETURN> is pressed.
  */
-extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyState(int *numkeys);
+extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
 
 /**
  * \fn SDLMod SDL_GetModState(void)
@@ -124,32 +110,49 @@
 extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);
 
 /**
- * \fn SDLKey SDL_GetLayoutKey(SDLKey physicalKey)
+ * \fn SDLKey SDL_GetKeyFromScancode(SDL_scancode scancode)
  * 
- * \brief Get the layout key code corresponding to the given physical key code according to the current keyboard layout.
+ * \brief Get the key code corresponding to the given scancode according to the current keyboard layout.
  *
  * See ::SDLKey for details.
  *
- * If \a physicalKey is not a physical key code, it is returned unchanged.
- *
  * \sa SDL_GetKeyName()
  */
-extern DECLSPEC SDLKey SDLCALL SDL_GetLayoutKey(SDLKey physicalKey);
+extern DECLSPEC SDLKey SDLCALL SDL_GetKeyFromScancode(SDL_scancode scancode);
+
+/**
+ * \fn SDL_scancode SDL_GetScancodeFromKey(SDLKey key)
+ * 
+ * \brief Get the scancode corresponding to the given key code according to the current keyboard layout.
+ *
+ * See ::SDL_scancode for details.
+ *
+ * \sa SDL_GetScancodeName()
+ */
+extern DECLSPEC SDL_scancode SDLCALL SDL_GetScancodeFromKey(SDLKey key);
 
 /**
- * \fn const char *SDL_GetKeyName(SDLKey layoutKey)
+ * \fn const char *SDL_GetScancodeName(SDL_scancode scancode)
+ * 
+ * \brief Get a human-readable name for a scancode.
+ *
+ * \return A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it.  If the scancode doesn't have a name, this function returns "".
+ *
+ * \sa SDL_scancode
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_scancode
+                                                        scancode);
+
+/**
+ * \fn const char *SDL_GetKeyName(SDLKey key)
  * 
  * \brief Get a human-readable name for a key.
  *
- * \param layoutKey An SDL layout key code.
- *
- * If what you have is a physical key code, e.g. from the \link SDL_keysym::sym key.keysym.sym \endlink field of the SDL_Event structure, convert it to a layout key code using SDL_GetLayoutKey() first. Doing this ensures that the returned name matches what users see on their keyboards. Calling this function directly on a physical key code (that is not also a layout key code) is possible, but is not recommended except for debugging purposes. The name returned in that case is the name of the \link ::SDLPhysicalKey SDLK_* \endlink constant and is not suitable for display to users.
- *
- * \return A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it. Always non-NULL.
+ * \return A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it.  If the key doesn't have a name, this function returns "".
  *
  * \sa SDLKey
  */
-extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey layoutKey);
+extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);
 
 
 /* Ends C function definitions when using C++ */
--- a/include/SDL_keysym.h	Mon Feb 04 17:25:33 2008 +0000
+++ b/include/SDL_keysym.h	Tue Feb 05 07:19:23 2008 +0000
@@ -28,413 +28,222 @@
 #define _SDL_keysym_h
 
 #include "SDL_stdinc.h"
+#include "SDL_scancode.h"
 
 /**
  * \typedef SDLKey
  *
  * \brief The SDL virtual key representation.
  *
- * Values of this type are used to represent keyboard keys, among other places
- * in the \link SDL_keysym::sym key.keysym.sym \endlink field of the SDL_Event
- * structure.
- *
- * There are two fundamental ways of referring to a key: First, a certain code
- * can stand for a key at a specific physical location on the keyboard,
- * independent of its label or what character it generates. These are the \e
- * physical key codes, comparable to the raw hardware scancodes that a keyboard
- * generates. Second, a code can refer to a key with a specific label,
- * generating a specific character or performing a specific function, which may
- * be located at different places on the keyboard, or not exist at all,
- * depending on what keyboard layout is used. These are \e layout key codes.
- *
- * There is a certain overlap between the sets of physical key codes and layout
- * key codes: \e return, \e tab, \e ctrl etc. are typically independent of the
- * keyboard layout and can be thought of as either a physical or a layout key.
- * Therefore, rather than having separate types with separate sets of constants
- * for physical keys and layout keys, a single type ::SDLKey is used for both
- * sets. The physical key codes (forming a well-known set of a few hundred
- * elements) are enumerated in enum ::SDLPhysicalKey. The set of layout key
- * codes is more diverse: For keys that don't generate characters, the layout
- * key code is equal to the physical key code, i.e. the same SDLK_* constants
- * from enum ::SDLPhysicalKey are used. For character keys, the layout key code
- * is equal to the Unicode code point of the character that is generated when
- * the key is pressed without shift or any other modifiers (for ASCII
- * characters, this can be directly written as a character literal like
- * <tt>'x'</tt>).
- *
- * The \link SDL_keysym::sym key.keysym.sym \endlink field of the SDL_Event
- * structure is always a physical key code. To get the layout key code for the
- * event, run that physical key code through SDL_GetLayoutKey(), which converts
- * it to a layout key code according to the current keyboard layout settings of
- * the OS. In particular, this is what should be done when displaying the name
- * of a key to the user: use
- * <tt>SDL_GetKeyName(SDL_GetLayoutKey(myPhysicalKeyCode))</tt>. Do not use
- * SDL_GetKeyName() directly on a physical key code (except for debugging
- * purposes), as the name returned by that will not correspond to how the key
- * is labeled on the user's keyboard.
- *
- * \par Example:
- * To implement WASD directional keys, it makes sense to use physical key
- * codes, so that the "forward" key will be above the "backward" key even
- * though, for example, it's labeled "Z", not "W", on a French keyboard:
- * \code
- * print("To go forward, press the %s key.", SDL_GetKeyName(SDL_GetLayoutKey(SDLK_W)));
- * ...
- * switch (event.key.keysym.sym) {
- *     case SDLK_W:
- *         forward();
- *         break;
- *     case SDLK_A:
- *         left();
- *         break;
- *     ...
- * }
- * \endcode
- * For keys based on mnemonics like "I for inventory" or "Z for zoom", use
- * layout key codes, so that the key labeled "Z" will zoom, whether it's at the
- * bottom left of the keyboard like on a US layout, or in the upper center like
- * on a German layout (but keep in mind that this forces your users to use a
- * keyboard layout where there \e is an I or Z key):
- * \code
- * print("To open the inventory, press the %s key.", SDL_GetKeyName('i'));
- * ...
- * switch (SDL_GetLayoutKey(event.key.keysym.sym)) {
- *     case 'i':
- *         inventory();
- *         break;
- *     case 'z':
- *         zoom();
- *         break;
- *     ...
- * }
- * \endcode
- * Of course, in a real application, you should not hardcode your key
- * assignments like this, but make them user-configurable.
+ * Values of this type are used to represent keyboard keys using the current
+ * layout of the keyboard.  These values include Unicode values representing
+ * the unmodified character that would be generated by pressing the key, or
+ * an SDLK_* constant for those keys that do not generate characters.
  */
-typedef Uint32 SDLKey;
+typedef Sint32 SDLKey;
+
+#define SDLK_SCANCODE_MASK (1<<30)
+#define SDL_SCANCODE_TO_KEYCODE(X)	(X | SDLK_SCANCODE_MASK)
+
+enum
+{
+    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_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK),
 
-#define SDL_KEY_CAN_BE_PHYSICAL_BIT (1<<24)     /* marks SDLKeys from the "physical" set (some of these are also in the "layout" set) */
-#define SDL_KEY_KEYPAD_BIT (1<<25)      /* marks keypad keys that need [] around their name to distinguish them from the corresponding keyboard keys */
-#define SDL_KEY_LAYOUT_SPECIAL_BIT (1<<26)      /* marks non-physical layout keys that cannot be described by a single character */
+    SDLK_F1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1),
+    SDLK_F2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2),
+    SDLK_F3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F3),
+    SDLK_F4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F4),
+    SDLK_F5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F5),
+    SDLK_F6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F6),
+    SDLK_F7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F7),
+    SDLK_F8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F8),
+    SDLK_F9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F9),
+    SDLK_F10 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F10),
+    SDLK_F11 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F11),
+    SDLK_F12 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F12),
 
-/** Converts an \link ::SDLPhysicalKey SDLK_* \endlink constant to an index into the array obtained from SDL_GetKeyState(). */
-#define SDLK_INDEX(k) ((k) & 0x00FFFFFF)
-
-#define SDL_PHYSICAL_KEY(n) ((n) | SDL_KEY_CAN_BE_PHYSICAL_BIT)
+    SDLK_PRINTSCREEN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRINTSCREEN),
+    SDLK_SCROLLLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SCROLLLOCK),
+    SDLK_PAUSE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAUSE),
+    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_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),
+    SDLK_LEFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LEFT),
+    SDLK_DOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN),
+    SDLK_UP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP),
 
-/**
- * \brief SDL physical key codes.
- *
- * This is the set of physical key codes, i.e. the values of SDL_keysym::sym.
- * Some of them (those for non-character keys) also appear as layout key codes.
- * The constants are typically named after how the key would be labeled on a US
- * keyboard, e.g. SDLK_A or SDLK_LEFTBRACKET refer to the keys used as A and [
- * on a US layout, but used as Q and ^ on a French layout.
- *
- * <em>enum SDLPhysicalKey</em> is not a useful type in its own right - the
- * constants defined here are intended as values of the ::SDLKey type. The only
- * reason for the enum to have a name at all is that otherwise it would be
- * impossible to refer to it in the documentation.
- *
- * \sa SDLKey
- *
- * \par Notes for driver implementors:
- * These constants and their numerical values are based on the USB HID usage
- * tables, version 1.12
- * <http://www.usb.org/developers/devclass_docs/Hut1_12.pdf>, section "10
- * Keyboard/Keypad Page (0x07)". When deciding what code to generate for what
- * key, the following rules can be used as guidelines:
- * - A given key on a given keyboard should produce the same SDLK_* code, no
- * matter what computer it is connected to, what OS runs on that computer, and
- * what the keyboard layout settings in the OS are. For USB keyboards, that
- * should be the code numerically corresponding to the key's USB usage code
- * (with exceptions, see comments for specific constants).
- * - Two keys on two different keyboards are considered "the same key" and
- * should generate the same SDLK_* code if, when connected to the same
- * computer, they are treated equally by the OS. For USB keyboards, that's
- * generally the case when they generate the same USB usage code. Non-USB
- * keyboards can probably be treated like USB keyboards of the same layout, if
- * such exist. If not, and there's no possibility to determine the equivalence
- * relation by transitivity from the above - in particular, on devices like
- * phones or game consoles that don't have PC-style alphabetic keyboards -
- * apply common sense. If none of the predefined codes fit, insert new ones at
- * the end.
- */
-enum SDLPhysicalKey
-{
-    SDLK_FIRST_PHYSICAL = 0, /**< (not a key, just marks the lowest used value in this enum) */
-    SDLK_NONE = SDL_PHYSICAL_KEY(0),
-    SDLK_UNKNOWN = SDL_PHYSICAL_KEY(1), /* Not from the USB spec, but this is a convenient place for it */
+    SDLK_NUMLOCKCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR),
+    SDLK_KP_DIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE),
+    SDLK_KP_MULTIPLY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY),
+    SDLK_KP_MINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS),
+    SDLK_KP_PLUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS),
+    SDLK_KP_ENTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER),
+    SDLK_KP_1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1),
+    SDLK_KP_2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2),
+    SDLK_KP_3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3),
+    SDLK_KP_4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4),
+    SDLK_KP_5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5),
+    SDLK_KP_6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6),
+    SDLK_KP_7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7),
+    SDLK_KP_8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8),
+    SDLK_KP_9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9),
+    SDLK_KP_0 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0),
+    SDLK_KP_PERIOD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD),
 
-    SDLK_A = SDL_PHYSICAL_KEY(4),
-    SDLK_B = SDL_PHYSICAL_KEY(5),
-    SDLK_C = SDL_PHYSICAL_KEY(6),
-    SDLK_D = SDL_PHYSICAL_KEY(7),
-    SDLK_E = SDL_PHYSICAL_KEY(8),
-    SDLK_F = SDL_PHYSICAL_KEY(9),
-    SDLK_G = SDL_PHYSICAL_KEY(10),
-    SDLK_H = SDL_PHYSICAL_KEY(11),
-    SDLK_I = SDL_PHYSICAL_KEY(12),
-    SDLK_J = SDL_PHYSICAL_KEY(13),
-    SDLK_K = SDL_PHYSICAL_KEY(14),
-    SDLK_L = SDL_PHYSICAL_KEY(15),
-    SDLK_M = SDL_PHYSICAL_KEY(16),
-    SDLK_N = SDL_PHYSICAL_KEY(17),
-    SDLK_O = SDL_PHYSICAL_KEY(18),
-    SDLK_P = SDL_PHYSICAL_KEY(19),
-    SDLK_Q = SDL_PHYSICAL_KEY(20),
-    SDLK_R = SDL_PHYSICAL_KEY(21),
-    SDLK_S = SDL_PHYSICAL_KEY(22),
-    SDLK_T = SDL_PHYSICAL_KEY(23),
-    SDLK_U = SDL_PHYSICAL_KEY(24),
-    SDLK_V = SDL_PHYSICAL_KEY(25),
-    SDLK_W = SDL_PHYSICAL_KEY(26),
-    SDLK_X = SDL_PHYSICAL_KEY(27),
-    SDLK_Y = SDL_PHYSICAL_KEY(28),
-    SDLK_Z = SDL_PHYSICAL_KEY(29),
-
-    SDLK_1 = SDL_PHYSICAL_KEY(30),
-    SDLK_2 = SDL_PHYSICAL_KEY(31),
-    SDLK_3 = SDL_PHYSICAL_KEY(32),
-    SDLK_4 = SDL_PHYSICAL_KEY(33),
-    SDLK_5 = SDL_PHYSICAL_KEY(34),
-    SDLK_6 = SDL_PHYSICAL_KEY(35),
-    SDLK_7 = SDL_PHYSICAL_KEY(36),
-    SDLK_8 = SDL_PHYSICAL_KEY(37),
-    SDLK_9 = SDL_PHYSICAL_KEY(38),
-    SDLK_0 = SDL_PHYSICAL_KEY(39),
-
-    SDLK_RETURN = SDL_PHYSICAL_KEY(40),
-    SDLK_ESCAPE = SDL_PHYSICAL_KEY(41),
-    SDLK_BACKSPACE = SDL_PHYSICAL_KEY(42),
-    SDLK_TAB = SDL_PHYSICAL_KEY(43),
-    SDLK_SPACE = SDL_PHYSICAL_KEY(44),
-
-    SDLK_HYPHENMINUS = SDL_PHYSICAL_KEY(45),
-    SDLK_EQUALS = SDL_PHYSICAL_KEY(46),
-    SDLK_LEFTBRACKET = SDL_PHYSICAL_KEY(47),
-    SDLK_RIGHTBRACKET = SDL_PHYSICAL_KEY(48),
-    SDLK_BACKSLASH = SDL_PHYSICAL_KEY(49), /**< Located at the lower left of the return key on ISO keyboards and at the right end of the QWERTY row on ANSI keyboards. Produces REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US layout, REVERSE SOLIDUS and VERTICAL LINE in a UK Mac layout, NUMBER SIGN and TILDE in a UK Windows layout, DOLLAR SIGN and POUND SIGN in a Swiss German layout, NUMBER SIGN and APOSTROPHE in a German layout, GRAVE ACCENT and POUND SIGN in a French Mac layout, and ASTERISK and MICRO SIGN in a French Windows layout. */
-    SDLK_NONUSHASH = SDL_PHYSICAL_KEY(50), /**< ISO USB keyboards actually use this code instead of 49 for the same key, but all OSes I've seen treat the two codes identically. So, as an implementor, unless your keyboard generates both of those codes and your OS treats them differently, you should generate SDLK_BACKSLASH instead of this code. As a user, you should not rely on this code because SDL will never generate it with most (all?) keyboards. */
-    SDLK_SEMICOLON = SDL_PHYSICAL_KEY(51),
-    SDLK_APOSTROPHE = SDL_PHYSICAL_KEY(52),
-    SDLK_GRAVE = SDL_PHYSICAL_KEY(53), /**< Located in the top left corner (on both ANSI and ISO keyboards). Produces GRAVE ACCENT and TILDE in a US Windows layout and in US and UK Mac layouts on ANSI keyboards, GRAVE ACCENT and NOT SIGN in a UK Windows layout, SECTION SIGN and PLUS-MINUS SIGN in US and UK Mac layouts on ISO keyboards, SECTION SIGN and DEGREE SIGN in a Swiss German layout (Mac: only on ISO keyboards), CIRCUMFLEX ACCENT and DEGREE SIGN in a German layout (Mac: only on ISO keyboards), SUPERSCRIPT TWO and TILDE in a French Windows layout, COMMERCIAL AT and NUMBER SIGN in a French Mac layout on ISO keyboards, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French Mac layout on ANSI keyboards. */
-    SDLK_COMMA = SDL_PHYSICAL_KEY(54),
-    SDLK_PERIOD = SDL_PHYSICAL_KEY(55),
-    SDLK_SLASH = SDL_PHYSICAL_KEY(56),
-
-    SDLK_CAPSLOCK = SDL_PHYSICAL_KEY(57),
+    SDLK_APPLICATION = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION),
+    SDLK_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER),
+    SDLK_KP_EQUALS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS),
+    SDLK_F13 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13),
+    SDLK_F14 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14),
+    SDLK_F15 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15),
+    SDLK_F16 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F16),
+    SDLK_F17 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F17),
+    SDLK_F18 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F18),
+    SDLK_F19 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F19),
+    SDLK_F20 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F20),
+    SDLK_F21 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F21),
+    SDLK_F22 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F22),
+    SDLK_F23 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F23),
+    SDLK_F24 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F24),
+    SDLK_EXECUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXECUTE),
+    SDLK_HELP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HELP),
+    SDLK_MENU = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MENU),
+    SDLK_SELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SELECT),
+    SDLK_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_STOP),
+    SDLK_AGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AGAIN),
+    SDLK_UNDO = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UNDO),
+    SDLK_CUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CUT),
+    SDLK_COPY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COPY),
+    SDLK_PASTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PASTE),
+    SDLK_FIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_FIND),
+    SDLK_MUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE),
+    SDLK_VOLUMEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP),
+    SDLK_VOLUMEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN),
+    SDLK_KP_COMMA = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA),
+    SDLK_KP_EQUALSAS400 =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400),
 
-    SDLK_F1 = SDL_PHYSICAL_KEY(58),
-    SDLK_F2 = SDL_PHYSICAL_KEY(59),
-    SDLK_F3 = SDL_PHYSICAL_KEY(60),
-    SDLK_F4 = SDL_PHYSICAL_KEY(61),
-    SDLK_F5 = SDL_PHYSICAL_KEY(62),
-    SDLK_F6 = SDL_PHYSICAL_KEY(63),
-    SDLK_F7 = SDL_PHYSICAL_KEY(64),
-    SDLK_F8 = SDL_PHYSICAL_KEY(65),
-    SDLK_F9 = SDL_PHYSICAL_KEY(66),
-    SDLK_F10 = SDL_PHYSICAL_KEY(67),
-    SDLK_F11 = SDL_PHYSICAL_KEY(68),
-    SDLK_F12 = SDL_PHYSICAL_KEY(69),
-
-    SDLK_PRINTSCREEN = SDL_PHYSICAL_KEY(70),
-    SDLK_SCROLLLOCK = SDL_PHYSICAL_KEY(71),
-    SDLK_PAUSE = SDL_PHYSICAL_KEY(72),
-    SDLK_INSERT = SDL_PHYSICAL_KEY(73), /**< insert on PC, help on some Mac keyboards (but does send code 73, not 117) */
-    SDLK_HOME = SDL_PHYSICAL_KEY(74),
-    SDLK_PAGEUP = SDL_PHYSICAL_KEY(75),
-    SDLK_DELETE = SDL_PHYSICAL_KEY(76),
-    SDLK_END = SDL_PHYSICAL_KEY(77),
-    SDLK_PAGEDOWN = SDL_PHYSICAL_KEY(78),
-    SDLK_RIGHT = SDL_PHYSICAL_KEY(79),
-    SDLK_LEFT = SDL_PHYSICAL_KEY(80),
-    SDLK_DOWN = SDL_PHYSICAL_KEY(81),
-    SDLK_UP = SDL_PHYSICAL_KEY(82),
-
-    SDLK_KP_NUMLOCKCLEAR = SDL_PHYSICAL_KEY(83), /**< num lock on PC, clear on Mac keyboards */
-    SDLK_KP_DIVIDE = SDL_PHYSICAL_KEY(84) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MULTIPLY = SDL_PHYSICAL_KEY(85) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MINUS = SDL_PHYSICAL_KEY(86) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_PLUS = SDL_PHYSICAL_KEY(87) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_ENTER = SDL_PHYSICAL_KEY(88),
-    SDLK_KP_1 = SDL_PHYSICAL_KEY(89) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_2 = SDL_PHYSICAL_KEY(90) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_3 = SDL_PHYSICAL_KEY(91) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_4 = SDL_PHYSICAL_KEY(92) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_5 = SDL_PHYSICAL_KEY(93) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_6 = SDL_PHYSICAL_KEY(94) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_7 = SDL_PHYSICAL_KEY(95) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_8 = SDL_PHYSICAL_KEY(96) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_9 = SDL_PHYSICAL_KEY(97) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_0 = SDL_PHYSICAL_KEY(98) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_PERIOD = SDL_PHYSICAL_KEY(99) | SDL_KEY_KEYPAD_BIT,
-
-    SDLK_NONUSBACKSLASH = SDL_PHYSICAL_KEY(100), /**< This is the additional key that ISO keyboards have over ANSI ones, located between left shift and Y. Produces GRAVE ACCENT and TILDE in a US or UK Mac layout, REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US or UK Windows layout, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French layout. */
-    SDLK_APPLICATION = SDL_PHYSICAL_KEY(101), /**< windows contextual menu, compose */
-    SDLK_POWER = SDL_PHYSICAL_KEY(102), /**< The USB document says this is a status flag, not a physical key - but some Mac keyboards do have a power key. */
-    SDLK_KP_EQUALS = SDL_PHYSICAL_KEY(103) | SDL_KEY_KEYPAD_BIT,
-    SDLK_F13 = SDL_PHYSICAL_KEY(104),
-    SDLK_F14 = SDL_PHYSICAL_KEY(105),
-    SDLK_F15 = SDL_PHYSICAL_KEY(106),
-    SDLK_F16 = SDL_PHYSICAL_KEY(107),
-    SDLK_F17 = SDL_PHYSICAL_KEY(108),
-    SDLK_F18 = SDL_PHYSICAL_KEY(109),
-    SDLK_F19 = SDL_PHYSICAL_KEY(110),
-    SDLK_F20 = SDL_PHYSICAL_KEY(111),
-    SDLK_F21 = SDL_PHYSICAL_KEY(112),
-    SDLK_F22 = SDL_PHYSICAL_KEY(113),
-    SDLK_F23 = SDL_PHYSICAL_KEY(114),
-    SDLK_F24 = SDL_PHYSICAL_KEY(115),
-    SDLK_EXECUTE = SDL_PHYSICAL_KEY(116),
-    SDLK_HELP = SDL_PHYSICAL_KEY(117),
-    SDLK_MENU = SDL_PHYSICAL_KEY(118),
-    SDLK_SELECT = SDL_PHYSICAL_KEY(119),
-    SDLK_STOP = SDL_PHYSICAL_KEY(120),
-    SDLK_AGAIN = SDL_PHYSICAL_KEY(121), /*!< redo */
-    SDLK_UNDO = SDL_PHYSICAL_KEY(122),
-    SDLK_CUT = SDL_PHYSICAL_KEY(123),
-    SDLK_COPY = SDL_PHYSICAL_KEY(124),
-    SDLK_PASTE = SDL_PHYSICAL_KEY(125),
-    SDLK_FIND = SDL_PHYSICAL_KEY(126),
-    SDLK_MUTE = SDL_PHYSICAL_KEY(127),
-    SDLK_VOLUMEUP = SDL_PHYSICAL_KEY(128),
-    SDLK_VOLUMEDOWN = SDL_PHYSICAL_KEY(129),
-/* not sure whether there's a reason to enable these */
-/*     SDLK_LOCKINGCAPSLOCK = SDL_PHYSICAL_KEY(130),  */
-/*     SDLK_LOCKINGNUMLOCK = SDL_PHYSICAL_KEY(131), */
-/*     SDLK_LOCKINGSCROLLLOCK = SDL_PHYSICAL_KEY(132), */
-    SDLK_KP_COMMA = SDL_PHYSICAL_KEY(133) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_EQUALSAS400 = SDL_PHYSICAL_KEY(134) | SDL_KEY_KEYPAD_BIT,
-
-    SDLK_INTERNATIONAL1 = SDL_PHYSICAL_KEY(135), /**< used on Asian keyboards, see footnotes in USB doc */
-    SDLK_INTERNATIONAL2 = SDL_PHYSICAL_KEY(136),
-    SDLK_INTERNATIONAL3 = SDL_PHYSICAL_KEY(137), /**< Yen */
-    SDLK_INTERNATIONAL4 = SDL_PHYSICAL_KEY(138),
-    SDLK_INTERNATIONAL5 = SDL_PHYSICAL_KEY(139),
-    SDLK_INTERNATIONAL6 = SDL_PHYSICAL_KEY(140),
-    SDLK_INTERNATIONAL7 = SDL_PHYSICAL_KEY(141),
-    SDLK_INTERNATIONAL8 = SDL_PHYSICAL_KEY(142),
-    SDLK_INTERNATIONAL9 = SDL_PHYSICAL_KEY(143),
-    SDLK_LANG1 = SDL_PHYSICAL_KEY(144), /**< Hangul/English toggle */
-    SDLK_LANG2 = SDL_PHYSICAL_KEY(145), /**< Hanja conversion */
-    SDLK_LANG3 = SDL_PHYSICAL_KEY(146), /**< Katakana */
-    SDLK_LANG4 = SDL_PHYSICAL_KEY(147), /**< Hiragana */
-    SDLK_LANG5 = SDL_PHYSICAL_KEY(148), /**< Zenkaku/Hankaku */
-    SDLK_LANG6 = SDL_PHYSICAL_KEY(149), /**< reserved */
-    SDLK_LANG7 = SDL_PHYSICAL_KEY(150), /**< reserved */
-    SDLK_LANG8 = SDL_PHYSICAL_KEY(151), /**< reserved */
-    SDLK_LANG9 = SDL_PHYSICAL_KEY(152), /**< reserved */
+    SDLK_ALTERASE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE),
+    SDLK_SYSREQ = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ),
+    SDLK_CANCEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL),
+    SDLK_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEAR),
+    SDLK_PRIOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRIOR),
+    SDLK_RETURN2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN2),
+    SDLK_SEPARATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SEPARATOR),
+    SDLK_OUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OUT),
+    SDLK_OPER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OPER),
+    SDLK_CLEARAGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEARAGAIN),
+    SDLK_CRSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CRSEL),
+    SDLK_EXSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXSEL),
 
-    SDLK_ALTERASE = SDL_PHYSICAL_KEY(153), /**< Erase-Eaze */
-    SDLK_SYSREQ = SDL_PHYSICAL_KEY(154),
-    SDLK_CANCEL = SDL_PHYSICAL_KEY(155),
-    SDLK_CLEAR = SDL_PHYSICAL_KEY(156),
-    SDLK_PRIOR = SDL_PHYSICAL_KEY(157),
-    SDLK_RETURN2 = SDL_PHYSICAL_KEY(158),
-    SDLK_SEPARATOR = SDL_PHYSICAL_KEY(159),
-    SDLK_OUT = SDL_PHYSICAL_KEY(160),
-    SDLK_OPER = SDL_PHYSICAL_KEY(161),
-    SDLK_CLEARAGAIN = SDL_PHYSICAL_KEY(162),
-    SDLK_CRSELPROPS = SDL_PHYSICAL_KEY(163),
-    SDLK_EXSEL = SDL_PHYSICAL_KEY(164),
+    SDLK_KP_00 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_00),
+    SDLK_KP_000 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_000),
+    SDLK_THOUSANDSSEPARATOR =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_THOUSANDSSEPARATOR),
+    SDLK_DECIMALSEPARATOR =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR),
+    SDLK_CURRENCYUNIT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT),
+    SDLK_CURRENCYSUBUNIT =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT),
+    SDLK_KP_LEFTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN),
+    SDLK_KP_RIGHTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN),
+    SDLK_KP_LEFTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE),
+    SDLK_KP_RIGHTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE),
+    SDLK_KP_TAB = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB),
+    SDLK_KP_BACKSPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE),
+    SDLK_KP_A = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A),
+    SDLK_KP_B = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B),
+    SDLK_KP_C = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C),
+    SDLK_KP_D = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D),
+    SDLK_KP_E = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E),
+    SDLK_KP_F = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F),
+    SDLK_KP_XOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR),
+    SDLK_KP_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER),
+    SDLK_KP_PERCENT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT),
+    SDLK_KP_LESS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS),
+    SDLK_KP_GREATER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER),
+    SDLK_KP_AMPERSAND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND),
+    SDLK_KP_DBLAMPERSAND =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND),
+    SDLK_KP_VERTICALBAR =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR),
+    SDLK_KP_DBLVERTICALBAR =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR),
+    SDLK_KP_COLON = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON),
+    SDLK_KP_HASH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH),
+    SDLK_KP_SPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE),
+    SDLK_KP_AT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT),
+    SDLK_KP_EXCLAM = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM),
+    SDLK_KP_MEMSTORE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE),
+    SDLK_KP_MEMRECALL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL),
+    SDLK_KP_MEMCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR),
+    SDLK_KP_MEMADD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD),
+    SDLK_KP_MEMSUBTRACT =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT),
+    SDLK_KP_MEMMULTIPLY =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY),
+    SDLK_KP_MEMDIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE),
+    SDLK_KP_PLUSMINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS),
+    SDLK_KP_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR),
+    SDLK_KP_CLEARENTRY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY),
+    SDLK_KP_BINARY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY),
+    SDLK_KP_OCTAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_OCTAL),
+    SDLK_KP_DECIMAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DECIMAL),
+    SDLK_KP_HEXADECIMAL =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HEXADECIMAL),
 
-    SDLK_KP_00 = SDL_PHYSICAL_KEY(176) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_000 = SDL_PHYSICAL_KEY(177) | SDL_KEY_KEYPAD_BIT,
-    SDLK_THOUSANDSSEPARATOR = SDL_PHYSICAL_KEY(178),
-    SDLK_DECIMALSEPARATOR = SDL_PHYSICAL_KEY(179),
-    SDLK_CURRENCYUNIT = SDL_PHYSICAL_KEY(180),
-    SDLK_CURRENCYSUBUNIT = SDL_PHYSICAL_KEY(181),
-    SDLK_KP_LEFTPAREN = SDL_PHYSICAL_KEY(182) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_RIGHTPAREN = SDL_PHYSICAL_KEY(183) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_LEFTBRACE = SDL_PHYSICAL_KEY(184) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_RIGHTBRACE = SDL_PHYSICAL_KEY(185) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_TAB = SDL_PHYSICAL_KEY(186) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_BACKSPACE = SDL_PHYSICAL_KEY(187) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_A = SDL_PHYSICAL_KEY(188) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_B = SDL_PHYSICAL_KEY(189) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_C = SDL_PHYSICAL_KEY(190) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_D = SDL_PHYSICAL_KEY(191) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_E = SDL_PHYSICAL_KEY(192) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_F = SDL_PHYSICAL_KEY(193) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_XOR = SDL_PHYSICAL_KEY(194) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_POWER = SDL_PHYSICAL_KEY(195) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_PERCENT = SDL_PHYSICAL_KEY(196) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_LESS = SDL_PHYSICAL_KEY(197) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_GREATER = SDL_PHYSICAL_KEY(198) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_AMPERSAND = SDL_PHYSICAL_KEY(199) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_DBLAMPERSAND = SDL_PHYSICAL_KEY(200) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_VERTICALBAR = SDL_PHYSICAL_KEY(201) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_DBLVERTICALBAR = SDL_PHYSICAL_KEY(202) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_COLON = SDL_PHYSICAL_KEY(203) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_HASH = SDL_PHYSICAL_KEY(204) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_SPACE = SDL_PHYSICAL_KEY(205) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_AT = SDL_PHYSICAL_KEY(206) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_EXCLAM = SDL_PHYSICAL_KEY(207) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MEMSTORE = SDL_PHYSICAL_KEY(208) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MEMRECALL = SDL_PHYSICAL_KEY(209) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MEMCLEAR = SDL_PHYSICAL_KEY(210) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MEMADD = SDL_PHYSICAL_KEY(211) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MEMSUBTRACT = SDL_PHYSICAL_KEY(212) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MEMMULTIPLY = SDL_PHYSICAL_KEY(213) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_MEMDIVIDE = SDL_PHYSICAL_KEY(214) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_PLUSMINUS = SDL_PHYSICAL_KEY(215) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_CLEAR = SDL_PHYSICAL_KEY(216) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_CLEARENTRY = SDL_PHYSICAL_KEY(217) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_BINARY = SDL_PHYSICAL_KEY(218) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_OCTAL = SDL_PHYSICAL_KEY(219) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_DECIMAL = SDL_PHYSICAL_KEY(220) | SDL_KEY_KEYPAD_BIT,
-    SDLK_KP_HEXADECIMAL = SDL_PHYSICAL_KEY(221) | SDL_KEY_KEYPAD_BIT,
+    SDLK_LCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LCTRL),
+    SDLK_LSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT),
+    SDLK_LALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LALT),
+    SDLK_LGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LGUI),
+    SDLK_RCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RCTRL),
+    SDLK_RSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RSHIFT),
+    SDLK_RALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RALT),
+    SDLK_RGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RGUI),
+
+    SDLK_MODE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MODE),
 
-    SDLK_LCTRL = SDL_PHYSICAL_KEY(224),
-    SDLK_LSHIFT = SDL_PHYSICAL_KEY(225),
-    SDLK_LALT = SDL_PHYSICAL_KEY(226), /**< alt, option */
-    SDLK_LMETA = SDL_PHYSICAL_KEY(227), /**< windows, command (apple), meta */
-    SDLK_RCTRL = SDL_PHYSICAL_KEY(228),
-    SDLK_RSHIFT = SDL_PHYSICAL_KEY(229),
-    SDLK_RALT = SDL_PHYSICAL_KEY(230), /**< alt gr, option */
-    SDLK_RMETA = SDL_PHYSICAL_KEY(231), /**< windows, command (apple), meta */
-
-    /* Everything below here is not from the USB spec */
-
-    SDLK_MODE = SDL_PHYSICAL_KEY(232),  /* I'm not sure if this is really not covered by any of the above, but since there's a special KMOD_MODE for it I'm adding it here */
-
-    SDLK_BRIGHTNESSDOWN = SDL_PHYSICAL_KEY(236),
-    SDLK_BRIGHTNESSUP = SDL_PHYSICAL_KEY(237),
-    SDLK_DISPLAYSWITCH = SDL_PHYSICAL_KEY(238), /**< display mirroring/dual display switch, video mode switch */
-    SDLK_KBDILLUMTOGGLE = SDL_PHYSICAL_KEY(239),
-    SDLK_KBDILLUMDOWN = SDL_PHYSICAL_KEY(240),
-    SDLK_KBDILLUMUP = SDL_PHYSICAL_KEY(241),
-    SDLK_EJECT = SDL_PHYSICAL_KEY(242),
-    SDLK_SLEEP = SDL_PHYSICAL_KEY(243),
+    SDLK_AUDIONEXT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIONEXT),
+    SDLK_AUDIOPREV = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPREV),
+    SDLK_AUDIOSTOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOSTOP),
+    SDLK_AUDIOPLAY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPLAY),
+    SDLK_AUDIOMUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOMUTE),
+    SDLK_MEDIASELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIASELECT),
+    SDLK_MAIL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MAIL),
+    SDLK_CALCULATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CALCULATOR),
+    SDLK_COMPUTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COMPUTER),
+    SDLK_AC_SEARCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SEARCH),
+    SDLK_AC_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_HOME),
+    SDLK_AC_BACK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BACK),
+    SDLK_AC_FORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_FORWARD),
+    SDLK_AC_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_STOP),
+    SDLK_AC_REFRESH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_REFRESH),
+    SDLK_AC_BOOKMARKS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BOOKMARKS),
 
-    /* Some of the more common and more standardized "multimedia"/"internet" keyboard keys */
-    SDLK_AUDIOPLAY = SDL_PHYSICAL_KEY(244),
-    SDLK_AUDIOSTOP = SDL_PHYSICAL_KEY(245),
-    SDLK_AUDIOPREV = SDL_PHYSICAL_KEY(246),
-    SDLK_AUDIONEXT = SDL_PHYSICAL_KEY(247),
-    SDLK_CALC = SDL_PHYSICAL_KEY(248),
-    SDLK_WWW = SDL_PHYSICAL_KEY(249),
-    SDLK_EMAIL = SDL_PHYSICAL_KEY(250),
-    SDLK_MEDIA = SDL_PHYSICAL_KEY(251),
-    SDLK_COMPUTER = SDL_PHYSICAL_KEY(252),
-    SDLK_SEARCH = SDL_PHYSICAL_KEY(253),
-    SDLK_BOOKMARKS = SDL_PHYSICAL_KEY(254),
-    SDLK_BROWSERBACK = SDL_PHYSICAL_KEY(255),
-    SDLK_BROWSERFORWARD = SDL_PHYSICAL_KEY(256),
-    SDLK_BROWSERRELOAD = SDL_PHYSICAL_KEY(257),
-    SDLK_BROWSERSTOP = SDL_PHYSICAL_KEY(258),
-
-    /* Add any other keys here */
-
-    SDLK_LAST_PHYSICAL /**< (not a key, just marks the highest used value in this enum) */
+    SDLK_BRIGHTNESSDOWN =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSDOWN),
+    SDLK_BRIGHTNESSUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSUP),
+    SDLK_DISPLAYSWITCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DISPLAYSWITCH),
+    SDLK_KBDILLUMTOGGLE =
+        SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMTOGGLE),
+    SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
+    SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
+    SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
+    SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP),
 };
 
-#define SDLK_FIRST SDLK_INDEX(SDLK_FIRST_PHYSICAL)
-#define SDLK_LAST SDLK_INDEX(SDLK_LAST_PHYSICAL)
-
-
-
 /**
  * \enum SDLMod
  *
@@ -449,8 +258,8 @@
     KMOD_RCTRL = 0x0080,
     KMOD_LALT = 0x0100,
     KMOD_RALT = 0x0200,
-    KMOD_LMETA = 0x0400,
-    KMOD_RMETA = 0x0800,
+    KMOD_LGUI = 0x0400,
+    KMOD_RGUI = 0x0800,
     KMOD_NUM = 0x1000,
     KMOD_CAPS = 0x2000,
     KMOD_MODE = 0x4000,
@@ -460,6 +269,8 @@
 #define KMOD_CTRL	(KMOD_LCTRL|KMOD_RCTRL)
 #define KMOD_SHIFT	(KMOD_LSHIFT|KMOD_RSHIFT)
 #define KMOD_ALT	(KMOD_LALT|KMOD_RALT)
-#define KMOD_META	(KMOD_LMETA|KMOD_RMETA)
+#define KMOD_GUI	(KMOD_LGUI|KMOD_RGUI)
 
 #endif /* _SDL_keysym_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/SDL_scancode.h	Tue Feb 05 07:19:23 2008 +0000
@@ -0,0 +1,318 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2006 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+/**
+ * \file SDL_scancode.h
+ */
+
+#ifndef _SDL_scancode_h
+#define _SDL_scancode_h
+
+#include "SDL_stdinc.h"
+
+/**
+ * \enum SDL_scancode
+ *
+ * \brief The SDL keyboard scancode representation.
+ *
+ * Values of this type are used to represent keyboard keys, among other places
+ * in the \link SDL_keysym::scancode key.keysym.scancode \endlink field of the
+ * SDL_Event structure.
+ *
+ * The values in this enumeration are based on the USB usage page standard:
+ * http://www.usb.org/developers/devclass_docs/Hut1_12.pdf
+ */
+typedef enum
+{
+    SDL_SCANCODE_UNKNOWN = 0,
+
+    /* These values are from usage page 0x07 (USB keyboard page) */
+
+    SDL_SCANCODE_A = 4,
+    SDL_SCANCODE_B = 5,
+    SDL_SCANCODE_C = 6,
+    SDL_SCANCODE_D = 7,
+    SDL_SCANCODE_E = 8,
+    SDL_SCANCODE_F = 9,
+    SDL_SCANCODE_G = 10,
+    SDL_SCANCODE_H = 11,
+    SDL_SCANCODE_I = 12,
+    SDL_SCANCODE_J = 13,
+    SDL_SCANCODE_K = 14,
+    SDL_SCANCODE_L = 15,
+    SDL_SCANCODE_M = 16,
+    SDL_SCANCODE_N = 17,
+    SDL_SCANCODE_O = 18,
+    SDL_SCANCODE_P = 19,
+    SDL_SCANCODE_Q = 20,
+    SDL_SCANCODE_R = 21,
+    SDL_SCANCODE_S = 22,
+    SDL_SCANCODE_T = 23,
+    SDL_SCANCODE_U = 24,
+    SDL_SCANCODE_V = 25,
+    SDL_SCANCODE_W = 26,
+    SDL_SCANCODE_X = 27,
+    SDL_SCANCODE_Y = 28,
+    SDL_SCANCODE_Z = 29,
+
+    SDL_SCANCODE_1 = 30,
+    SDL_SCANCODE_2 = 31,
+    SDL_SCANCODE_3 = 32,
+    SDL_SCANCODE_4 = 33,
+    SDL_SCANCODE_5 = 34,
+    SDL_SCANCODE_6 = 35,
+    SDL_SCANCODE_7 = 36,
+    SDL_SCANCODE_8 = 37,
+    SDL_SCANCODE_9 = 38,
+    SDL_SCANCODE_0 = 39,
+
+    SDL_SCANCODE_RETURN = 40,
+    SDL_SCANCODE_ESCAPE = 41,
+    SDL_SCANCODE_BACKSPACE = 42,
+    SDL_SCANCODE_TAB = 43,
+    SDL_SCANCODE_SPACE = 44,
+
+    SDL_SCANCODE_HYPHENMINUS = 45,
+    SDL_SCANCODE_EQUALS = 46,
+    SDL_SCANCODE_LEFTBRACKET = 47,
+    SDL_SCANCODE_RIGHTBRACKET = 48,
+    SDL_SCANCODE_BACKSLASH = 49, /**< Located at the lower left of the return key on ISO keyboards and at the right end of the QWERTY row on ANSI keyboards. Produces REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US layout, REVERSE SOLIDUS and VERTICAL LINE in a UK Mac layout, NUMBER SIGN and TILDE in a UK Windows layout, DOLLAR SIGN and POUND SIGN in a Swiss German layout, NUMBER SIGN and APOSTROPHE in a German layout, GRAVE ACCENT and POUND SIGN in a French Mac layout, and ASTERISK and MICRO SIGN in a French Windows layout. */
+    SDL_SCANCODE_NONUSHASH = 50, /**< ISO USB keyboards actually use this code instead of 49 for the same key, but all OSes I've seen treat the two codes identically. So, as an implementor, unless your keyboard generates both of those codes and your OS treats them differently, you should generate SDL_SCANCODE_BACKSLASH instead of this code. As a user, you should not rely on this code because SDL will never generate it with most (all?) keyboards. */
+    SDL_SCANCODE_SEMICOLON = 51,
+    SDL_SCANCODE_APOSTROPHE = 52,
+    SDL_SCANCODE_GRAVE = 53, /**< Located in the top left corner (on both ANSI and ISO keyboards). Produces GRAVE ACCENT and TILDE in a US Windows layout and in US and UK Mac layouts on ANSI keyboards, GRAVE ACCENT and NOT SIGN in a UK Windows layout, SECTION SIGN and PLUS-MINUS SIGN in US and UK Mac layouts on ISO keyboards, SECTION SIGN and DEGREE SIGN in a Swiss German layout (Mac: only on ISO keyboards), CIRCUMFLEX ACCENT and DEGREE SIGN in a German layout (Mac: only on ISO keyboards), SUPERSCRIPT TWO and TILDE in a French Windows layout, COMMERCIAL AT and NUMBER SIGN in a French Mac layout on ISO keyboards, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French Mac layout on ANSI keyboards. */
+    SDL_SCANCODE_COMMA = 54,
+    SDL_SCANCODE_PERIOD = 55,
+    SDL_SCANCODE_SLASH = 56,
+
+    SDL_SCANCODE_CAPSLOCK = 57,
+
+    SDL_SCANCODE_F1 = 58,
+    SDL_SCANCODE_F2 = 59,
+    SDL_SCANCODE_F3 = 60,
+    SDL_SCANCODE_F4 = 61,
+    SDL_SCANCODE_F5 = 62,
+    SDL_SCANCODE_F6 = 63,
+    SDL_SCANCODE_F7 = 64,
+    SDL_SCANCODE_F8 = 65,
+    SDL_SCANCODE_F9 = 66,
+    SDL_SCANCODE_F10 = 67,
+    SDL_SCANCODE_F11 = 68,
+    SDL_SCANCODE_F12 = 69,
+
+    SDL_SCANCODE_PRINTSCREEN = 70,
+    SDL_SCANCODE_SCROLLLOCK = 71,
+    SDL_SCANCODE_PAUSE = 72,
+    SDL_SCANCODE_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but does send code 73, not 117) */
+    SDL_SCANCODE_HOME = 74,
+    SDL_SCANCODE_PAGEUP = 75,
+    SDL_SCANCODE_DELETE = 76,
+    SDL_SCANCODE_END = 77,
+    SDL_SCANCODE_PAGEDOWN = 78,
+    SDL_SCANCODE_RIGHT = 79,
+    SDL_SCANCODE_LEFT = 80,
+    SDL_SCANCODE_DOWN = 81,
+    SDL_SCANCODE_UP = 82,
+
+    SDL_SCANCODE_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards */
+    SDL_SCANCODE_KP_DIVIDE = 84,
+    SDL_SCANCODE_KP_MULTIPLY = 85,
+    SDL_SCANCODE_KP_MINUS = 86,
+    SDL_SCANCODE_KP_PLUS = 87,
+    SDL_SCANCODE_KP_ENTER = 88,
+    SDL_SCANCODE_KP_1 = 89,
+    SDL_SCANCODE_KP_2 = 90,
+    SDL_SCANCODE_KP_3 = 91,
+    SDL_SCANCODE_KP_4 = 92,
+    SDL_SCANCODE_KP_5 = 93,
+    SDL_SCANCODE_KP_6 = 94,
+    SDL_SCANCODE_KP_7 = 95,
+    SDL_SCANCODE_KP_8 = 96,
+    SDL_SCANCODE_KP_9 = 97,
+    SDL_SCANCODE_KP_0 = 98,
+    SDL_SCANCODE_KP_PERIOD = 99,
+
+    SDL_SCANCODE_NONUSBACKSLASH = 100, /**< This is the additional key that ISO keyboards have over ANSI ones, located between left shift and Y. Produces GRAVE ACCENT and TILDE in a US or UK Mac layout, REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US or UK Windows layout, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French layout. */
+    SDL_SCANCODE_APPLICATION = 101, /**< windows contextual menu, compose */
+    SDL_SCANCODE_POWER = 102, /**< The USB document says this is a status flag, not a physical key - but some Mac keyboards do have a power key. */
+    SDL_SCANCODE_KP_EQUALS = 103,
+    SDL_SCANCODE_F13 = 104,
+    SDL_SCANCODE_F14 = 105,
+    SDL_SCANCODE_F15 = 106,
+    SDL_SCANCODE_F16 = 107,
+    SDL_SCANCODE_F17 = 108,
+    SDL_SCANCODE_F18 = 109,
+    SDL_SCANCODE_F19 = 110,
+    SDL_SCANCODE_F20 = 111,
+    SDL_SCANCODE_F21 = 112,
+    SDL_SCANCODE_F22 = 113,
+    SDL_SCANCODE_F23 = 114,
+    SDL_SCANCODE_F24 = 115,
+    SDL_SCANCODE_EXECUTE = 116,
+    SDL_SCANCODE_HELP = 117,
+    SDL_SCANCODE_MENU = 118,
+    SDL_SCANCODE_SELECT = 119,
+    SDL_SCANCODE_STOP = 120,
+    SDL_SCANCODE_AGAIN = 121,   /*!< redo */
+    SDL_SCANCODE_UNDO = 122,
+    SDL_SCANCODE_CUT = 123,
+    SDL_SCANCODE_COPY = 124,
+    SDL_SCANCODE_PASTE = 125,
+    SDL_SCANCODE_FIND = 126,
+    SDL_SCANCODE_MUTE = 127,
+    SDL_SCANCODE_VOLUMEUP = 128,
+    SDL_SCANCODE_VOLUMEDOWN = 129,
+/* not sure whether there's a reason to enable these */
+/*     SDL_SCANCODE_LOCKINGCAPSLOCK = 130,  */
+/*     SDL_SCANCODE_LOCKINGNUMLOCK = 131, */
+/*     SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */
+    SDL_SCANCODE_KP_COMMA = 133,
+    SDL_SCANCODE_KP_EQUALSAS400 = 134,
+
+    SDL_SCANCODE_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see footnotes in USB doc */
+    SDL_SCANCODE_INTERNATIONAL2 = 136,
+    SDL_SCANCODE_INTERNATIONAL3 = 137, /**< Yen */
+    SDL_SCANCODE_INTERNATIONAL4 = 138,
+    SDL_SCANCODE_INTERNATIONAL5 = 139,
+    SDL_SCANCODE_INTERNATIONAL6 = 140,
+    SDL_SCANCODE_INTERNATIONAL7 = 141,
+    SDL_SCANCODE_INTERNATIONAL8 = 142,
+    SDL_SCANCODE_INTERNATIONAL9 = 143,
+    SDL_SCANCODE_LANG1 = 144, /**< Hangul/English toggle */
+    SDL_SCANCODE_LANG2 = 145, /**< Hanja conversion */
+    SDL_SCANCODE_LANG3 = 146, /**< Katakana */
+    SDL_SCANCODE_LANG4 = 147, /**< Hiragana */
+    SDL_SCANCODE_LANG5 = 148, /**< Zenkaku/Hankaku */
+    SDL_SCANCODE_LANG6 = 149, /**< reserved */
+    SDL_SCANCODE_LANG7 = 150, /**< reserved */
+    SDL_SCANCODE_LANG8 = 151, /**< reserved */
+    SDL_SCANCODE_LANG9 = 152, /**< reserved */
+
+    SDL_SCANCODE_ALTERASE = 153, /**< Erase-Eaze */
+    SDL_SCANCODE_SYSREQ = 154,
+    SDL_SCANCODE_CANCEL = 155,
+    SDL_SCANCODE_CLEAR = 156,
+    SDL_SCANCODE_PRIOR = 157,
+    SDL_SCANCODE_RETURN2 = 158,
+    SDL_SCANCODE_SEPARATOR = 159,
+    SDL_SCANCODE_OUT = 160,
+    SDL_SCANCODE_OPER = 161,
+    SDL_SCANCODE_CLEARAGAIN = 162,
+    SDL_SCANCODE_CRSEL = 163,
+    SDL_SCANCODE_EXSEL = 164,
+
+    SDL_SCANCODE_KP_00 = 176,
+    SDL_SCANCODE_KP_000 = 177,
+    SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
+    SDL_SCANCODE_DECIMALSEPARATOR = 179,
+    SDL_SCANCODE_CURRENCYUNIT = 180,
+    SDL_SCANCODE_CURRENCYSUBUNIT = 181,
+    SDL_SCANCODE_KP_LEFTPAREN = 182,
+    SDL_SCANCODE_KP_RIGHTPAREN = 183,
+    SDL_SCANCODE_KP_LEFTBRACE = 184,
+    SDL_SCANCODE_KP_RIGHTBRACE = 185,
+    SDL_SCANCODE_KP_TAB = 186,
+    SDL_SCANCODE_KP_BACKSPACE = 187,
+    SDL_SCANCODE_KP_A = 188,
+    SDL_SCANCODE_KP_B = 189,
+    SDL_SCANCODE_KP_C = 190,
+    SDL_SCANCODE_KP_D = 191,
+    SDL_SCANCODE_KP_E = 192,
+    SDL_SCANCODE_KP_F = 193,
+    SDL_SCANCODE_KP_XOR = 194,
+    SDL_SCANCODE_KP_POWER = 195,
+    SDL_SCANCODE_KP_PERCENT = 196,
+    SDL_SCANCODE_KP_LESS = 197,
+    SDL_SCANCODE_KP_GREATER = 198,
+    SDL_SCANCODE_KP_AMPERSAND = 199,
+    SDL_SCANCODE_KP_DBLAMPERSAND = 200,
+    SDL_SCANCODE_KP_VERTICALBAR = 201,
+    SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
+    SDL_SCANCODE_KP_COLON = 203,
+    SDL_SCANCODE_KP_HASH = 204,
+    SDL_SCANCODE_KP_SPACE = 205,
+    SDL_SCANCODE_KP_AT = 206,
+    SDL_SCANCODE_KP_EXCLAM = 207,
+    SDL_SCANCODE_KP_MEMSTORE = 208,
+    SDL_SCANCODE_KP_MEMRECALL = 209,
+    SDL_SCANCODE_KP_MEMCLEAR = 210,
+    SDL_SCANCODE_KP_MEMADD = 211,
+    SDL_SCANCODE_KP_MEMSUBTRACT = 212,
+    SDL_SCANCODE_KP_MEMMULTIPLY = 213,
+    SDL_SCANCODE_KP_MEMDIVIDE = 214,
+    SDL_SCANCODE_KP_PLUSMINUS = 215,
+    SDL_SCANCODE_KP_CLEAR = 216,
+    SDL_SCANCODE_KP_CLEARENTRY = 217,
+    SDL_SCANCODE_KP_BINARY = 218,
+    SDL_SCANCODE_KP_OCTAL = 219,
+    SDL_SCANCODE_KP_DECIMAL = 220,
+    SDL_SCANCODE_KP_HEXADECIMAL = 221,
+
+    SDL_SCANCODE_LCTRL = 224,
+    SDL_SCANCODE_LSHIFT = 225,
+    SDL_SCANCODE_LALT = 226, /**< alt, option */
+    SDL_SCANCODE_LGUI = 227, /**< windows, command (apple), meta */
+    SDL_SCANCODE_RCTRL = 228,
+    SDL_SCANCODE_RSHIFT = 229,
+    SDL_SCANCODE_RALT = 230, /**< alt gr, option */
+    SDL_SCANCODE_RGUI = 231, /**< windows, command (apple), meta */
+
+    SDL_SCANCODE_MODE = 257,    /* I'm not sure if this is really not covered by any of the above, but since there's a special KMOD_MODE for it I'm adding it here */
+
+    /* These values are mapped from usage page 0x0C (USB consumer page) */
+
+    SDL_SCANCODE_AUDIONEXT = 258,
+    SDL_SCANCODE_AUDIOPREV = 259,
+    SDL_SCANCODE_AUDIOSTOP = 260,
+    SDL_SCANCODE_AUDIOPLAY = 261,
+    SDL_SCANCODE_AUDIOMUTE = 262,
+    SDL_SCANCODE_MEDIASELECT = 263,
+    SDL_SCANCODE_MAIL = 264,
+    SDL_SCANCODE_CALCULATOR = 265,
+    SDL_SCANCODE_COMPUTER = 266,
+    SDL_SCANCODE_AC_SEARCH = 267,
+    SDL_SCANCODE_AC_HOME = 268,
+    SDL_SCANCODE_AC_BACK = 269,
+    SDL_SCANCODE_AC_FORWARD = 270,
+    SDL_SCANCODE_AC_STOP = 271,
+    SDL_SCANCODE_AC_REFRESH = 272,
+    SDL_SCANCODE_AC_BOOKMARKS = 273,
+
+    /* These are values that Christian Walther added (for mac keyboard?) */
+
+    SDL_SCANCODE_BRIGHTNESSDOWN = 274,
+    SDL_SCANCODE_BRIGHTNESSUP = 275,
+    SDL_SCANCODE_DISPLAYSWITCH = 276, /**< display mirroring/dual display switch, video mode switch */
+    SDL_SCANCODE_KBDILLUMTOGGLE = 277,
+    SDL_SCANCODE_KBDILLUMDOWN = 278,
+    SDL_SCANCODE_KBDILLUMUP = 279,
+    SDL_SCANCODE_EJECT = 280,
+    SDL_SCANCODE_SLEEP = 281,
+
+    /* Add any other keys here */
+
+    SDL_NUM_SCANCODES = 512 /**< (not a key, just marks the number of scancodes for array bounds) */
+} SDL_scancode;
+
+#endif /* _SDL_scancode_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- a/src/SDL_compat.c	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/SDL_compat.c	Tue Feb 05 07:19:23 2008 +0000
@@ -1531,4 +1531,10 @@
     }
 }
 
+int
+SDL_EnableUNICODE(int enable)
+{
+    return SDL_EventState(SDL_TEXTINPUT, enable);
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/events/SDL_keyboard.c	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/events/SDL_keyboard.c	Tue Feb 05 07:19:23 2008 +0000
@@ -27,18 +27,475 @@
 #include "SDL_events.h"
 #include "SDL_events_c.h"
 #include "SDL_sysevents.h"
-#include "SDL_keynames.h"
 
 
 /* Global keyboard information */
-int SDL_TranslateUNICODE = 0;
 static int SDL_num_keyboards;
 static int SDL_current_keyboard;
 static SDL_Keyboard **SDL_keyboards;
 
+static SDLKey SDL_default_keymap[SDL_NUM_SCANCODES] = {
+    0, 0, 0, 0,
+    'a',
+    'b',
+    'c',
+    'd',
+    'e',
+    'f',
+    'g',
+    'h',
+    'i',
+    'j',
+    'k',
+    'l',
+    'm',
+    'n',
+    'o',
+    'p',
+    'q',
+    'r',
+    's',
+    't',
+    'u',
+    'v',
+    'w',
+    'x',
+    'y',
+    'z',
+    '1',
+    '2',
+    '3',
+    '4',
+    '5',
+    '6',
+    '7',
+    '8',
+    '9',
+    '0',
+    SDLK_RETURN,
+    SDLK_ESCAPE,
+    SDLK_BACKSPACE,
+    SDLK_TAB,
+    SDLK_SPACE,
+    '-',
+    '=',
+    '[',
+    ']',
+    '\\',
+    '#',
+    ';',
+    '\'',
+    '`',
+    ',',
+    '.',
+    '/',
+    SDLK_CAPSLOCK,
+    SDLK_F1,
+    SDLK_F2,
+    SDLK_F3,
+    SDLK_F4,
+    SDLK_F5,
+    SDLK_F6,
+    SDLK_F7,
+    SDLK_F8,
+    SDLK_F9,
+    SDLK_F10,
+    SDLK_F11,
+    SDLK_F12,
+    SDLK_PRINTSCREEN,
+    SDLK_SCROLLLOCK,
+    SDLK_PAUSE,
+    SDLK_INSERT,
+    SDLK_HOME,
+    SDLK_PAGEUP,
+    SDLK_DELETE,
+    SDLK_END,
+    SDLK_PAGEDOWN,
+    SDLK_RIGHT,
+    SDLK_LEFT,
+    SDLK_DOWN,
+    SDLK_UP,
+    SDLK_NUMLOCKCLEAR,
+    SDLK_KP_DIVIDE,
+    SDLK_KP_MULTIPLY,
+    SDLK_KP_MINUS,
+    SDLK_KP_PLUS,
+    SDLK_KP_ENTER,
+    SDLK_KP_1,
+    SDLK_KP_2,
+    SDLK_KP_3,
+    SDLK_KP_4,
+    SDLK_KP_5,
+    SDLK_KP_6,
+    SDLK_KP_7,
+    SDLK_KP_8,
+    SDLK_KP_9,
+    SDLK_KP_0,
+    SDLK_KP_PERIOD,
+    0,
+    SDLK_APPLICATION,
+    SDLK_POWER,
+    SDLK_KP_EQUALS,
+    SDLK_F13,
+    SDLK_F14,
+    SDLK_F15,
+    SDLK_F16,
+    SDLK_F17,
+    SDLK_F18,
+    SDLK_F19,
+    SDLK_F20,
+    SDLK_F21,
+    SDLK_F22,
+    SDLK_F23,
+    SDLK_F24,
+    SDLK_EXECUTE,
+    SDLK_HELP,
+    SDLK_MENU,
+    SDLK_SELECT,
+    SDLK_STOP,
+    SDLK_AGAIN,
+    SDLK_UNDO,
+    SDLK_CUT,
+    SDLK_COPY,
+    SDLK_PASTE,
+    SDLK_FIND,
+    SDLK_MUTE,
+    SDLK_VOLUMEUP,
+    SDLK_VOLUMEDOWN,
+    0, 0, 0,
+    SDLK_KP_COMMA,
+    SDLK_KP_EQUALSAS400,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    SDLK_ALTERASE,
+    SDLK_SYSREQ,
+    SDLK_CANCEL,
+    SDLK_CLEAR,
+    SDLK_PRIOR,
+    SDLK_RETURN2,
+    SDLK_SEPARATOR,
+    SDLK_OUT,
+    SDLK_OPER,
+    SDLK_CLEARAGAIN,
+    SDLK_CRSEL,
+    SDLK_EXSEL,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    SDLK_KP_00,
+    SDLK_KP_000,
+    SDLK_THOUSANDSSEPARATOR,
+    SDLK_DECIMALSEPARATOR,
+    SDLK_CURRENCYUNIT,
+    SDLK_CURRENCYSUBUNIT,
+    SDLK_KP_LEFTPAREN,
+    SDLK_KP_RIGHTPAREN,
+    SDLK_KP_LEFTBRACE,
+    SDLK_KP_RIGHTBRACE,
+    SDLK_KP_TAB,
+    SDLK_KP_BACKSPACE,
+    SDLK_KP_A,
+    SDLK_KP_B,
+    SDLK_KP_C,
+    SDLK_KP_D,
+    SDLK_KP_E,
+    SDLK_KP_F,
+    SDLK_KP_XOR,
+    SDLK_KP_POWER,
+    SDLK_KP_PERCENT,
+    SDLK_KP_LESS,
+    SDLK_KP_GREATER,
+    SDLK_KP_AMPERSAND,
+    SDLK_KP_DBLAMPERSAND,
+    SDLK_KP_VERTICALBAR,
+    SDLK_KP_DBLVERTICALBAR,
+    SDLK_KP_COLON,
+    SDLK_KP_HASH,
+    SDLK_KP_SPACE,
+    SDLK_KP_AT,
+    SDLK_KP_EXCLAM,
+    SDLK_KP_MEMSTORE,
+    SDLK_KP_MEMRECALL,
+    SDLK_KP_MEMCLEAR,
+    SDLK_KP_MEMADD,
+    SDLK_KP_MEMSUBTRACT,
+    SDLK_KP_MEMMULTIPLY,
+    SDLK_KP_MEMDIVIDE,
+    SDLK_KP_PLUSMINUS,
+    SDLK_KP_CLEAR,
+    SDLK_KP_CLEARENTRY,
+    SDLK_KP_BINARY,
+    SDLK_KP_OCTAL,
+    SDLK_KP_DECIMAL,
+    SDLK_KP_HEXADECIMAL,
+    0, 0,
+    SDLK_LCTRL,
+    SDLK_LSHIFT,
+    SDLK_LALT,
+    SDLK_LGUI,
+    SDLK_RCTRL,
+    SDLK_RSHIFT,
+    SDLK_RALT,
+    SDLK_RGUI,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    SDLK_MODE,
+    SDLK_AUDIONEXT,
+    SDLK_AUDIOPREV,
+    SDLK_AUDIOSTOP,
+    SDLK_AUDIOPLAY,
+    SDLK_AUDIOMUTE,
+    SDLK_MEDIASELECT,
+    SDLK_MAIL,
+    SDLK_CALCULATOR,
+    SDLK_COMPUTER,
+    SDLK_AC_SEARCH,
+    SDLK_AC_HOME,
+    SDLK_AC_BACK,
+    SDLK_AC_FORWARD,
+    SDLK_AC_STOP,
+    SDLK_AC_REFRESH,
+    SDLK_AC_BOOKMARKS,
+    SDLK_BRIGHTNESSDOWN,
+    SDLK_BRIGHTNESSUP,
+    SDLK_DISPLAYSWITCH,
+    SDLK_KBDILLUMTOGGLE,
+    SDLK_KBDILLUMDOWN,
+    SDLK_KBDILLUMUP,
+    SDLK_EJECT,
+    SDLK_SLEEP,
+};
+
+static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = {
+    NULL, NULL, NULL, NULL,
+    "A",
+    "B",
+    "C",
+    "D",
+    "E",
+    "F",
+    "G",
+    "H",
+    "I",
+    "J",
+    "K",
+    "L",
+    "M",
+    "N",
+    "O",
+    "P",
+    "Q",
+    "R",
+    "S",
+    "T",
+    "U",
+    "V",
+    "W",
+    "X",
+    "Y",
+    "Z",
+    "1",
+    "2",
+    "3",
+    "4",
+    "5",
+    "6",
+    "7",
+    "8",
+    "9",
+    "0",
+    "Return",
+    "Escape",
+    "Backspace",
+    "Tab",
+    "Space",
+    "-",
+    "=",
+    "[",
+    "]",
+    "\\",
+    "#",
+    ";",
+    "'",
+    "`",
+    ",",
+    ".",
+    "/",
+    "CapsLock",
+    "F1",
+    "F2",
+    "F3",
+    "F4",
+    "F5",
+    "F6",
+    "F7",
+    "F8",
+    "F9",
+    "F10",
+    "F11",
+    "F12",
+    "PrintScreen",
+    "ScrollLock",
+    "Pause",
+    "Insert",
+    "Home",
+    "PageUp",
+    "Delete",
+    "End",
+    "PageDown",
+    "Right",
+    "Left",
+    "Down",
+    "Up",
+    "Numlock",
+    "Keypad /",
+    "Keypad *",
+    "Keypad -",
+    "Keypad +",
+    "Keypad Enter",
+    "Keypad 1",
+    "Keypad 2",
+    "Keypad 3",
+    "Keypad 4",
+    "Keypad 5",
+    "Keypad 6",
+    "Keypad 7",
+    "Keypad 8",
+    "Keypad 9",
+    "Keypad 0",
+    "Keypad .",
+    NULL,
+    "Application",
+    "Power",
+    "Keypad =",
+    "F13",
+    "F14",
+    "F15",
+    "F16",
+    "F17",
+    "F18",
+    "F19",
+    "F20",
+    "F21",
+    "F22",
+    "F23",
+    "F24",
+    "Execute",
+    "Help",
+    "Menu",
+    "Select",
+    "Stop",
+    "Again",
+    "Undo",
+    "Cut",
+    "Copy",
+    "Paste",
+    "Find",
+    "Mute",
+    "VolumeUp",
+    "VolumeDown",
+    NULL, NULL, NULL,
+    "Keypad ,",
+    "Keypad = (AS400)",
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    NULL, NULL, NULL, NULL, NULL, NULL,
+    "AltErase",
+    "SysReq",
+    "Cancel",
+    "Clear",
+    "Prior",
+    "Return",
+    "Separator",
+    "Out",
+    "Oper",
+    "Clear / Again",
+    "CrSel",
+    "ExSel",
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    "Keypad 00",
+    "Keypad 000",
+    "ThousandsSeparator",
+    "DecimalSeparator",
+    "CurrencyUnit",
+    "CurrencySubUnit",
+    "Keypad (",
+    "Keypad )",
+    "Keypad {",
+    "Keypad }",
+    "Keypad Tab",
+    "Keypad Backspace",
+    "Keypad A",
+    "Keypad B",
+    "Keypad C",
+    "Keypad D",
+    "Keypad E",
+    "Keypad F",
+    "Keypad XOR",
+    "Keypad ^",
+    "Keypad %",
+    "Keypad <",
+    "Keypad >",
+    "Keypad &",
+    "Keypad &&",
+    "Keypad |",
+    "Keypad ||",
+    "Keypad :",
+    "Keypad #",
+    "Keypad Space",
+    "Keypad @",
+    "Keypad !",
+    "Keypad MemStore",
+    "Keypad MemRecall",
+    "Keypad MemClear",
+    "Keypad MemAdd",
+    "Keypad MemSubtract",
+    "Keypad MemMultiply",
+    "Keypad MemDivide",
+    "Keypad +/-",
+    "Keypad Clear",
+    "Keypad ClearEntry",
+    "Keypad Binary",
+    "Keypad Octal",
+    "Keypad Decimal",
+    "Keypad Hexadecimal",
+    NULL, NULL,
+    "Left Ctrl",
+    "Left Shift",
+    "Left Alt",
+    "Left GUI",
+    "Right Ctrl",
+    "Right Shift",
+    "Right Alt",
+    "Right GUI",
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+    NULL,
+    "ModeSwitch",
+    "AudioNext",
+    "AudioPrev",
+    "AudioStop",
+    "AudioPlay",
+    "AudioMute",
+    "MediaSelect",
+    "Mail",
+    "Calculator",
+    "Computer",
+    "AC Search",
+    "AC Home",
+    "AC Back",
+    "AC Forward",
+    "AC Stop",
+    "AC Refresh",
+    "AC Bookmarks",
+    "BrightnessDown",
+    "BrightnessUp",
+    "DisplaySwitch",
+    "KBDIllumToggle",
+    "KBDIllumDown",
+    "KBDIllumUp",
+    "Eject",
+    "Sleep",
+};
+
 /* Taken from SDL_iconv() */
-char *
-SDL_Ucs4ToUtf8(Uint32 ch, char *dst)
+static char *
+SDL_UCS4ToUTF8(Uint32 ch, char *dst)
 {
     Uint8 *p = (Uint8 *) dst;
     if (ch <= 0x7F) {
@@ -82,9 +539,6 @@
 int
 SDL_KeyboardInit(void)
 {
-    /* Set default mode of UNICODE translation */
-    SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
-
     return (0);
 }
 
@@ -148,170 +602,45 @@
 SDL_ResetKeyboard(int index)
 {
     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
-    int key;
+    SDL_scancode scancode;
 
     if (!keyboard) {
         return;
     }
 
-    for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
-        if (keyboard->keystate[key] == SDL_PRESSED) {
-            SDL_SendKeyboardKey(index, SDL_RELEASED, 0,
-                                key | SDL_KEY_CAN_BE_PHYSICAL_BIT);
+    for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
+        if (keyboard->keystate[scancode] == SDL_PRESSED) {
+            SDL_SendKeyboardKey(index, SDL_RELEASED, scancode);
         }
     }
 }
 
 void
-SDL_KeyboardQuit(void)
-{
-    int i;
-
-    for (i = 0; i < SDL_num_keyboards; ++i) {
-        SDL_DelKeyboard(i);
-    }
-    SDL_num_keyboards = 0;
-    SDL_current_keyboard = 0;
-
-    if (SDL_keyboards) {
-        SDL_free(SDL_keyboards);
-        SDL_keyboards = NULL;
-    }
-}
-
-int
-SDL_GetNumKeyboards(void)
-{
-    return SDL_num_keyboards;
-}
-
-int
-SDL_SelectKeyboard(int index)
-{
-    if (index >= 0 && index < SDL_num_keyboards) {
-        SDL_current_keyboard = index;
-    }
-    return SDL_current_keyboard;
-}
-
-int
-SDL_EnableUNICODE(int enable)
+SDL_GetDefaultKeymap(SDLKey * keymap)
 {
-    int old_mode;
-
-    old_mode = SDL_TranslateUNICODE;
-    if (enable >= 0) {
-        SDL_TranslateUNICODE = enable;
-    }
-    return (old_mode);
-}
-
-Uint8 *
-SDL_GetKeyState(int *numkeys)
-{
-    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
-
-    if (numkeys != (int *) 0) {
-        *numkeys = SDLK_LAST;
-    }
-
-    if (!keyboard) {
-        return NULL;
-    }
-    return keyboard->keystate;
-}
-
-SDLMod
-SDL_GetModState(void)
-{
-    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
-
-    if (!keyboard) {
-        return KMOD_NONE;
-    }
-    return keyboard->modstate;
+    SDL_memcpy(keymap, SDL_default_keymap, sizeof(SDL_default_keymap));
 }
 
 void
-SDL_SetModState(SDLMod modstate)
+SDL_SetKeymap(int index, int start, SDLKey * keys, int length)
 {
-    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
+    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
 
     if (!keyboard) {
         return;
     }
-    keyboard->modstate = modstate;
-}
 
-SDLKey
-SDL_GetLayoutKey(SDLKey physicalKey)
-{
-    SDL_VideoDevice *_this = SDL_GetVideoDevice();
-    if (_this && _this->GetLayoutKey) {
-        return _this->GetLayoutKey(_this, physicalKey)
-            | (physicalKey & SDL_KEY_KEYPAD_BIT);
-    } else {
-        return physicalKey;
-    }
-}
-
-const char *
-SDL_GetKeyName(SDLKey layoutKey)
-{
-    const char *keyname = NULL;
-
-    if ((layoutKey & SDL_KEY_LAYOUT_SPECIAL_BIT) != 0) {
-        SDL_VideoDevice *_this = SDL_GetVideoDevice();
-        if (_this && _this->GetSpecialKeyName) {
-            keyname = _this->GetSpecialKeyName(_this, layoutKey);
-        }
-    } else if ((layoutKey & SDL_KEY_CAN_BE_PHYSICAL_BIT) == 0) {
-        /* SDLK_INDEX(layoutKey) is the unicode code point of the
-           character generated by the key */
-        static char buffer[9];  /* 6 (maximal UTF-8 char length) + 2 ([] for keypad) + 1 (null teminator) */
-        char *bufferPtr = &buffer[1];
-        Uint32 codepoint = SDLK_INDEX(layoutKey);
-
-        /* 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 (codepoint >= 'a' && codepoint <= 'z') {
-            codepoint -= 32;
-        }
-
-        bufferPtr = SDL_Ucs4ToUtf8(codepoint, bufferPtr);
-        *bufferPtr = '\0';
-
-        if ((layoutKey & SDL_KEY_KEYPAD_BIT) != 0) {
-            buffer[0] = '[';
-            *bufferPtr++ = ']';
-            *bufferPtr = '\0';
-            keyname = buffer;
-        } else {
-            keyname = &buffer[1];
-        }
-    } else {
-        /* SDLK_INDEX(layoutKey) is a physical key number */
-        if (SDLK_INDEX(layoutKey) < SDL_arraysize(SDL_keynames)) {
-            keyname = SDL_keynames[SDLK_INDEX(layoutKey)];
-        }
+    if (start < 0 || start + length > SDL_NUM_SCANCODES) {
+        return;
     }
 
-    if (keyname == NULL) {
-        keyname = SDL_keynames[SDLK_INDEX(SDLK_UNKNOWN)];
-    }
-
-    return keyname;
+    SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
 }
 
 void
-SDL_SetKeyName(SDLKey physicalKey, const char *name)
+SDL_SetScancodeName(SDL_scancode scancode, const char *name)
 {
-    physicalKey = SDLK_INDEX(physicalKey);
-    if (physicalKey < SDL_arraysize(SDL_keynames)) {
-        SDL_keynames[physicalKey] = name;
-    }
+    SDL_scancode_names[scancode] = name;
 }
 
 void
@@ -366,94 +695,89 @@
 }
 
 int
-SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode,
-                    SDLKey physicalKey)
+SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
 {
     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
     int posted;
     Uint16 modstate;
     Uint8 type;
 
-    if (!keyboard || physicalKey == SDLK_NONE) {
+    if (!keyboard || !scancode) {
         return 0;
     }
 #if 0
-    printf("The '%s' key has been %s\n", SDL_GetKeyName(physicalKey),
+    printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
            state == SDL_PRESSED ? "pressed" : "released");
 #endif
     if (state == SDL_PRESSED) {
         modstate = keyboard->modstate;
-        switch (physicalKey) {
-        case SDLK_UNKNOWN:
-            break;
-        case SDLK_KP_NUMLOCKCLEAR:
+        switch (scancode) {
+        case SDL_SCANCODE_NUMLOCKCLEAR:
             keyboard->modstate ^= KMOD_NUM;
             break;
-        case SDLK_CAPSLOCK:
+        case SDL_SCANCODE_CAPSLOCK:
             keyboard->modstate ^= KMOD_CAPS;
             break;
-        case SDLK_LCTRL:
+        case SDL_SCANCODE_LCTRL:
             keyboard->modstate |= KMOD_LCTRL;
             break;
-        case SDLK_RCTRL:
+        case SDL_SCANCODE_RCTRL:
             keyboard->modstate |= KMOD_RCTRL;
             break;
-        case SDLK_LSHIFT:
+        case SDL_SCANCODE_LSHIFT:
             keyboard->modstate |= KMOD_LSHIFT;
             break;
-        case SDLK_RSHIFT:
+        case SDL_SCANCODE_RSHIFT:
             keyboard->modstate |= KMOD_RSHIFT;
             break;
-        case SDLK_LALT:
+        case SDL_SCANCODE_LALT:
             keyboard->modstate |= KMOD_LALT;
             break;
-        case SDLK_RALT:
+        case SDL_SCANCODE_RALT:
             keyboard->modstate |= KMOD_RALT;
             break;
-        case SDLK_LMETA:
-            keyboard->modstate |= KMOD_LMETA;
+        case SDL_SCANCODE_LGUI:
+            keyboard->modstate |= KMOD_LGUI;
             break;
-        case SDLK_RMETA:
-            keyboard->modstate |= KMOD_RMETA;
+        case SDL_SCANCODE_RGUI:
+            keyboard->modstate |= KMOD_RGUI;
             break;
-        case SDLK_MODE:
+        case SDL_SCANCODE_MODE:
             keyboard->modstate |= KMOD_MODE;
             break;
         default:
             break;
         }
     } else {
-        switch (physicalKey) {
-        case SDLK_UNKNOWN:
+        switch (scancode) {
+        case SDL_SCANCODE_NUMLOCKCLEAR:
+        case SDL_SCANCODE_CAPSLOCK:
             break;
-        case SDLK_KP_NUMLOCKCLEAR:
-        case SDLK_CAPSLOCK:
-            break;
-        case SDLK_LCTRL:
+        case SDL_SCANCODE_LCTRL:
             keyboard->modstate &= ~KMOD_LCTRL;
             break;
-        case SDLK_RCTRL:
+        case SDL_SCANCODE_RCTRL:
             keyboard->modstate &= ~KMOD_RCTRL;
             break;
-        case SDLK_LSHIFT:
+        case SDL_SCANCODE_LSHIFT:
             keyboard->modstate &= ~KMOD_LSHIFT;
             break;
-        case SDLK_RSHIFT:
+        case SDL_SCANCODE_RSHIFT:
             keyboard->modstate &= ~KMOD_RSHIFT;
             break;
-        case SDLK_LALT:
+        case SDL_SCANCODE_LALT:
             keyboard->modstate &= ~KMOD_LALT;
             break;
-        case SDLK_RALT:
+        case SDL_SCANCODE_RALT:
             keyboard->modstate &= ~KMOD_RALT;
             break;
-        case SDLK_LMETA:
-            keyboard->modstate &= ~KMOD_LMETA;
+        case SDL_SCANCODE_LGUI:
+            keyboard->modstate &= ~KMOD_LGUI;
             break;
-        case SDLK_RMETA:
-            keyboard->modstate &= ~KMOD_RMETA;
+        case SDL_SCANCODE_RGUI:
+            keyboard->modstate &= ~KMOD_RGUI;
             break;
-        case SDLK_MODE:
+        case SDL_SCANCODE_MODE:
             keyboard->modstate &= ~KMOD_MODE;
             break;
         default:
@@ -475,18 +799,16 @@
         return 0;
     }
 
-    if (physicalKey != SDLK_UNKNOWN) {
-        /* Drop events that don't change state */
-        if (keyboard->keystate[SDLK_INDEX(physicalKey)] == state) {
+    /* Drop events that don't change state */
+    if (keyboard->keystate[scancode] == state) {
 #if 0
-            printf("Keyboard event didn't change state - dropped!\n");
+        printf("Keyboard event didn't change state - dropped!\n");
 #endif
-            return 0;
-        }
+        return 0;
+    }
 
-        /* Update internal keyboard state */
-        keyboard->keystate[SDLK_INDEX(physicalKey)] = state;
-    }
+    /* Update internal keyboard state */
+    keyboard->keystate[scancode] = state;
 
     /* Post the event, if desired */
     posted = 0;
@@ -496,7 +818,7 @@
         event.key.which = (Uint8) index;
         event.key.state = state;
         event.key.keysym.scancode = scancode;
-        event.key.keysym.sym = physicalKey;
+        event.key.keysym.sym = keyboard->keymap[scancode];
         event.key.keysym.mod = modstate;
         event.key.keysym.unicode = 0;
         event.key.windowID = keyboard->focus;
@@ -528,4 +850,138 @@
     return (posted);
 }
 
+void
+SDL_KeyboardQuit(void)
+{
+    int i;
+
+    for (i = 0; i < SDL_num_keyboards; ++i) {
+        SDL_DelKeyboard(i);
+    }
+    SDL_num_keyboards = 0;
+    SDL_current_keyboard = 0;
+
+    if (SDL_keyboards) {
+        SDL_free(SDL_keyboards);
+        SDL_keyboards = NULL;
+    }
+}
+
+int
+SDL_GetNumKeyboards(void)
+{
+    return SDL_num_keyboards;
+}
+
+int
+SDL_SelectKeyboard(int index)
+{
+    if (index >= 0 && index < SDL_num_keyboards) {
+        SDL_current_keyboard = index;
+    }
+    return SDL_current_keyboard;
+}
+
+Uint8 *
+SDL_GetKeyboardState(int *numkeys)
+{
+    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
+
+    if (numkeys != (int *) 0) {
+        *numkeys = SDL_NUM_SCANCODES;
+    }
+
+    if (!keyboard) {
+        return NULL;
+    }
+    return keyboard->keystate;
+}
+
+SDLMod
+SDL_GetModState(void)
+{
+    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
+
+    if (!keyboard) {
+        return KMOD_NONE;
+    }
+    return keyboard->modstate;
+}
+
+void
+SDL_SetModState(SDLMod modstate)
+{
+    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
+
+    if (!keyboard) {
+        return;
+    }
+    keyboard->modstate = modstate;
+}
+
+SDLKey
+SDL_GetKeyFromScancode(SDL_scancode scancode)
+{
+    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
+
+    if (!keyboard) {
+        return SDLK_UNKNOWN;
+    }
+    return keyboard->keymap[scancode];
+}
+
+SDL_scancode
+SDL_GetScancodeFromKey(SDLKey key)
+{
+    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
+    SDL_scancode scancode;
+
+    if (!keyboard) {
+        return SDL_SCANCODE_UNKNOWN;
+    }
+
+    for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
+         ++scancode) {
+        if (keyboard->keymap[scancode] == key) {
+            return scancode;
+        }
+    }
+    return SDL_SCANCODE_UNKNOWN;
+}
+
+const char *
+SDL_GetScancodeName(SDL_scancode scancode)
+{
+    const char *name = SDL_scancode_names[scancode];
+
+    if (name)
+        return name;
+    else
+        return "";
+}
+
+const char *
+SDL_GetKeyName(SDLKey key)
+{
+    static char name[8];
+    char *end;
+
+    if (key & SDLK_SCANCODE_MASK) {
+        return
+            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;
+    }
+
+    end = SDL_UCS4ToUTF8((Uint32) key, name);
+    *end = '\0';
+    return name;
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/events/SDL_keyboard_c.h	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/events/SDL_keyboard_c.h	Tue Feb 05 07:19:23 2008 +0000
@@ -37,20 +37,12 @@
     /* Data common to all keyboards */
     SDL_WindowID focus;
     Uint16 modstate;
-    Uint8 keystate[SDLK_LAST];
+    Uint8 keystate[(SDL_NUM_SCANCODES + 7) / 8];
+    SDLKey keymap[SDL_NUM_SCANCODES];
 
     void *driverdata;
 };
 
-/* Used by the OS keyboard code to detect whether or not to do UNICODE */
-#ifndef DEFAULT_UNICODE_TRANSLATION
-#define DEFAULT_UNICODE_TRANSLATION 0   /* Default off because of overhead */
-#endif
-extern int SDL_TranslateUNICODE;
-
-/* convert UCS4 to utf8 */
-extern char *SDL_Ucs4ToUtf8(Uint32 ch, char *dst);
-
 /* Initialize the keyboard subsystem */
 extern int SDL_KeyboardInit(void);
 
@@ -68,18 +60,23 @@
 /* Clear the state of a keyboard at an index */
 extern void SDL_ResetKeyboard(int index);
 
+/* Get the default keymap */
+extern void SDL_GetDefaultKeymap(SDLKey * keymap);
+
+/* Set the mapping of scancode to key codes for this keyboard */
+extern void SDL_SetKeymap(int index, int start, SDLKey * keys, int length);
+
 /* Set a platform-dependent key name, overriding the default platform-agnostic
    name. Encoded as UTF-8. The string is not copied, thus the pointer given to
    this function must stay valid forever (or at least until the call to
    VideoQuit()). */
-extern void SDL_SetKeyName(SDLKey physicalKey, const char *name);
+extern void SDL_SetScancodeName(SDL_scancode scancode, const char *name);
 
 /* Set the keyboard focus window */
 extern void SDL_SetKeyboardFocus(int index, SDL_WindowID windowID);
 
 /* Send a keyboard event for a keyboard at an index */
-extern int SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode,
-                               SDLKey key);
+extern int SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode);
 
 /* Send keyboard text input for a keyboard at an index */
 extern int SDL_SendKeyboardText(int index, const char *text);
--- a/src/events/SDL_keynames.h	Mon Feb 04 17:25:33 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,304 +0,0 @@
-/*
-    SDL - Simple DirectMedia Layer
-    Copyright (C) 1997-2007 Sam Lantinga
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-    Christian Walther
-    cwalther@gmx.ch
-*/
-
-/* Names for the physical SDLKey constants, returned by SDL_GetKeyName().
-   The strings are in UTF-8 encoding.
-   This table can (and should) be modified by a video driver in its VideoInit()
-   function using SDL_SetKeyName() to account for platform-dependent (but
-   layout-independent) key names.
-   
-   The physical SDLKey codes can be divided into two groups:
-   - codes that occur both as physical and as layout keys. These have their
-     real, "user-readable" display name here.
-   - codes that only occur as physical keys, i.e. are never returned by
-     SDL_GetLayoutKey() if the backend implements it properly. These names are
-     therefore never returned by SDL_GetKeyName(SDL_GetLayoutKey(
-     event.key.keysym.sym)), the proper way of displaying a key name to the
-     user, but only by SDL_GetKeyName(event.key.keysym.sym), which is only
-     useful for debugging purposes. To emphasize this, these codes are named by
-     their "programmer-readable" SDLK_ constants here rather than by a
-     "user-readable" display name.
- */
-
-/* *INDENT-OFF* */
-static const char *SDL_keynames[SDLK_LAST] = {
-    /*   0 */   "", /* SDL_PK_NONE */
-    /*   1 */   "unknown key",
-    /*   2 */   NULL, /* unused */
-    /*   3 */   NULL, /* unused */
-    /*   4 */   "SDLK_A",
-    /*   5 */   "SDLK_B",
-    /*   6 */   "SDLK_C",
-    /*   7 */   "SDLK_D",
-    /*   8 */   "SDLK_E",
-    /*   9 */   "SDLK_F",
-    /*  10 */   "SDLK_G",
-    /*  11 */   "SDLK_H",
-    /*  12 */   "SDLK_I",
-    /*  13 */   "SDLK_J",
-    /*  14 */   "SDLK_K",
-    /*  15 */   "SDLK_L",
-    /*  16 */   "SDLK_M",
-    /*  17 */   "SDLK_N",
-    /*  18 */   "SDLK_O",
-    /*  19 */   "SDLK_P",
-    /*  20 */   "SDLK_Q",
-    /*  21 */   "SDLK_R",
-    /*  22 */   "SDLK_S",
-    /*  23 */   "SDLK_T",
-    /*  24 */   "SDLK_U",
-    /*  25 */   "SDLK_V",
-    /*  26 */   "SDLK_W",
-    /*  27 */   "SDLK_X",
-    /*  28 */   "SDLK_Y",
-    /*  29 */   "SDLK_Z",
-    /*  30 */   "SDLK_1",
-    /*  31 */   "SDLK_2",
-    /*  32 */   "SDLK_3",
-    /*  33 */   "SDLK_4",
-    /*  34 */   "SDLK_5",
-    /*  35 */   "SDLK_6",
-    /*  36 */   "SDLK_7",
-    /*  37 */   "SDLK_8",
-    /*  38 */   "SDLK_9",
-    /*  39 */   "SDLK_0",
-    /*  40 */   "return",
-    /*  41 */   "escape",
-    /*  42 */   "backspace",
-    /*  43 */   "tab",
-    /*  44 */   "space",
-    /*  45 */   "SDLK_HYPHENMINUS",
-    /*  46 */   "SDLK_EQUALS",
-    /*  47 */   "SDLK_LEFTBRACKET",
-    /*  48 */   "SDLK_RIGHTBRACKET",
-    /*  49 */   "SDLK_BACKSLASH",
-    /*  50 */   "SDLK_NONUSHASH",
-    /*  51 */   "SDLK_SEMICOLON",
-    /*  52 */   "SDLK_APOSTROPHE",
-    /*  53 */   "SDLK_GRAVE",
-    /*  54 */   "SDLK_COMMA",
-    /*  55 */   "SDLK_PERIOD",
-    /*  56 */   "SDLK_SLASH",
-    /*  57 */   "caps lock",
-    /*  58 */   "F1",
-    /*  59 */   "F2",
-    /*  60 */   "F3",
-    /*  61 */   "F4",
-    /*  62 */   "F5",
-    /*  63 */   "F6",
-    /*  64 */   "F7",
-    /*  65 */   "F8",
-    /*  66 */   "F9",
-    /*  67 */   "F10",
-    /*  68 */   "F11",
-    /*  69 */   "F12",
-    /*  70 */   "print screen",
-    /*  71 */   "scroll lock",
-    /*  72 */   "pause",
-    /*  73 */   "insert",
-    /*  74 */   "home",
-    /*  75 */   "page up",
-    /*  76 */   "delete",
-    /*  77 */   "end",
-    /*  78 */   "page down",
-    /*  79 */   "right",
-    /*  80 */   "left",
-    /*  81 */   "down",
-    /*  82 */   "up",
-    /*  83 */   "num lock",
-    /*  84 */   "SDLK_KP_DIVIDE",
-    /*  85 */   "SDLK_KP_MULTIPLY",
-    /*  86 */   "SDLK_KP_MINUS",
-    /*  87 */   "SDLK_KP_PLUS",
-    /*  88 */   "enter",
-    /*  89 */   "SDLK_KP_1",
-    /*  90 */   "SDLK_KP_2",
-    /*  91 */   "SDLK_KP_3",
-    /*  92 */   "SDLK_KP_4",
-    /*  93 */   "SDLK_KP_5",
-    /*  94 */   "SDLK_KP_6",
-    /*  95 */   "SDLK_KP_7",
-    /*  96 */   "SDLK_KP_8",
-    /*  97 */   "SDLK_KP_9",
-    /*  98 */   "SDLK_KP_0",
-    /*  99 */   "SDLK_KP_PERIOD",
-    /* 100 */   "SDLK_NONUSBACKSLASH",
-    /* 101 */   "application",
-    /* 102 */   "power",
-    /* 103 */   "SDLK_KP_EQUALS",
-    /* 104 */   "F13",
-    /* 105 */   "F14",
-    /* 106 */   "F15",
-    /* 107 */   "F16",
-    /* 108 */   "F17",
-    /* 109 */   "F18",
-    /* 110 */   "F19",
-    /* 111 */   "F20",
-    /* 112 */   "F21",
-    /* 113 */   "F22",
-    /* 114 */   "F23",
-    /* 115 */   "F24",
-    /* 116 */   "execute",
-    /* 117 */   "help",
-    /* 118 */   "menu",
-    /* 119 */   "select",
-    /* 120 */   "stop",
-    /* 121 */   "again",
-    /* 122 */   "undo",
-    /* 123 */   "cut",
-    /* 124 */   "copy",
-    /* 125 */   "paste",
-    /* 126 */   "find",
-    /* 127 */   "mute",
-    /* 128 */   "volume up",
-    /* 129 */   "volume down",
-    /* 130 */   "caps lock", /* unused */
-    /* 131 */   "num lock", /* unused */
-    /* 132 */   "scroll lock", /* unused */
-    /* 133 */   "SDLK_KP_COMMA",
-    /* 134 */   "SDLK_KP_EQUALSAS400",
-    /* 135 */   "international 1",
-    /* 136 */   "international 2",
-    /* 137 */   "international 3",
-    /* 138 */   "international 4",
-    /* 139 */   "international 5",
-    /* 140 */   "international 6",
-    /* 141 */   "international 7",
-    /* 142 */   "international 8",
-    /* 143 */   "international 9",
-    /* 144 */   "lang 1",
-    /* 145 */   "lang 2",
-    /* 146 */   "lang 3",
-    /* 147 */   "lang 4",
-    /* 148 */   "lang 5",
-    /* 149 */   "lang 6",
-    /* 150 */   "lang 7",
-    /* 151 */   "lang 8",
-    /* 152 */   "lang 9",
-    /* 153 */   "alt erase",
-    /* 154 */   "sys req",
-    /* 155 */   "cancel",
-    /* 156 */   "clear",
-    /* 157 */   "prior",
-    /* 158 */   "return",
-    /* 159 */   "separator",
-    /* 160 */   "out",
-    /* 161 */   "oper",
-    /* 162 */   "clear/again",
-    /* 163 */   "crsel/props",
-    /* 164 */   "exsel",
-    /* 165 */   NULL, /* unused */
-    /* 166 */   NULL, /* unused */
-    /* 167 */   NULL, /* unused */
-    /* 168 */   NULL, /* unused */
-    /* 169 */   NULL, /* unused */
-    /* 170 */   NULL, /* unused */
-    /* 171 */   NULL, /* unused */
-    /* 172 */   NULL, /* unused */
-    /* 173 */   NULL, /* unused */
-    /* 174 */   NULL, /* unused */
-    /* 175 */   NULL, /* unused */
-    /* 176 */   "[00]",
-    /* 177 */   "[000]",
-    /* 178 */   "thousands separator",
-    /* 179 */   "decimal separator",
-    /* 180 */   "currency unit",
-    /* 181 */   "currency sub-unit",
-    /* 182 */   "[(]",
-    /* 183 */   "[)]",
-    /* 184 */   "[{]",
-    /* 185 */   "[}]",
-    /* 186 */   "[tab]",
-    /* 187 */   "[backspace]",
-    /* 188 */   "[A]",
-    /* 189 */   "[B]",
-    /* 190 */   "[C]",
-    /* 191 */   "[D]",
-    /* 192 */   "[E]",
-    /* 193 */   "[F]",
-    /* 194 */   "[XOR]",
-    /* 195 */   "[^]",
-    /* 196 */   "[%]",
-    /* 197 */   "[<]",
-    /* 198 */   "[>]",
-    /* 199 */   "[&]",
-    /* 200 */   "[&&]",
-    /* 201 */   "[|]",
-    /* 202 */   "[||]",
-    /* 203 */   "[:]",
-    /* 204 */   "[#]",
-    /* 205 */   "[space]",
-    /* 206 */   "[@]",
-    /* 207 */   "[!]",
-    /* 208 */   "[mem store]",
-    /* 209 */   "[mem recall]",
-    /* 210 */   "[mem clear]",
-    /* 211 */   "[mem +]",
-    /* 212 */   "[mem -]",
-    /* 213 */   "[mem *]",
-    /* 214 */   "[mem /]",
-    /* 215 */   "[+/-]",
-    /* 216 */   "[clear]",
-    /* 217 */   "[clear entry]",
-    /* 218 */   "[binary]",
-    /* 219 */   "[octal]",
-    /* 220 */   "[decimal]",
-    /* 221 */   "[hexadecimal]",
-    /* 222 */   NULL, /* unused */
-    /* 223 */   NULL, /* unused */
-    /* 224 */   "left ctrl",
-    /* 225 */   "left shift",
-    /* 226 */   "left alt",
-    /* 227 */   "left meta",
-    /* 228 */   "right ctrl",
-    /* 229 */   "right shift",
-    /* 230 */   "right alt",
-    /* 231 */   "right meta",
-    /* 232 */   "mode",
-    /* 233 */   NULL, /* unused */
-    /* 234 */   NULL, /* unused */
-    /* 235 */   NULL, /* unused */
-    /* 236 */   "brightness down",
-    /* 237 */   "brightness up",
-    /* 238 */   "display switch",
-    /* 239 */   "kbd illum toggle",
-    /* 240 */   "kbd illum down",
-    /* 241 */   "kbd illum up",
-    /* 242 */   "eject",
-    /* 243 */   "sleep",
-    /* 244 */   "play",
-    /* 245 */   "stop",
-    /* 246 */   "previous",
-    /* 247 */   "next",
-    /* 248 */   "calc",
-    /* 249 */   "www",
-    /* 250 */   "e-mail",
-    /* 251 */   "media",
-    /* 252 */   "computer",
-    /* 253 */   "search",
-    /* 254 */   "bookmarks",
-    /* 255 */   "back",
-    /* 256 */   "forward",
-    /* 257 */   "reload",
-    /* 258 */   "stop"
-};
-/* *INDENT-ON* */
--- a/src/video/SDL_sysvideo.h	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/video/SDL_sysvideo.h	Tue Feb 05 07:19:23 2008 +0000
@@ -257,45 +257,6 @@
      */
     void (*PumpEvents) (_THIS);
 
-    /* Get the layout key code corresponding to the given physical key code
-     * according to the OS' current keyboard layout.
-     *
-     * - For character keys, this should return the Unicode code point of the
-     * character that is generated when the key is pressed without shift or
-     * any other modifiers.
-     * - For non-character keys, this should return one of the SDLK_* constants
-     * (usually the argument itself since these keys are typically layout-
-     * independent). Make sure that all of these values returned by this
-     * function have a suitable name defined, either the default from
-     * SDL_keynames.h, or one set using SDL_SetKeyName() in VideoInit(). In
-     * particular, if this function can return any of the codes whose default
-     * names start with "SDLK_" (usually, it shouldn't, since these are layout-
-     * dependent character keys), these names should be replaced by proper
-     * user-readable names.
-     * - If there are keys that cannot be adequately described by either a
-     * single Unicode character or an SDLK_* constant, this function may return
-     * a code with SDL_KEY_LAYOUT_SPECIAL_BIT set in the most significant byte
-     * and an arbitrary value in the less significant 3 bytes. The
-     * GetSpecialKeyName() function must then be implemented to take this code
-     * and return a human-readable key name for it.
-     * If the argument is not a physical key code or if translation of the key
-     * code by the OS' keyboard layout fails for any reason, the argument must
-     * be returned unchanged.
-     *
-     * On platforms that don't have the notion of a user-configurable keyboard
-     * layout, this may be left unimplemented. The default implementation of
-     * SDL_GetLayoutKey() then acts as the identity. The note about defining
-     * key names above particularly applies in this case.
-     */
-      SDLKey(*GetLayoutKey) (_THIS, SDLKey physicalKey);
-
-    /* Get a human-readable name for a special layout key code.
-     * This only needs to be implemented if this driver's implementation of
-     * GetLayoutKey() generates such codes (with SDL_KEY_LAYOUT_SPECIAL_BIT
-     * set) - see above.
-     */
-    const char *(*GetSpecialKeyName) (_THIS, SDLKey layoutKey);
-
     /* * * */
     /* Data common to all drivers */
     int num_displays;
--- a/src/video/cocoa/SDL_cocoakeyboard.h	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/video/cocoa/SDL_cocoakeyboard.h	Tue Feb 05 07:19:23 2008 +0000
@@ -26,7 +26,6 @@
 
 extern void Cocoa_InitKeyboard(_THIS);
 extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
-extern SDLKey Cocoa_GetLayoutKey(_THIS, SDLKey physicalKey);
 extern void Cocoa_QuitKeyboard(_THIS);
 
 #endif /* _SDL_cocoakeyboard_h */
--- a/src/video/cocoa/SDL_cocoakeyboard.m	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/video/cocoa/SDL_cocoakeyboard.m	Tue Feb 05 07:19:23 2008 +0000
@@ -71,7 +71,13 @@
 DoUnsidedModifiers(int keyboard, unsigned short scancode,
                    unsigned int oldMods, unsigned int newMods)
 {
-    const int mapping[] = { SDLK_CAPSLOCK, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA };
+    const int mapping[] = {
+        SDL_SCANCODE_CAPSLOCK,
+        SDL_SCANCODE_LSHIFT,
+        SDL_SCANCODE_LCTRL,
+        SDL_SCANCODE_LALT,
+        SDL_SCANCODE_LGUI
+    };
     unsigned int i, bit;
 
     /* Iterate through the bits, testing each against the current modifiers */
@@ -84,14 +90,14 @@
         if (oldMask && oldMask != newMask) {        /* modifier up event */
             /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
             if (bit == NSAlphaShiftKeyMask) {
-                SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, mapping[i]);
+                SDL_SendKeyboardKey(keyboard, SDL_PRESSED, mapping[i]);
             }
-            SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, mapping[i]);
+            SDL_SendKeyboardKey(keyboard, SDL_RELEASED, mapping[i]);
         } else if (newMask && oldMask != newMask) { /* modifier down event */
-            SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, mapping[i]);
+            SDL_SendKeyboardKey(keyboard, SDL_PRESSED, mapping[i]);
             /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
             if (bit == NSAlphaShiftKeyMask) {
-                SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, mapping[i]);
+                SDL_SendKeyboardKey(keyboard, SDL_RELEASED, mapping[i]);
             }
         }
     }
@@ -102,11 +108,11 @@
  * sides was made.
  */
 static void
-HandleNonDeviceModifier(int keyboard, unsigned short scancode,
+HandleNonDeviceModifier(int keyboard,
                         unsigned int device_independent_mask,
                         unsigned int oldMods,
                         unsigned int newMods,
-                        SDLKey key_sym)
+                        SDL_scancode scancode)
 {
     unsigned int oldMask, newMask;
     
@@ -117,9 +123,9 @@
     newMask = newMods & device_independent_mask;
     
     if (oldMask && oldMask != newMask) {
-        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, key_sym);
+        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, scancode);
     } else if (newMask && oldMask != newMask) {
-        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, key_sym);
+        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, scancode);
     }
 }
 
@@ -127,9 +133,9 @@
  * This function sets the actual SDL_PrivateKeyboard event.
  */
 static void
-HandleModifierOneSide(int keyboard, unsigned short scancode,
+HandleModifierOneSide(int keyboard,
                       unsigned int oldMods, unsigned int newMods,
-                      SDLKey key_sym, 
+                      SDL_scancode scancode, 
                       unsigned int sided_device_dependent_mask)
 {
     unsigned int old_dep_mask, new_dep_mask;
@@ -145,9 +151,9 @@
      * find out which it is.
      */
     if (new_dep_mask && old_dep_mask != new_dep_mask) {
-        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, key_sym);
+        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, scancode);
     } else {
-        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, key_sym);
+        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, scancode);
     }
 }
 
@@ -156,11 +162,11 @@
  * e.g. left-shift vs right-shift. 
  */
 static void
-HandleModifierSide(int keyboard, unsigned short scancode,
+HandleModifierSide(int keyboard,
                    int device_independent_mask, 
                    unsigned int oldMods, unsigned int newMods, 
-                   SDLKey left_key_sym, 
-                   SDLKey right_key_sym,
+                   SDL_scancode left_scancode, 
+                   SDL_scancode right_scancode,
                    unsigned int left_device_dependent_mask, 
                    unsigned int right_device_dependent_mask)
 {
@@ -174,7 +180,7 @@
      */
     if ((device_dependent_mask & newMods) == 0) {
         /* Revert to the old behavior */
-        HandleNonDeviceModifier(keyboard, scancode, device_independent_mask, oldMods, newMods, left_key_sym);
+        HandleNonDeviceModifier(keyboard, device_independent_mask, oldMods, newMods, left_scancode);
         return;
     }
 
@@ -187,10 +193,10 @@
          * change or if the bits don't both exist.
          */
         if (left_device_dependent_mask & diff_mod) {
-            HandleModifierOneSide(keyboard, scancode, oldMods, newMods, left_key_sym, left_device_dependent_mask);
+            HandleModifierOneSide(keyboard, oldMods, newMods, left_scancode, left_device_dependent_mask);
         }
         if (right_device_dependent_mask & diff_mod) {
-            HandleModifierOneSide(keyboard, scancode, oldMods, newMods, right_key_sym, right_device_dependent_mask);
+            HandleModifierOneSide(keyboard, oldMods, newMods, right_scancode, right_device_dependent_mask);
         }
     }
 }
@@ -201,11 +207,11 @@
  * can't still be down).
  */
 static void
-ReleaseModifierSide(int keyboard, unsigned short scancode,
+ReleaseModifierSide(int keyboard,
                     unsigned int device_independent_mask, 
                     unsigned int oldMods, unsigned int newMods,
-                    SDLKey left_key_sym, 
-                    SDLKey right_key_sym,
+                    SDL_scancode left_scancode, 
+                    SDL_scancode right_scancode,
                     unsigned int left_device_dependent_mask, 
                     unsigned int right_device_dependent_mask)
 {
@@ -220,7 +226,7 @@
         /* In this case, we can't detect the keyboard, so use the left side 
          * to represent both, and release it. 
          */
-        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, left_key_sym);
+        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, left_scancode);
         return;
     }
 
@@ -231,10 +237,10 @@
      * so I hope this doesn't cause other problems.
      */
     if ( left_device_dependent_mask & oldMods ) {
-        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, left_key_sym);
+        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, left_scancode);
     }
     if ( right_device_dependent_mask & oldMods ) {
-        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, right_key_sym);
+        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, right_scancode);
     }
 }
 
@@ -251,16 +257,16 @@
     newMask = newMods & NSAlphaShiftKeyMask;
 
     if (oldMask != newMask) {
-        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_CAPSLOCK);
-        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_CAPSLOCK);
+        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
+        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
     }
 
     oldMask = oldMods & NSNumericPadKeyMask;
     newMask = newMods & NSNumericPadKeyMask;
 
     if (oldMask != newMask) {
-        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_KP_NUMLOCKCLEAR);
-        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_KP_NUMLOCKCLEAR);
+        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR);
+        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR);
     }
 }
 
@@ -272,8 +278,18 @@
                  unsigned int oldMods, unsigned int newMods)
 {
 	/* Set up arrays for the key syms for the left and right side. */
-    const SDLKey left_mapping[]  = { SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA };
-    const SDLKey right_mapping[] = { SDLK_RSHIFT, SDLK_RCTRL, SDLK_RALT, SDLK_RMETA };
+    const SDL_scancode left_mapping[]  = {
+        SDL_SCANCODE_LSHIFT,
+        SDL_SCANCODE_LCTRL,
+        SDL_SCANCODE_LALT,
+        SDL_SCANCODE_LGUI
+    };
+    const SDL_scancode right_mapping[] = {
+        SDL_SCANCODE_RSHIFT,
+        SDL_SCANCODE_RCTRL,
+        SDL_SCANCODE_RALT,
+        SDL_SCANCODE_RGUI
+    };
 	/* Set up arrays for the device dependent masks with indices that 
      * correspond to the _mapping arrays 
      */
@@ -296,7 +312,7 @@
          * and right side keys may alternate or both may be pressed.
          */
         if (newMask) {
-            HandleModifierSide(keyboard, scancode, bit, oldMods, newMods,
+            HandleModifierSide(keyboard, bit, oldMods, newMods,
                                left_mapping[i], right_mapping[i],
                                left_device_mapping[i], right_device_mapping[i]);
         }
@@ -304,7 +320,7 @@
             * the device dependent bits to release the correct keys.
             */
         else if (oldMask && oldMask != newMask) {
-            ReleaseModifierSide(keyboard, scancode, bit, oldMods, newMods,
+            ReleaseModifierSide(keyboard, bit, oldMods, newMods,
                               left_mapping[i], right_mapping[i],
                               left_device_mapping[i], right_device_mapping[i]);
         }
@@ -332,6 +348,109 @@
     data->modifierFlags = modifierFlags;
 }
 
+static void
+UpdateKeymap(SDL_VideoData *data)
+{
+    KeyboardLayoutRef key_layout;
+    const void *chr_data;
+    int i;
+    SDL_scancode scancode;
+    SDLKey keymap[SDL_NUM_SCANCODES];
+
+    /* See if the keymap needs to be updated */
+    KLGetCurrentKeyboardLayout(&key_layout);
+    if (key_layout == data->key_layout) {
+        return;
+    }
+    data->key_layout = key_layout;
+
+    SDL_GetDefaultKeymap(keymap);
+
+    /* Try Unicode data first (preferred as of Mac OS X 10.5) */
+    KLGetKeyboardLayoutProperty(key_layout, kKLuchrData, &chr_data);
+    if (chr_data) {
+        UInt32 keyboard_type = LMGetKbdType();
+        OSStatus err;
+
+        for (i = 0; i < SDL_arraysize(scancode_table); i++) {
+            UniChar s[8];
+            UniCharCount len;
+            UInt32 dead_key_state;
+
+            /* Make sure this scancode is a valid character scancode */
+            scancode = scancode_table[i];
+            if (scancode == SDL_SCANCODE_UNKNOWN ||
+                (keymap[scancode] & SDLK_SCANCODE_MASK)) {
+                continue;
+            }
+
+            dead_key_state = 0;
+            err = UCKeyTranslate (chr_data, i, kUCKeyActionDown,
+                                  0, keyboard_type,
+                                  kUCKeyTranslateNoDeadKeysMask,
+                                  &dead_key_state, 8, &len, s);
+            if (err != noErr)
+                continue;
+
+            if (len > 0 && s[0] != 0x10) {
+                keymap[scancode] = s[0];
+            }
+        }
+        SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
+        return;
+    }
+
+    /* Fall back to older style key map data */
+    KLGetKeyboardLayoutProperty(key_layout, kKLKCHRData, &chr_data);
+    if (chr_data) {
+        for (i = 0; i < 128; i++) {
+            UInt32 c, state = 0;
+
+            /* Make sure this scancode is a valid character scancode */
+            scancode = scancode_table[i];
+            if (scancode == SDL_SCANCODE_UNKNOWN ||
+                (keymap[scancode] & SDLK_SCANCODE_MASK)) {
+                continue;
+            }
+
+            c = KeyTranslate (chr_data, i, &state);
+            if (state) {
+                /* Dead key, process key up */
+                c = KeyTranslate (chr_data, i | 128, &state);
+            }
+
+            if (c != 0 && c != 0x10 && c < 256) {
+                /* MacRoman to Unicode table, taken from X.org sources */
+                static const unsigned short macroman_table[128] = {
+                    0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1,
+                    0xe0, 0xe2, 0xe4, 0xe3, 0xe5, 0xe7, 0xe9, 0xe8,
+                    0xea, 0xeb, 0xed, 0xec, 0xee, 0xef, 0xf1, 0xf3,
+                    0xf2, 0xf4, 0xf6, 0xf5, 0xfa, 0xf9, 0xfb, 0xfc,
+                    0x2020, 0xb0, 0xa2, 0xa3, 0xa7, 0x2022, 0xb6, 0xdf,
+                    0xae, 0xa9, 0x2122, 0xb4, 0xa8, 0x2260, 0xc6, 0xd8,
+                    0x221e, 0xb1, 0x2264, 0x2265, 0xa5, 0xb5, 0x2202, 0x2211,
+                    0x220f, 0x3c0, 0x222b, 0xaa, 0xba, 0x3a9, 0xe6, 0xf8,
+                    0xbf, 0xa1, 0xac, 0x221a, 0x192, 0x2248, 0x2206, 0xab,
+                    0xbb, 0x2026, 0xa0, 0xc0, 0xc3, 0xd5, 0x152, 0x153,
+                    0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0xf7, 0x25ca,
+                    0xff, 0x178, 0x2044, 0x20ac, 0x2039, 0x203a, 0xfb01, 0xfb02,
+                    0x2021, 0xb7, 0x201a, 0x201e, 0x2030, 0xc2, 0xca, 0xc1,
+                    0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0xd3, 0xd4,
+                    0xf8ff, 0xd2, 0xda, 0xdb, 0xd9, 0x131, 0x2c6, 0x2dc,
+                    0xaf, 0x2d8, 0x2d9, 0x2da, 0xb8, 0x2dd, 0x2db, 0x2c7,
+                };
+
+                if (c >= 128) {
+                    c = macroman_table[c - 128];
+                }
+                keymap[scancode] = c;
+            }
+        }
+        SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
+        return;
+    }
+}
+
 void
 Cocoa_InitKeyboard(_THIS)
 {
@@ -345,13 +464,15 @@
     
     SDL_zero(keyboard);
     data->keyboard = SDL_AddKeyboard(&keyboard, -1);
+    UpdateKeymap(data);
     
     /* Set our own names for the platform-dependent but layout-independent keys */
-    SDL_SetKeyName(SDLK_KP_NUMLOCKCLEAR, "clear");
-    SDL_SetKeyName(SDLK_LALT, "left option");
-    SDL_SetKeyName(SDLK_LMETA, "left command");
-    SDL_SetKeyName(SDLK_RALT, "right option");
-    SDL_SetKeyName(SDLK_RMETA, "right command");
+    /* This key is NumLock on the MacBook keyboard. :) */
+    /*SDL_SetScancodeName(SDL_SCANCODE_NUMLOCKCLEAR, "Clear");*/
+    SDL_SetScancodeName(SDL_SCANCODE_LALT, "Left Option");
+    SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Command");
+    SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
+    SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
 }
 
 void
@@ -359,27 +480,30 @@
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     unsigned short scancode = [event keyCode];
-    SDLKey physicalKey;
+    SDL_scancode code;
     const char *text;
 
     if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
         /* see comments in SDL_cocoakeys.h */
         scancode = 60 - scancode;
     }
-    if (scancode < SDL_arraysize(macToSDLKey)) {
-        physicalKey = macToSDLKey[scancode];
+    if (scancode < SDL_arraysize(scancode_table)) {
+        code = scancode_table[scancode];
     }
     else {
         /* Hmm, does this ever happen?  If so, need to extend the keymap... */
-        physicalKey = SDLK_UNKNOWN;
+        code = SDL_SCANCODE_UNKNOWN;
     }
 
     switch ([event type]) {
     case NSKeyDown:
         if (![event isARepeat]) {
-            SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, (Uint8)scancode, physicalKey);
+            /* See if we need to rebuild the keyboard layout */
+            UpdateKeymap(data);
+
+            SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, code);
 #if 1
-            if (physicalKey == SDLK_UNKNOWN) {
+            if (code == SDL_SCANCODE_UNKNOWN) {
                 fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
             }
 #endif
@@ -395,7 +519,7 @@
         }
         break;
     case NSKeyUp:
-        SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, (Uint8)scancode, physicalKey);
+        SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, code);
         break;
     case NSFlagsChanged:
         /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */
@@ -406,128 +530,6 @@
     }
 }
 
-SDLKey
-Cocoa_GetLayoutKey(_THIS, SDLKey physicalKey)
-{
-    switch (physicalKey) {
-        /* Many of these keys would generate a character in the translation by keyboard layout, but an inappropriate one, so we catch them before. */
-        case SDLK_UNKNOWN:
-        case SDLK_RETURN:
-        case SDLK_ESCAPE:
-        case SDLK_BACKSPACE:
-        case SDLK_TAB:
-        case SDLK_SPACE:
-        case SDLK_CAPSLOCK:
-        case SDLK_F1:
-        case SDLK_F2:
-        case SDLK_F3:
-        case SDLK_F4:
-        case SDLK_F5:
-        case SDLK_F6:
-        case SDLK_F7:
-        case SDLK_F8:
-        case SDLK_F9:
-        case SDLK_F10:
-        case SDLK_F11:
-        case SDLK_F12:
-        case SDLK_PRINTSCREEN:
-        case SDLK_SCROLLLOCK:
-        case SDLK_PAUSE:
-        case SDLK_INSERT:
-        case SDLK_HOME:
-        case SDLK_PAGEUP:
-        case SDLK_DELETE:
-        case SDLK_END:
-        case SDLK_PAGEDOWN:
-        case SDLK_RIGHT:
-        case SDLK_LEFT:
-        case SDLK_DOWN:
-        case SDLK_UP:
-        case SDLK_KP_NUMLOCKCLEAR:
-        case SDLK_KP_ENTER:
-        case SDLK_APPLICATION:
-        case SDLK_POWER:
-        case SDLK_F13:
-        case SDLK_F14:
-        case SDLK_F15:
-        case SDLK_F16:
-        case SDLK_LCTRL:
-        case SDLK_LSHIFT:
-        case SDLK_LALT:
-        case SDLK_LMETA:
-        case SDLK_RCTRL:
-        case SDLK_RSHIFT:
-        case SDLK_RALT:
-        case SDLK_RMETA:
-            return physicalKey;
-        
-        /* For the rest, we try the translation first. */
-        default: {
-            UInt16 vkey = 0;
-            KeyboardLayoutRef layout;
-            KeyboardLayoutKind kind;
-            UInt32 keyboardType = LMGetKbdType();
-            
-            /* Look up pkey to get a Mac virtual key code - linear search isn't terribly efficient, this might have to be optimized. */
-            while (vkey < 128 && physicalKey != macToSDLKey[vkey]) vkey++;
-            if (vkey == 128) return physicalKey;
-            if ((vkey == 10 || vkey == 50) && KBGetLayoutType(keyboardType) == kKeyboardISO) vkey = 60 - vkey; /* see comments in SDL_cocoakeys.h */
-            
-            if (KLGetCurrentKeyboardLayout(&layout) != noErr) return physicalKey;
-            if (KLGetKeyboardLayoutProperty(layout, kKLKind, (const void **)&kind) != noErr) return physicalKey;
-            if (kind == kKLKCHRuchrKind || kind == kKLuchrKind) {
-                UniChar utf16String[4];
-                UInt32 deadKeyState = 0;
-                UniCharCount actualStringLength;
-                const UCKeyboardLayout *uchrData;
-                
-                if (KLGetKeyboardLayoutProperty(layout, kKLuchrData, (const void **)&uchrData) != noErr) return physicalKey;
-                if (UCKeyTranslate(uchrData, vkey, kUCKeyActionDisplay, 0, keyboardType, 0, &deadKeyState, 4, &actualStringLength, utf16String) != noErr) return physicalKey;
-                /* kUCKeyActionDisplay (instead of kUCKeyActionDown) seems to take care of dead keys, so no need to check for that case and simulate a second key press */
-                
-                if (actualStringLength == 0) return physicalKey;
-                
-                /* Decode the first character from UTF-16. I'm not sure if this is appropriate for keyboard layouts that generate more than 1 character, or if we would have to use SDL_KEY_LAYOUT_SPECIAL_BIT in that case. */
-                if (utf16String[0] < 0xD800 || utf16String[0] > 0xDFFF) {
-                    return utf16String[0];
-                }
-                else if (utf16String[0] > 0xDBFF || utf16String[1] < 0xDC00 || utf16String[1] > 0xDFFF) {
-                    /* invalid UTF-16 */
-                    return physicalKey;
-                }
-                else {
-                    return (((utf16String[0] & 0x3FF) << 10) | (utf16String[1] & 0x3FF)) + 0x10000;
-                }
-            }
-            else { /* kind == kKLKCHRKind */
-                const void *kchrData;
-                UInt32 state = 0;
-                UInt8 charCode;
-                SInt32 scriptCode;
-                TextEncoding keyboardEncoding;
-                CFStringRef conversionString;
-                UniChar codepoint;
-                
-                if (KLGetKeyboardLayoutProperty(layout, kKLKCHRData, &kchrData) != noErr) return physicalKey;
-                charCode = KeyTranslate(kchrData, vkey, &state) & 0xFF; /* Actually returns a UInt32 containing two character codes (and two 'reserved' bytes), but we're only interested in the second (or only) one */
-                if (charCode == 0) {
-                    /* It's a dead key, so simulate a second key press */
-                    charCode = KeyTranslate(kchrData, vkey, &state) & 0xFF;
-                    /* Still zero? Give up. */
-                    if (charCode == 0) return physicalKey;
-                }
-                if (KLGetKeyboardLayoutProperty(layout, kKLGroupIdentifier, (const void **)&scriptCode) != noErr) return physicalKey; /* That the group identifier is actually a script code is not documented, but confirmed here: <http://lists.apple.com/archives/carbon-dev/2005/Jan/msg00533.html> */
-                if (UpgradeScriptInfoToTextEncoding(scriptCode, kTextLanguageDontCare, kTextRegionDontCare, NULL, &keyboardEncoding) != noErr) return physicalKey;
-                
-                conversionString = CFStringCreateWithBytes(kCFAllocatorDefault, &charCode, 1, keyboardEncoding, FALSE);
-                codepoint = CFStringGetCharacterAtIndex(conversionString, 0);
-                CFRelease(conversionString);
-                return codepoint;
-            }
-        }
-    }
-}
-
 void
 Cocoa_QuitKeyboard(_THIS)
 {
--- a/src/video/cocoa/SDL_cocoakeys.h	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/video/cocoa/SDL_cocoakeys.h	Tue Feb 05 07:19:23 2008 +0000
@@ -27,134 +27,134 @@
    - experimentation on various ADB and USB ISO keyboards and one ADB ANSI keyboard
 */
 /* *INDENT-OFF* */
-static SDLKey macToSDLKey[128] = {
-    /*   0 */   SDLK_A,
-    /*   1 */   SDLK_S,
-    /*   2 */   SDLK_D,
-    /*   3 */   SDLK_F,
-    /*   4 */   SDLK_H,
-    /*   5 */   SDLK_G,
-    /*   6 */   SDLK_Z,
-    /*   7 */   SDLK_X,
-    /*   8 */   SDLK_C,
-    /*   9 */   SDLK_V,
-    /*  10 */   SDLK_NONUSBACKSLASH, /* SDLK_NONUSBACKSLASH on ANSI and JIS keyboards (if this key would exist there), SDLK_GRAVE on ISO. (The USB keyboard driver actually translates these usage codes to different virtual key codes depending on whether the keyboard is ISO/ANSI/JIS. That's why you have to help it identify the keyboard type when you plug in a PC USB keyboard. It's a historical thing - ADB keyboards are wired this way.) */
-    /*  11 */   SDLK_B,
-    /*  12 */   SDLK_Q,
-    /*  13 */   SDLK_W,
-    /*  14 */   SDLK_E,
-    /*  15 */   SDLK_R,
-    /*  16 */   SDLK_Y,
-    /*  17 */   SDLK_T,
-    /*  18 */   SDLK_1,
-    /*  19 */   SDLK_2,
-    /*  20 */   SDLK_3,
-    /*  21 */   SDLK_4,
-    /*  22 */   SDLK_6,
-    /*  23 */   SDLK_5,
-    /*  24 */   SDLK_EQUALS,
-    /*  25 */   SDLK_9,
-    /*  26 */   SDLK_7,
-    /*  27 */   SDLK_HYPHENMINUS,
-    /*  28 */   SDLK_8,
-    /*  29 */   SDLK_0,
-    /*  30 */   SDLK_RIGHTBRACKET,
-    /*  31 */   SDLK_O,
-    /*  32 */   SDLK_U,
-    /*  33 */   SDLK_LEFTBRACKET,
-    /*  34 */   SDLK_I,
-    /*  35 */   SDLK_P,
-    /*  36 */   SDLK_RETURN,
-    /*  37 */   SDLK_L,
-    /*  38 */   SDLK_J,
-    /*  39 */   SDLK_APOSTROPHE,
-    /*  40 */   SDLK_K,
-    /*  41 */   SDLK_SEMICOLON,
-    /*  42 */   SDLK_BACKSLASH,
-    /*  43 */   SDLK_COMMA,
-    /*  44 */   SDLK_SLASH,
-    /*  45 */   SDLK_N,
-    /*  46 */   SDLK_M,
-    /*  47 */   SDLK_PERIOD,
-    /*  48 */   SDLK_TAB,
-    /*  49 */   SDLK_SPACE,
-    /*  50 */   SDLK_GRAVE, /* SDLK_GRAVE on ANSI and JIS keyboards, SDLK_NONUSBACKSLASH on ISO (see comment about virtual key code 10 above) */
-    /*  51 */   SDLK_BACKSPACE,
-    /*  52 */   SDLK_KP_ENTER, /* keyboard enter on portables */
-    /*  53 */   SDLK_ESCAPE,
-    /*  54 */   SDLK_RMETA,
-    /*  55 */   SDLK_LMETA,
-    /*  56 */   SDLK_LSHIFT,
-    /*  57 */   SDLK_CAPSLOCK,
-    /*  58 */   SDLK_LALT,
-    /*  59 */   SDLK_LCTRL,
-    /*  60 */   SDLK_RSHIFT,
-    /*  61 */   SDLK_RALT,
-    /*  62 */   SDLK_RCTRL,
-    /*  63 */   SDLK_NONE, /* fn on portables, acts as a hardware-level modifier already, so we don't generate events for it */
-    /*  64 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /*  65 */   SDLK_KP_PERIOD,
-    /*  66 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /*  67 */   SDLK_KP_MULTIPLY,
-    /*  68 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /*  69 */   SDLK_KP_PLUS,
-    /*  70 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /*  71 */   SDLK_KP_NUMLOCKCLEAR,
-    /*  72 */   SDLK_VOLUMEUP,
-    /*  73 */   SDLK_VOLUMEDOWN,
-    /*  74 */   SDLK_MUTE,
-    /*  75 */   SDLK_KP_DIVIDE,
-    /*  76 */   SDLK_KP_ENTER, /* keypad enter on external keyboards, fn-return on portables */
-    /*  77 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /*  78 */   SDLK_KP_MINUS,
-    /*  79 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /*  80 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /*  81 */   SDLK_KP_EQUALS,
-    /*  82 */   SDLK_KP_0,
-    /*  83 */   SDLK_KP_1,
-    /*  84 */   SDLK_KP_2,
-    /*  85 */   SDLK_KP_3,
-    /*  86 */   SDLK_KP_4,
-    /*  87 */   SDLK_KP_5,
-    /*  88 */   SDLK_KP_6,
-    /*  89 */   SDLK_KP_7,
-    /*  90 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /*  91 */   SDLK_KP_8,
-    /*  92 */   SDLK_KP_9,
-    /*  93 */   SDLK_INTERNATIONAL3, /* Cosmo_USB2ADB.c says "Yen (JIS)" */
-    /*  94 */   SDLK_INTERNATIONAL1, /* Cosmo_USB2ADB.c says "Ro (JIS)" */
-    /*  95 */   SDLK_KP_COMMA, /* Cosmo_USB2ADB.c says ", JIS only" */
-    /*  96 */   SDLK_F5,
-    /*  97 */   SDLK_F6,
-    /*  98 */   SDLK_F7,
-    /*  99 */   SDLK_F3,
-    /* 100 */   SDLK_F8,
-    /* 101 */   SDLK_F9,
-    /* 102 */   SDLK_LANG2, /* Cosmo_USB2ADB.c says "Eisu" */
-    /* 103 */   SDLK_F11,
-    /* 104 */   SDLK_LANG1, /* Cosmo_USB2ADB.c says "Kana" */
-    /* 105 */   SDLK_PRINTSCREEN, /* On ADB keyboards, this key is labeled "F13/print screen". Problem: USB has different usage codes for these two functions. On Apple USB keyboards, the key is labeled "F13" and sends the F13 usage code (SDLK_F13). I decided to use SDLK_PRINTSCREEN here nevertheless since SDL applications are more likely to assume the presence of a print screen key than an F13 key. */
-    /* 106 */   SDLK_F16,
-    /* 107 */   SDLK_SCROLLLOCK, /* F14/scroll lock, see comment about F13/print screen above */
-    /* 108 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /* 109 */   SDLK_F10,
-    /* 110 */   SDLK_APPLICATION, /* windows contextual menu key, fn-enter on portables */
-    /* 111 */   SDLK_F12,
-    /* 112 */   SDLK_UNKNOWN, /* unknown (unused?) */
-    /* 113 */   SDLK_PAUSE, /* F15/pause, see comment about F13/print screen above */
-    /* 114 */   SDLK_INSERT, /* the key is actually labeled "help" on Apple keyboards, and works as such in Mac OS, but it sends the "insert" usage code even on Apple USB keyboards */
-    /* 115 */   SDLK_HOME,
-    /* 116 */   SDLK_PAGEUP,
-    /* 117 */   SDLK_DELETE,
-    /* 118 */   SDLK_F4,
-    /* 119 */   SDLK_END,
-    /* 120 */   SDLK_F2,
-    /* 121 */   SDLK_PAGEDOWN,
-    /* 122 */   SDLK_F1,
-    /* 123 */   SDLK_LEFT,
-    /* 124 */   SDLK_RIGHT,
-    /* 125 */   SDLK_DOWN,
-    /* 126 */   SDLK_UP,
-    /* 127 */   SDLK_POWER
+static SDL_scancode scancode_table[128] = {
+    /*   0 */   SDL_SCANCODE_A,
+    /*   1 */   SDL_SCANCODE_S,
+    /*   2 */   SDL_SCANCODE_D,
+    /*   3 */   SDL_SCANCODE_F,
+    /*   4 */   SDL_SCANCODE_H,
+    /*   5 */   SDL_SCANCODE_G,
+    /*   6 */   SDL_SCANCODE_Z,
+    /*   7 */   SDL_SCANCODE_X,
+    /*   8 */   SDL_SCANCODE_C,
+    /*   9 */   SDL_SCANCODE_V,
+    /*  10 */   SDL_SCANCODE_NONUSBACKSLASH, /* SDL_SCANCODE_NONUSBACKSLASH on ANSI and JIS keyboards (if this key would exist there), SDL_SCANCODE_GRAVE on ISO. (The USB keyboard driver actually translates these usage codes to different virtual key codes depending on whether the keyboard is ISO/ANSI/JIS. That's why you have to help it identify the keyboard type when you plug in a PC USB keyboard. It's a historical thing - ADB keyboards are wired this way.) */
+    /*  11 */   SDL_SCANCODE_B,
+    /*  12 */   SDL_SCANCODE_Q,
+    /*  13 */   SDL_SCANCODE_W,
+    /*  14 */   SDL_SCANCODE_E,
+    /*  15 */   SDL_SCANCODE_R,
+    /*  16 */   SDL_SCANCODE_Y,
+    /*  17 */   SDL_SCANCODE_T,
+    /*  18 */   SDL_SCANCODE_1,
+    /*  19 */   SDL_SCANCODE_2,
+    /*  20 */   SDL_SCANCODE_3,
+    /*  21 */   SDL_SCANCODE_4,
+    /*  22 */   SDL_SCANCODE_6,
+    /*  23 */   SDL_SCANCODE_5,
+    /*  24 */   SDL_SCANCODE_EQUALS,
+    /*  25 */   SDL_SCANCODE_9,
+    /*  26 */   SDL_SCANCODE_7,
+    /*  27 */   SDL_SCANCODE_HYPHENMINUS,
+    /*  28 */   SDL_SCANCODE_8,
+    /*  29 */   SDL_SCANCODE_0,
+    /*  30 */   SDL_SCANCODE_RIGHTBRACKET,
+    /*  31 */   SDL_SCANCODE_O,
+    /*  32 */   SDL_SCANCODE_U,
+    /*  33 */   SDL_SCANCODE_LEFTBRACKET,
+    /*  34 */   SDL_SCANCODE_I,
+    /*  35 */   SDL_SCANCODE_P,
+    /*  36 */   SDL_SCANCODE_RETURN,
+    /*  37 */   SDL_SCANCODE_L,
+    /*  38 */   SDL_SCANCODE_J,
+    /*  39 */   SDL_SCANCODE_APOSTROPHE,
+    /*  40 */   SDL_SCANCODE_K,
+    /*  41 */   SDL_SCANCODE_SEMICOLON,
+    /*  42 */   SDL_SCANCODE_BACKSLASH,
+    /*  43 */   SDL_SCANCODE_COMMA,
+    /*  44 */   SDL_SCANCODE_SLASH,
+    /*  45 */   SDL_SCANCODE_N,
+    /*  46 */   SDL_SCANCODE_M,
+    /*  47 */   SDL_SCANCODE_PERIOD,
+    /*  48 */   SDL_SCANCODE_TAB,
+    /*  49 */   SDL_SCANCODE_SPACE,
+    /*  50 */   SDL_SCANCODE_GRAVE, /* SDL_SCANCODE_GRAVE on ANSI and JIS keyboards, SDL_SCANCODE_NONUSBACKSLASH on ISO (see comment about virtual key code 10 above) */
+    /*  51 */   SDL_SCANCODE_BACKSPACE,
+    /*  52 */   SDL_SCANCODE_KP_ENTER, /* keyboard enter on portables */
+    /*  53 */   SDL_SCANCODE_ESCAPE,
+    /*  54 */   SDL_SCANCODE_RGUI,
+    /*  55 */   SDL_SCANCODE_LGUI,
+    /*  56 */   SDL_SCANCODE_LSHIFT,
+    /*  57 */   SDL_SCANCODE_CAPSLOCK,
+    /*  58 */   SDL_SCANCODE_LALT,
+    /*  59 */   SDL_SCANCODE_LCTRL,
+    /*  60 */   SDL_SCANCODE_RSHIFT,
+    /*  61 */   SDL_SCANCODE_RALT,
+    /*  62 */   SDL_SCANCODE_RCTRL,
+    /*  63 */   SDL_SCANCODE_UNKNOWN, /* fn on portables, acts as a hardware-level modifier already, so we don't generate events for it */
+    /*  64 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /*  65 */   SDL_SCANCODE_KP_PERIOD,
+    /*  66 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /*  67 */   SDL_SCANCODE_KP_MULTIPLY,
+    /*  68 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /*  69 */   SDL_SCANCODE_KP_PLUS,
+    /*  70 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /*  71 */   SDL_SCANCODE_NUMLOCKCLEAR,
+    /*  72 */   SDL_SCANCODE_VOLUMEUP,
+    /*  73 */   SDL_SCANCODE_VOLUMEDOWN,
+    /*  74 */   SDL_SCANCODE_MUTE,
+    /*  75 */   SDL_SCANCODE_KP_DIVIDE,
+    /*  76 */   SDL_SCANCODE_KP_ENTER, /* keypad enter on external keyboards, fn-return on portables */
+    /*  77 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /*  78 */   SDL_SCANCODE_KP_MINUS,
+    /*  79 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /*  80 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /*  81 */   SDL_SCANCODE_KP_EQUALS,
+    /*  82 */   SDL_SCANCODE_KP_0,
+    /*  83 */   SDL_SCANCODE_KP_1,
+    /*  84 */   SDL_SCANCODE_KP_2,
+    /*  85 */   SDL_SCANCODE_KP_3,
+    /*  86 */   SDL_SCANCODE_KP_4,
+    /*  87 */   SDL_SCANCODE_KP_5,
+    /*  88 */   SDL_SCANCODE_KP_6,
+    /*  89 */   SDL_SCANCODE_KP_7,
+    /*  90 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /*  91 */   SDL_SCANCODE_KP_8,
+    /*  92 */   SDL_SCANCODE_KP_9,
+    /*  93 */   SDL_SCANCODE_INTERNATIONAL3, /* Cosmo_USB2ADB.c says "Yen (JIS)" */
+    /*  94 */   SDL_SCANCODE_INTERNATIONAL1, /* Cosmo_USB2ADB.c says "Ro (JIS)" */
+    /*  95 */   SDL_SCANCODE_KP_COMMA, /* Cosmo_USB2ADB.c says ", JIS only" */
+    /*  96 */   SDL_SCANCODE_F5,
+    /*  97 */   SDL_SCANCODE_F6,
+    /*  98 */   SDL_SCANCODE_F7,
+    /*  99 */   SDL_SCANCODE_F3,
+    /* 100 */   SDL_SCANCODE_F8,
+    /* 101 */   SDL_SCANCODE_F9,
+    /* 102 */   SDL_SCANCODE_LANG2, /* Cosmo_USB2ADB.c says "Eisu" */
+    /* 103 */   SDL_SCANCODE_F11,
+    /* 104 */   SDL_SCANCODE_LANG1, /* Cosmo_USB2ADB.c says "Kana" */
+    /* 105 */   SDL_SCANCODE_PRINTSCREEN, /* On ADB keyboards, this key is labeled "F13/print screen". Problem: USB has different usage codes for these two functions. On Apple USB keyboards, the key is labeled "F13" and sends the F13 usage code (SDL_SCANCODE_F13). I decided to use SDL_SCANCODE_PRINTSCREEN here nevertheless since SDL applications are more likely to assume the presence of a print screen key than an F13 key. */
+    /* 106 */   SDL_SCANCODE_F16,
+    /* 107 */   SDL_SCANCODE_SCROLLLOCK, /* F14/scroll lock, see comment about F13/print screen above */
+    /* 108 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /* 109 */   SDL_SCANCODE_F10,
+    /* 110 */   SDL_SCANCODE_APPLICATION, /* windows contextual menu key, fn-enter on portables */
+    /* 111 */   SDL_SCANCODE_F12,
+    /* 112 */   SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+    /* 113 */   SDL_SCANCODE_PAUSE, /* F15/pause, see comment about F13/print screen above */
+    /* 114 */   SDL_SCANCODE_INSERT, /* the key is actually labeled "help" on Apple keyboards, and works as such in Mac OS, but it sends the "insert" usage code even on Apple USB keyboards */
+    /* 115 */   SDL_SCANCODE_HOME,
+    /* 116 */   SDL_SCANCODE_PAGEUP,
+    /* 117 */   SDL_SCANCODE_DELETE,
+    /* 118 */   SDL_SCANCODE_F4,
+    /* 119 */   SDL_SCANCODE_END,
+    /* 120 */   SDL_SCANCODE_F2,
+    /* 121 */   SDL_SCANCODE_PAGEDOWN,
+    /* 122 */   SDL_SCANCODE_F1,
+    /* 123 */   SDL_SCANCODE_LEFT,
+    /* 124 */   SDL_SCANCODE_RIGHT,
+    /* 125 */   SDL_SCANCODE_DOWN,
+    /* 126 */   SDL_SCANCODE_UP,
+    /* 127 */   SDL_SCANCODE_POWER
 };
 /* *INDENT-ON* */
--- a/src/video/cocoa/SDL_cocoavideo.h	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/video/cocoa/SDL_cocoavideo.h	Tue Feb 05 07:19:23 2008 +0000
@@ -45,6 +45,7 @@
     unsigned int modifierFlags;
     int mouse;
     int keyboard;
+    void *key_layout;
     NSText *fieldEdit;
 } SDL_VideoData;
 
--- a/src/video/cocoa/SDL_cocoavideo.m	Mon Feb 04 17:25:33 2008 +0000
+++ b/src/video/cocoa/SDL_cocoavideo.m	Tue Feb 05 07:19:23 2008 +0000
@@ -75,7 +75,6 @@
     device->GetDisplayModes = Cocoa_GetDisplayModes;
     device->SetDisplayMode = Cocoa_SetDisplayMode;
     device->PumpEvents = Cocoa_PumpEvents;
-    device->GetLayoutKey = Cocoa_GetLayoutKey;
 
     device->CreateWindow = Cocoa_CreateWindow;
     device->CreateWindowFrom = Cocoa_CreateWindowFrom;
--- a/test/checkkeys.c	Mon Feb 04 17:25:33 2008 +0000
+++ b/test/checkkeys.c	Tue Feb 05 07:19:23 2008 +0000
@@ -40,10 +40,10 @@
         printf(" LALT");
     if (mod & KMOD_RALT)
         printf(" RALT");
-    if (mod & KMOD_LMETA)
-        printf(" LMETA");
-    if (mod & KMOD_RMETA)
-        printf(" RMETA");
+    if (mod & KMOD_LGUI)
+        printf(" LGUI");
+    if (mod & KMOD_RGUI)
+        printf(" RGUI");
     if (mod & KMOD_NUM)
         printf(" NUM");
     if (mod & KMOD_CAPS)
@@ -57,14 +57,13 @@
 {
     /* Print the keycode, name and state */
     if (sym->sym) {
-        printf("Key %s:  physical 0x%08X = %s, layout 0x%08X = %s ",
+        printf("Key %s:  scancode 0x%04X = %s, keycode 0x%08X = %s ",
                pressed ? "pressed " : "released",
-               sym->sym,
-               SDL_GetKeyName(sym->sym),
-               SDL_GetLayoutKey(sym->sym),
-               SDL_GetKeyName(SDL_GetLayoutKey(sym->sym)));
+               sym->scancode,
+               SDL_GetScancodeName(sym->scancode),
+               sym->sym, SDL_GetKeyName(sym->sym));
     } else {
-        printf("Unknown Key (scancode = 0x%08X) %s ",
+        printf("Unknown Key (scancode = 0x%04X) %s ",
                sym->scancode, pressed ? "pressed" : "released");
     }