Date: Thu, 05 Jul 2007 14:02:33 -0700
authorSam Lantinga <slouken@libsdl.org>
Sun, 19 Aug 2007 14:52:52 +0000
changeset 22684baee598306d
parent 2267 c785543d1843
child 2269 5b826389e298
Date: Thu, 05 Jul 2007 14:02:33 -0700
From: Sam Lantinga
Subject: SDL 1.3 keyboard plan

After lots of discussion with Christian, this is what we came up with:

> So, to sum up...
> SDLK_* become the physical keys, starting at > (1<<21)
> We create a macro SDLK_INDEX(X)
> We have two functions SDL_GetLayoutKey(SDLKey) and SDL_GetKeyName()
> SDL_GetLayoutKey maps to UCS4 for printable characters, and SDLK* for
non-printable characters
> and does so based on the OS's current keyboard layout
> SDL_GetKeyName() handles both SDLK_* and UCS4, converting UCS4 to UTF-8 and
converting SDLK_* into our names, which are UTF-8 for printable characters.
> WASD folks use SDLK_*, and 'I' folks use SDL_GetLayoutKey(SDLK_*)

Here is the patch he came up with, and his e-mail about it:

Date: Fri, 17 Aug 2007 19:50:28 +0200
From: Christian Walther
Subject: Re: SDL 1.3 keyboard plan

> Sounds great, go ahead and send me a patch.

Here goes! Thanks for having a look. Don't hesitate to comment if
anything does not conform to your ideas.

One caveat: Committing this now may break compilability of some video
drivers - specifically, if they use any of the SDLK_* codes that were
obsoleted and moved into SDL_compat.h. I only tried Cocoa (which did
break, but is already fixed) and X11 (which didn't, but then its key
handling is #iffed out). If that's a problem, it may need to go into
a branch.

-Christian
include/SDL_compat.h
include/SDL_keyboard.h
include/SDL_keysym.h
src/events/SDL_keyboard.c
src/events/SDL_keyboard_c.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/common.c
     1.1 --- a/include/SDL_compat.h	Sat Aug 18 05:39:09 2007 +0000
     1.2 +++ b/include/SDL_compat.h	Sun Aug 19 14:52:52 2007 +0000
     1.3 @@ -130,6 +130,87 @@
     1.4  
     1.5  struct SDL_SysWMinfo;
     1.6  
     1.7 +/* Key codes
     1.8 +   Note that the correspondences defined here are approximate at best because
     1.9 +   the meaning of the event structure field that carries these values has
    1.10 +   changed: in SDL 1.2, it referred to the key's label in the current keyboard
    1.11 +   layout, whereas now it refers to a specific physical key on the keyboard,
    1.12 +   regardless of the keyboard layout setting.
    1.13 +   To get comparable behavior to SDL 1.2, code that uses any of the codes below
    1.14 +   in ways like "if (somekey == SDLK_EXCLAIM)" should be changed to the
    1.15 +   equivalent of "if (SDL_GetLayoutKey(somekey) == '!')".
    1.16 + */
    1.17 +
    1.18 +/* These key constants were renamed for clarity or consistence. */
    1.19 +#define SDLK_QUOTE SDLK_APOSTROPHE
    1.20 +#define SDLK_MINUS SDLK_HYPHENMINUS
    1.21 +#define SDLK_BACKQUOTE SDLK_GRAVE
    1.22 +#define SDLK_a SDLK_A
    1.23 +#define SDLK_b SDLK_B
    1.24 +#define SDLK_c SDLK_C
    1.25 +#define SDLK_d SDLK_D
    1.26 +#define SDLK_e SDLK_E
    1.27 +#define SDLK_f SDLK_F
    1.28 +#define SDLK_g SDLK_G
    1.29 +#define SDLK_h SDLK_H
    1.30 +#define SDLK_i SDLK_I
    1.31 +#define SDLK_j SDLK_J
    1.32 +#define SDLK_k SDLK_K
    1.33 +#define SDLK_l SDLK_L
    1.34 +#define SDLK_m SDLK_M
    1.35 +#define SDLK_n SDLK_N
    1.36 +#define SDLK_o SDLK_O
    1.37 +#define SDLK_p SDLK_P
    1.38 +#define SDLK_q SDLK_Q
    1.39 +#define SDLK_r SDLK_R
    1.40 +#define SDLK_s SDLK_S
    1.41 +#define SDLK_t SDLK_T
    1.42 +#define SDLK_u SDLK_U
    1.43 +#define SDLK_v SDLK_V
    1.44 +#define SDLK_w SDLK_W
    1.45 +#define SDLK_x SDLK_X
    1.46 +#define SDLK_y SDLK_Y
    1.47 +#define SDLK_z SDLK_Z
    1.48 +#define SDLK_KP0 SDLK_KP_0
    1.49 +#define SDLK_KP1 SDLK_KP_1
    1.50 +#define SDLK_KP2 SDLK_KP_2
    1.51 +#define SDLK_KP3 SDLK_KP_3
    1.52 +#define SDLK_KP4 SDLK_KP_4
    1.53 +#define SDLK_KP5 SDLK_KP_5
    1.54 +#define SDLK_KP6 SDLK_KP_6
    1.55 +#define SDLK_KP7 SDLK_KP_7
    1.56 +#define SDLK_KP8 SDLK_KP_8
    1.57 +#define SDLK_KP9 SDLK_KP_9
    1.58 +#define SDLK_NUMLOCK SDLK_KP_NUMLOCKCLEAR
    1.59 +#define SDLK_SCROLLOCK SDLK_SCROLLLOCK
    1.60 +#define SDLK_PRINT SDLK_PRINTSCREEN
    1.61 +
    1.62 +/* These key constants are obsoleted the new keyboard handling, their definitions here correspond to how they appear on a US keyboard. */
    1.63 +#define SDLK_EXCLAIM SDLK_1
    1.64 +#define SDLK_QUOTEDBL SDLK_APOSTROPHE
    1.65 +#define SDLK_HASH SDLK_3
    1.66 +#define SDLK_DOLLAR SDLK_4
    1.67 +#define SDLK_AMPERSAND SDLK_7
    1.68 +#define SDLK_LEFTPAREN SDLK_9
    1.69 +#define SDLK_RIGHTPAREN SDLK_0
    1.70 +#define SDLK_ASTERISK SDLK_8
    1.71 +#define SDLK_PLUS SDLK_EQUALS
    1.72 +#define SDLK_COLON SDLK_SEMICOLON
    1.73 +#define SDLK_LESS SDLK_COMMA
    1.74 +#define SDLK_GREATER SDLK_PERIOD
    1.75 +#define SDLK_QUESTION SDLK_SLASH
    1.76 +#define SDLK_AT SDLK_2
    1.77 +#define SDLK_CARET SDLK_6
    1.78 +#define SDLK_UNDERSCORE SDLK_HYPHENMINUS
    1.79 +
    1.80 +/* 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. */
    1.81 +#define SDLK_LSUPER SDLK_LMETA
    1.82 +#define SDLK_RSUPER SDLK_RMETA
    1.83 +#define SDLK_COMPOSE SDLK_APPLICATION
    1.84 +#define SDLK_BREAK SDLK_STOP
    1.85 +#define SDLK_EURO SDLK_2
    1.86 +
    1.87 +
    1.88  #define SDL_SetModuleHandle(x)
    1.89  #define SDL_AllocSurface    SDL_CreateRGBSurface
    1.90  
     2.1 --- a/include/SDL_keyboard.h	Sat Aug 18 05:39:09 2007 +0000
     2.2 +++ b/include/SDL_keyboard.h	Sun Aug 19 14:52:52 2007 +0000
     2.3 @@ -50,7 +50,7 @@
     2.4  {
     2.5      Uint8 scancode;             /**< keyboard specific scancode */
     2.6      Uint8 padding[3];           /**< alignment padding */
     2.7 -    Uint16 sym;                 /**< SDL virtual keysym */
     2.8 +    SDLKey sym;                 /**< SDL virtual key code - see ::SDLKey for details */
     2.9      Uint16 mod;                 /**< current key modifiers */
    2.10      Uint32 unicode;             /**< OBSOLETE, use SDL_TextInputEvent instead */
    2.11  } SDL_keysym;
    2.12 @@ -97,11 +97,13 @@
    2.13   *
    2.14   * \brief Get a snapshot of the current state of the selected keyboard.
    2.15   *
    2.16 - * \return An array of keystates, indexed by the SDLK_* syms.
    2.17 + * \param numkeys if non-NULL, receives the length of the returned array.
    2.18 + *
    2.19 + * \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.
    2.20   *
    2.21   * Example:
    2.22   * 	Uint8 *keystate = SDL_GetKeyState(NULL);
    2.23 - *	if ( keystate[SDLK_RETURN] ) ... <RETURN> is pressed.
    2.24 + *	if ( keystate[SDLK_INDEX(SDLK_RETURN)] ) ... <RETURN> is pressed.
    2.25   */
    2.26  extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyState(int *numkeys);
    2.27  
    2.28 @@ -122,11 +124,32 @@
    2.29  extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);
    2.30  
    2.31  /**
    2.32 - * \fn const char *SDL_GetKeyName(SDLKey key)
    2.33 + * \fn SDLKey SDL_GetLayoutKey(SDLKey physicalKey)
    2.34   * 
    2.35 - * \brief Get the name of an SDL virtual keysym
    2.36 + * \brief Get the layout key code corresponding to the given physical key code according to the current keyboard layout.
    2.37 + *
    2.38 + * See ::SDLKey for details.
    2.39 + *
    2.40 + * If \a physicalKey is not a physical key code, it is returned unchanged.
    2.41 + *
    2.42 + * \sa SDL_GetKeyName()
    2.43   */
    2.44 -extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);
    2.45 +extern DECLSPEC SDLKey SDLCALL SDL_GetLayoutKey(SDLKey physicalKey);
    2.46 +
    2.47 +/**
    2.48 + * \fn const char *SDL_GetKeyName(SDLKey layoutKey)
    2.49 + * 
    2.50 + * \brief Get a human-readable name for a key.
    2.51 + *
    2.52 + * \param layoutKey An SDL layout key code.
    2.53 + *
    2.54 + * 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.
    2.55 + *
    2.56 + * \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.
    2.57 + *
    2.58 + * \sa SDLKey
    2.59 + */
    2.60 +extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey layoutKey);
    2.61  
    2.62  
    2.63  /* Ends C function definitions when using C++ */
     3.1 --- a/include/SDL_keysym.h	Sat Aug 18 05:39:09 2007 +0000
     3.2 +++ b/include/SDL_keysym.h	Sun Aug 19 14:52:52 2007 +0000
     3.3 @@ -27,175 +27,412 @@
     3.4  #ifndef _SDL_keysym_h
     3.5  #define _SDL_keysym_h
     3.6  
     3.7 +#include "SDL_stdinc.h"
     3.8 +
     3.9  /**
    3.10 - * \enum SDLKey
    3.11 + * \typedef SDLKey
    3.12 + *
    3.13 + * \brief The SDL virtual key representation.
    3.14 + *
    3.15 + * Values of this type are used to represent keyboard keys, among other places
    3.16 + * in the \link SDL_keysym::sym key.keysym.sym \endlink field of the SDL_Event
    3.17 + * structure.
    3.18 + *
    3.19 + * There are two fundamental ways of referring to a key: First, a certain code
    3.20 + * can stand for a key at a specific physical location on the keyboard,
    3.21 + * independent of its label or what character it generates. These are the \e
    3.22 + * physical key codes, comparable to the raw hardware scancodes that a keyboard
    3.23 + * generates. Second, a code can refer to a key with a specific label,
    3.24 + * generating a specific character or performing a specific function, which may
    3.25 + * be located at different places on the keyboard, or not exist at all,
    3.26 + * depending on what keyboard layout is used. These are \e layout key codes.
    3.27   *
    3.28 - * \brief The SDL virtual key representation
    3.29 + * There is a certain overlap between the sets of physical key codes and layout
    3.30 + * key codes: \e return, \e tab, \e ctrl etc. are typically independent of the
    3.31 + * keyboard layout and can be thought of as either a physical or a layout key.
    3.32 + * Therefore, rather than having separate types with separate sets of constants
    3.33 + * for physical keys and layout keys, a single type ::SDLKey is used for both
    3.34 + * sets. The physical key codes (forming a well-known set of a few hundred
    3.35 + * elements) are enumerated in enum ::SDLPhysicalKey. The set of layout key
    3.36 + * codes is more diverse: For keys that don't generate characters, the layout
    3.37 + * key code is equal to the physical key code, i.e. the same SDLK_* constants
    3.38 + * from enum ::SDLPhysicalKey are used. For character keys, the layout key code
    3.39 + * is equal to the Unicode code point of the character that is generated when
    3.40 + * the key is pressed without shift or any other modifiers (for ASCII
    3.41 + * characters, this can be directly written as a character literal like
    3.42 + * <tt>'x'</tt>).
    3.43 + *
    3.44 + * The \link SDL_keysym::sym key.keysym.sym \endlink field of the SDL_Event
    3.45 + * structure is always a physical key code. To get the layout key code for the
    3.46 + * event, run that physical key code through SDL_GetLayoutKey(), which converts
    3.47 + * it to a layout key code according to the current keyboard layout settings of
    3.48 + * the OS. In particular, this is what should be done when displaying the name
    3.49 + * of a key to the user: use
    3.50 + * <tt>SDL_GetKeyName(SDL_GetLayoutKey(myPhysicalKeyCode))</tt>. Do not use
    3.51 + * SDL_GetKeyName() directly on a physical key code (except for debugging
    3.52 + * purposes), as the name returned by that will not correspond to how the key
    3.53 + * is labeled on the user's keyboard.
    3.54   *
    3.55 - * The SDLKey represents the unmodified character printed on the key
    3.56 - * for the current keyboard layout.  The first 255 characters are used
    3.57 - * unchanged from Latin-1, e.g. a key with 'a' on it will have the value "a".
    3.58 - * The rest of the keys are named below, and fall into the range above 255.
    3.59 + * \par Example:
    3.60 + * To implement WASD directional keys, it makes sense to use physical key
    3.61 + * codes, so that the "forward" key will be above the "backward" key even
    3.62 + * though, for example, it's labeled "Z", not "W", on a French keyboard:
    3.63 + * \code
    3.64 + * print("To go forward, press the %s key.", SDL_GetKeyName(SDL_GetLayoutKey(SDLK_W)));
    3.65 + * ...
    3.66 + * switch (event.key.keysym.sym) {
    3.67 + *     case SDLK_W:
    3.68 + *         forward();
    3.69 + *         break;
    3.70 + *     case SDLK_A:
    3.71 + *         left();
    3.72 + *         break;
    3.73 + *     ...
    3.74 + * }
    3.75 + * \endcode
    3.76 + * For keys based on mnemonics like "I for inventory" or "Z for zoom", use
    3.77 + * layout key codes, so that the key labeled "Z" will zoom, whether it's at the
    3.78 + * bottom left of the keyboard like on a US layout, or in the upper center like
    3.79 + * on a German layout (but keep in mind that this forces your users to use a
    3.80 + * keyboard layout where there \e is an I or Z key):
    3.81 + * \code
    3.82 + * print("To open the inventory, press the %s key.", SDL_GetKeyName('i'));
    3.83 + * ...
    3.84 + * switch (SDL_GetLayoutKey(event.key.keysym.sym)) {
    3.85 + *     case 'i':
    3.86 + *         inventory();
    3.87 + *         break;
    3.88 + *     case 'z':
    3.89 + *         zoom();
    3.90 + *         break;
    3.91 + *     ...
    3.92 + * }
    3.93 + * \endcode
    3.94 + * Of course, in a real application, you should not hardcode your key
    3.95 + * assignments like this, but make them user-configurable.
    3.96   */
    3.97 -typedef enum
    3.98 +typedef Uint32 SDLKey;
    3.99 +
   3.100 +#define SDL_KEY_CAN_BE_PHYSICAL_BIT (1<<24)     /* marks SDLKeys from the "physical" set (some of these are also in the "layout" set) */
   3.101 +#define SDL_KEY_KEYPAD_BIT (1<<25)      /* marks keypad keys that need [] around their name to distinguish them from the corresponding keyboard keys */
   3.102 +#define SDL_KEY_LAYOUT_SPECIAL_BIT (1<<26)      /* marks non-physical layout keys that cannot be described by a single character */
   3.103 +
   3.104 +/** Converts an \link ::SDLPhysicalKey SDLK_* \endlink constant to an index into the array obtained from SDL_GetKeyState(). */
   3.105 +#define SDLK_INDEX(k) ((k) & 0x00FFFFFF)
   3.106 +
   3.107 +#define SDL_PHYSICAL_KEY(n) ((n) | SDL_KEY_CAN_BE_PHYSICAL_BIT)
   3.108 +
   3.109 +/**
   3.110 + * \brief SDL physical key codes.
   3.111 + *
   3.112 + * This is the set of physical key codes, i.e. the values of SDL_keysym::sym.
   3.113 + * Some of them (those for non-character keys) also appear as layout key codes.
   3.114 + * The constants are typically named after how the key would be labeled on a US
   3.115 + * keyboard, e.g. SDLK_A or SDLK_LEFTBRACKET refer to the keys used as A and [
   3.116 + * on a US layout, but used as Q and ^ on a French layout.
   3.117 + *
   3.118 + * <em>enum SDLPhysicalKey</em> is not a useful type in its own right - the
   3.119 + * constants defined here are intended as values of the ::SDLKey type. The only
   3.120 + * reason for the enum to have a name at all is that otherwise it would be
   3.121 + * impossible to refer to it in the documentation.
   3.122 + *
   3.123 + * \sa SDLKey
   3.124 + *
   3.125 + * \par Notes for driver implementors:
   3.126 + * These constants and their numerical values are based on the USB HID usage
   3.127 + * tables, version 1.12
   3.128 + * <http://www.usb.org/developers/devclass_docs/Hut1_12.pdf>, section "10
   3.129 + * Keyboard/Keypad Page (0x07)". When deciding what code to generate for what
   3.130 + * key, the following rules can be used as guidelines:
   3.131 + * - A given key on a given keyboard should produce the same SDLK_* code, no
   3.132 + * matter what computer it is connected to, what OS runs on that computer, and
   3.133 + * what the keyboard layout settings in the OS are. For USB keyboards, that
   3.134 + * should be the code numerically corresponding to the key's USB usage code
   3.135 + * (with exceptions, see comments for specific constants).
   3.136 + * - Two keys on two different keyboards are considered "the same key" and
   3.137 + * should generate the same SDLK_* code if, when connected to the same
   3.138 + * computer, they are treated equally by the OS. For USB keyboards, that's
   3.139 + * generally the case when they generate the same USB usage code. Non-USB
   3.140 + * keyboards can probably be treated like USB keyboards of the same layout, if
   3.141 + * such exist. If not, and there's no possibility to determine the equivalence
   3.142 + * relation by transitivity from the above - in particular, on devices like
   3.143 + * phones or game consoles that don't have PC-style alphabetic keyboards -
   3.144 + * apply common sense. If none of the predefined codes fit, insert new ones at
   3.145 + * the end.
   3.146 + */
   3.147 +enum SDLPhysicalKey
   3.148  {
   3.149 -    /* The keyboard syms have been cleverly chosen to map to ASCII */
   3.150 -    SDLK_UNKNOWN = 0,
   3.151 -    SDLK_FIRST = 0,
   3.152 -    SDLK_BACKSPACE = 8,
   3.153 -    SDLK_TAB = 9,
   3.154 -    SDLK_CLEAR = 12,
   3.155 -    SDLK_RETURN = 13,
   3.156 -    SDLK_PAUSE = 19,
   3.157 -    SDLK_ESCAPE = 27,
   3.158 -    SDLK_SPACE = 32,
   3.159 -    SDLK_EXCLAIM = 33,
   3.160 -    SDLK_QUOTEDBL = 34,
   3.161 -    SDLK_HASH = 35,
   3.162 -    SDLK_DOLLAR = 36,
   3.163 -    SDLK_AMPERSAND = 38,
   3.164 -    SDLK_QUOTE = 39,
   3.165 -    SDLK_LEFTPAREN = 40,
   3.166 -    SDLK_RIGHTPAREN = 41,
   3.167 -    SDLK_ASTERISK = 42,
   3.168 -    SDLK_PLUS = 43,
   3.169 -    SDLK_COMMA = 44,
   3.170 -    SDLK_MINUS = 45,
   3.171 -    SDLK_PERIOD = 46,
   3.172 -    SDLK_SLASH = 47,
   3.173 -    SDLK_0 = 48,
   3.174 -    SDLK_1 = 49,
   3.175 -    SDLK_2 = 50,
   3.176 -    SDLK_3 = 51,
   3.177 -    SDLK_4 = 52,
   3.178 -    SDLK_5 = 53,
   3.179 -    SDLK_6 = 54,
   3.180 -    SDLK_7 = 55,
   3.181 -    SDLK_8 = 56,
   3.182 -    SDLK_9 = 57,
   3.183 -    SDLK_COLON = 58,
   3.184 -    SDLK_SEMICOLON = 59,
   3.185 -    SDLK_LESS = 60,
   3.186 -    SDLK_EQUALS = 61,
   3.187 -    SDLK_GREATER = 62,
   3.188 -    SDLK_QUESTION = 63,
   3.189 -    SDLK_AT = 64,
   3.190 -    /* 
   3.191 -       Skip uppercase letters
   3.192 -     */
   3.193 -    SDLK_LEFTBRACKET = 91,
   3.194 -    SDLK_BACKSLASH = 92,
   3.195 -    SDLK_RIGHTBRACKET = 93,
   3.196 -    SDLK_CARET = 94,
   3.197 -    SDLK_UNDERSCORE = 95,
   3.198 -    SDLK_BACKQUOTE = 96,
   3.199 -    SDLK_a = 97,
   3.200 -    SDLK_b = 98,
   3.201 -    SDLK_c = 99,
   3.202 -    SDLK_d = 100,
   3.203 -    SDLK_e = 101,
   3.204 -    SDLK_f = 102,
   3.205 -    SDLK_g = 103,
   3.206 -    SDLK_h = 104,
   3.207 -    SDLK_i = 105,
   3.208 -    SDLK_j = 106,
   3.209 -    SDLK_k = 107,
   3.210 -    SDLK_l = 108,
   3.211 -    SDLK_m = 109,
   3.212 -    SDLK_n = 110,
   3.213 -    SDLK_o = 111,
   3.214 -    SDLK_p = 112,
   3.215 -    SDLK_q = 113,
   3.216 -    SDLK_r = 114,
   3.217 -    SDLK_s = 115,
   3.218 -    SDLK_t = 116,
   3.219 -    SDLK_u = 117,
   3.220 -    SDLK_v = 118,
   3.221 -    SDLK_w = 119,
   3.222 -    SDLK_x = 120,
   3.223 -    SDLK_y = 121,
   3.224 -    SDLK_z = 122,
   3.225 -    SDLK_DELETE = 127,
   3.226 -    /* End of ASCII mapped keysyms */
   3.227 +    SDLK_FIRST_PHYSICAL = 0, /**< (not a key, just marks the lowest used value in this enum) */
   3.228 +    SDLK_NONE = SDL_PHYSICAL_KEY(0),
   3.229 +    SDLK_UNKNOWN = SDL_PHYSICAL_KEY(1), /* Not from the USB spec, but this is a convenient place for it */
   3.230 +
   3.231 +    SDLK_A = SDL_PHYSICAL_KEY(4),
   3.232 +    SDLK_B = SDL_PHYSICAL_KEY(5),
   3.233 +    SDLK_C = SDL_PHYSICAL_KEY(6),
   3.234 +    SDLK_D = SDL_PHYSICAL_KEY(7),
   3.235 +    SDLK_E = SDL_PHYSICAL_KEY(8),
   3.236 +    SDLK_F = SDL_PHYSICAL_KEY(9),
   3.237 +    SDLK_G = SDL_PHYSICAL_KEY(10),
   3.238 +    SDLK_H = SDL_PHYSICAL_KEY(11),
   3.239 +    SDLK_I = SDL_PHYSICAL_KEY(12),
   3.240 +    SDLK_J = SDL_PHYSICAL_KEY(13),
   3.241 +    SDLK_K = SDL_PHYSICAL_KEY(14),
   3.242 +    SDLK_L = SDL_PHYSICAL_KEY(15),
   3.243 +    SDLK_M = SDL_PHYSICAL_KEY(16),
   3.244 +    SDLK_N = SDL_PHYSICAL_KEY(17),
   3.245 +    SDLK_O = SDL_PHYSICAL_KEY(18),
   3.246 +    SDLK_P = SDL_PHYSICAL_KEY(19),
   3.247 +    SDLK_Q = SDL_PHYSICAL_KEY(20),
   3.248 +    SDLK_R = SDL_PHYSICAL_KEY(21),
   3.249 +    SDLK_S = SDL_PHYSICAL_KEY(22),
   3.250 +    SDLK_T = SDL_PHYSICAL_KEY(23),
   3.251 +    SDLK_U = SDL_PHYSICAL_KEY(24),
   3.252 +    SDLK_V = SDL_PHYSICAL_KEY(25),
   3.253 +    SDLK_W = SDL_PHYSICAL_KEY(26),
   3.254 +    SDLK_X = SDL_PHYSICAL_KEY(27),
   3.255 +    SDLK_Y = SDL_PHYSICAL_KEY(28),
   3.256 +    SDLK_Z = SDL_PHYSICAL_KEY(29),
   3.257 +
   3.258 +    SDLK_1 = SDL_PHYSICAL_KEY(30),
   3.259 +    SDLK_2 = SDL_PHYSICAL_KEY(31),
   3.260 +    SDLK_3 = SDL_PHYSICAL_KEY(32),
   3.261 +    SDLK_4 = SDL_PHYSICAL_KEY(33),
   3.262 +    SDLK_5 = SDL_PHYSICAL_KEY(34),
   3.263 +    SDLK_6 = SDL_PHYSICAL_KEY(35),
   3.264 +    SDLK_7 = SDL_PHYSICAL_KEY(36),
   3.265 +    SDLK_8 = SDL_PHYSICAL_KEY(37),
   3.266 +    SDLK_9 = SDL_PHYSICAL_KEY(38),
   3.267 +    SDLK_0 = SDL_PHYSICAL_KEY(39),
   3.268 +
   3.269 +    SDLK_RETURN = SDL_PHYSICAL_KEY(40),
   3.270 +    SDLK_ESCAPE = SDL_PHYSICAL_KEY(41),
   3.271 +    SDLK_BACKSPACE = SDL_PHYSICAL_KEY(42),
   3.272 +    SDLK_TAB = SDL_PHYSICAL_KEY(43),
   3.273 +    SDLK_SPACE = SDL_PHYSICAL_KEY(44),
   3.274 +
   3.275 +    SDLK_HYPHENMINUS = SDL_PHYSICAL_KEY(45),
   3.276 +    SDLK_EQUALS = SDL_PHYSICAL_KEY(46),
   3.277 +    SDLK_LEFTBRACKET = SDL_PHYSICAL_KEY(47),
   3.278 +    SDLK_RIGHTBRACKET = SDL_PHYSICAL_KEY(48),
   3.279 +    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. */
   3.280 +    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. */
   3.281 +    SDLK_SEMICOLON = SDL_PHYSICAL_KEY(51),
   3.282 +    SDLK_APOSTROPHE = SDL_PHYSICAL_KEY(52),
   3.283 +    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. */
   3.284 +    SDLK_COMMA = SDL_PHYSICAL_KEY(54),
   3.285 +    SDLK_PERIOD = SDL_PHYSICAL_KEY(55),
   3.286 +    SDLK_SLASH = SDL_PHYSICAL_KEY(56),
   3.287 +
   3.288 +    SDLK_CAPSLOCK = SDL_PHYSICAL_KEY(57),
   3.289 +
   3.290 +    SDLK_F1 = SDL_PHYSICAL_KEY(58),
   3.291 +    SDLK_F2 = SDL_PHYSICAL_KEY(59),
   3.292 +    SDLK_F3 = SDL_PHYSICAL_KEY(60),
   3.293 +    SDLK_F4 = SDL_PHYSICAL_KEY(61),
   3.294 +    SDLK_F5 = SDL_PHYSICAL_KEY(62),
   3.295 +    SDLK_F6 = SDL_PHYSICAL_KEY(63),
   3.296 +    SDLK_F7 = SDL_PHYSICAL_KEY(64),
   3.297 +    SDLK_F8 = SDL_PHYSICAL_KEY(65),
   3.298 +    SDLK_F9 = SDL_PHYSICAL_KEY(66),
   3.299 +    SDLK_F10 = SDL_PHYSICAL_KEY(67),
   3.300 +    SDLK_F11 = SDL_PHYSICAL_KEY(68),
   3.301 +    SDLK_F12 = SDL_PHYSICAL_KEY(69),
   3.302 +
   3.303 +    SDLK_PRINTSCREEN = SDL_PHYSICAL_KEY(70),
   3.304 +    SDLK_SCROLLLOCK = SDL_PHYSICAL_KEY(71),
   3.305 +    SDLK_PAUSE = SDL_PHYSICAL_KEY(72),
   3.306 +    SDLK_INSERT = SDL_PHYSICAL_KEY(73), /**< insert on PC, help on some Mac keyboards (but does send code 73, not 117) */
   3.307 +    SDLK_HOME = SDL_PHYSICAL_KEY(74),
   3.308 +    SDLK_PAGEUP = SDL_PHYSICAL_KEY(75),
   3.309 +    SDLK_DELETE = SDL_PHYSICAL_KEY(76),
   3.310 +    SDLK_END = SDL_PHYSICAL_KEY(77),
   3.311 +    SDLK_PAGEDOWN = SDL_PHYSICAL_KEY(78),
   3.312 +    SDLK_RIGHT = SDL_PHYSICAL_KEY(79),
   3.313 +    SDLK_LEFT = SDL_PHYSICAL_KEY(80),
   3.314 +    SDLK_DOWN = SDL_PHYSICAL_KEY(81),
   3.315 +    SDLK_UP = SDL_PHYSICAL_KEY(82),
   3.316 +
   3.317 +    SDLK_KP_NUMLOCKCLEAR = SDL_PHYSICAL_KEY(83), /**< num lock on PC, clear on Mac keyboards */
   3.318 +    SDLK_KP_DIVIDE = SDL_PHYSICAL_KEY(84) | SDL_KEY_KEYPAD_BIT,
   3.319 +    SDLK_KP_MULTIPLY = SDL_PHYSICAL_KEY(85) | SDL_KEY_KEYPAD_BIT,
   3.320 +    SDLK_KP_MINUS = SDL_PHYSICAL_KEY(86) | SDL_KEY_KEYPAD_BIT,
   3.321 +    SDLK_KP_PLUS = SDL_PHYSICAL_KEY(87) | SDL_KEY_KEYPAD_BIT,
   3.322 +    SDLK_KP_ENTER = SDL_PHYSICAL_KEY(88),
   3.323 +    SDLK_KP_1 = SDL_PHYSICAL_KEY(89) | SDL_KEY_KEYPAD_BIT,
   3.324 +    SDLK_KP_2 = SDL_PHYSICAL_KEY(90) | SDL_KEY_KEYPAD_BIT,
   3.325 +    SDLK_KP_3 = SDL_PHYSICAL_KEY(91) | SDL_KEY_KEYPAD_BIT,
   3.326 +    SDLK_KP_4 = SDL_PHYSICAL_KEY(92) | SDL_KEY_KEYPAD_BIT,
   3.327 +    SDLK_KP_5 = SDL_PHYSICAL_KEY(93) | SDL_KEY_KEYPAD_BIT,
   3.328 +    SDLK_KP_6 = SDL_PHYSICAL_KEY(94) | SDL_KEY_KEYPAD_BIT,
   3.329 +    SDLK_KP_7 = SDL_PHYSICAL_KEY(95) | SDL_KEY_KEYPAD_BIT,
   3.330 +    SDLK_KP_8 = SDL_PHYSICAL_KEY(96) | SDL_KEY_KEYPAD_BIT,
   3.331 +    SDLK_KP_9 = SDL_PHYSICAL_KEY(97) | SDL_KEY_KEYPAD_BIT,
   3.332 +    SDLK_KP_0 = SDL_PHYSICAL_KEY(98) | SDL_KEY_KEYPAD_BIT,
   3.333 +    SDLK_KP_PERIOD = SDL_PHYSICAL_KEY(99) | SDL_KEY_KEYPAD_BIT,
   3.334  
   3.335 -    /* Numeric keypad */
   3.336 -    SDLK_KP0 = 256,
   3.337 -    SDLK_KP1 = 257,
   3.338 -    SDLK_KP2 = 258,
   3.339 -    SDLK_KP3 = 259,
   3.340 -    SDLK_KP4 = 260,
   3.341 -    SDLK_KP5 = 261,
   3.342 -    SDLK_KP6 = 262,
   3.343 -    SDLK_KP7 = 263,
   3.344 -    SDLK_KP8 = 264,
   3.345 -    SDLK_KP9 = 265,
   3.346 -    SDLK_KP_PERIOD = 266,
   3.347 -    SDLK_KP_DIVIDE = 267,
   3.348 -    SDLK_KP_MULTIPLY = 268,
   3.349 -    SDLK_KP_MINUS = 269,
   3.350 -    SDLK_KP_PLUS = 270,
   3.351 -    SDLK_KP_ENTER = 271,
   3.352 -    SDLK_KP_EQUALS = 272,
   3.353 +    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. */
   3.354 +    SDLK_APPLICATION = SDL_PHYSICAL_KEY(101), /**< windows contextual menu, compose */
   3.355 +    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. */
   3.356 +    SDLK_KP_EQUALS = SDL_PHYSICAL_KEY(103) | SDL_KEY_KEYPAD_BIT,
   3.357 +    SDLK_F13 = SDL_PHYSICAL_KEY(104),
   3.358 +    SDLK_F14 = SDL_PHYSICAL_KEY(105),
   3.359 +    SDLK_F15 = SDL_PHYSICAL_KEY(106),
   3.360 +    SDLK_F16 = SDL_PHYSICAL_KEY(107),
   3.361 +    SDLK_F17 = SDL_PHYSICAL_KEY(108),
   3.362 +    SDLK_F18 = SDL_PHYSICAL_KEY(109),
   3.363 +    SDLK_F19 = SDL_PHYSICAL_KEY(110),
   3.364 +    SDLK_F20 = SDL_PHYSICAL_KEY(111),
   3.365 +    SDLK_F21 = SDL_PHYSICAL_KEY(112),
   3.366 +    SDLK_F22 = SDL_PHYSICAL_KEY(113),
   3.367 +    SDLK_F23 = SDL_PHYSICAL_KEY(114),
   3.368 +    SDLK_F24 = SDL_PHYSICAL_KEY(115),
   3.369 +    SDLK_EXECUTE = SDL_PHYSICAL_KEY(116),
   3.370 +    SDLK_HELP = SDL_PHYSICAL_KEY(117),
   3.371 +    SDLK_MENU = SDL_PHYSICAL_KEY(118),
   3.372 +    SDLK_SELECT = SDL_PHYSICAL_KEY(119),
   3.373 +    SDLK_STOP = SDL_PHYSICAL_KEY(120),
   3.374 +    SDLK_AGAIN = SDL_PHYSICAL_KEY(121), /*!< redo */
   3.375 +    SDLK_UNDO = SDL_PHYSICAL_KEY(122),
   3.376 +    SDLK_CUT = SDL_PHYSICAL_KEY(123),
   3.377 +    SDLK_COPY = SDL_PHYSICAL_KEY(124),
   3.378 +    SDLK_PASTE = SDL_PHYSICAL_KEY(125),
   3.379 +    SDLK_FIND = SDL_PHYSICAL_KEY(126),
   3.380 +    SDLK_MUTE = SDL_PHYSICAL_KEY(127),
   3.381 +    SDLK_VOLUMEUP = SDL_PHYSICAL_KEY(128),
   3.382 +    SDLK_VOLUMEDOWN = SDL_PHYSICAL_KEY(129),
   3.383 +    /*SDLK_LOCKINGCAPSLOCK = SDL_PHYSICAL_KEY(130), not sure whether there's a reason to enable these
   3.384 +       SDLK_LOCKINGNUMLOCK = SDL_PHYSICAL_KEY(131),
   3.385 +       SDLK_LOCKINGSCROLLLOCK = SDL_PHYSICAL_KEY(132), */
   3.386 +    SDLK_KP_COMMA = SDL_PHYSICAL_KEY(133) | SDL_KEY_KEYPAD_BIT,
   3.387 +    SDLK_KP_EQUALSAS400 = SDL_PHYSICAL_KEY(134) | SDL_KEY_KEYPAD_BIT,
   3.388  
   3.389 -    /* Arrows + Home/End pad */
   3.390 -    SDLK_UP = 273,
   3.391 -    SDLK_DOWN = 274,
   3.392 -    SDLK_RIGHT = 275,
   3.393 -    SDLK_LEFT = 276,
   3.394 -    SDLK_INSERT = 277,
   3.395 -    SDLK_HOME = 278,
   3.396 -    SDLK_END = 279,
   3.397 -    SDLK_PAGEUP = 280,
   3.398 -    SDLK_PAGEDOWN = 281,
   3.399 +    SDLK_INTERNATIONAL1 = SDL_PHYSICAL_KEY(135), /**< used on Asian keyboards, see footnotes in USB doc */
   3.400 +    SDLK_INTERNATIONAL2 = SDL_PHYSICAL_KEY(136),
   3.401 +    SDLK_INTERNATIONAL3 = SDL_PHYSICAL_KEY(137), /**< Yen */
   3.402 +    SDLK_INTERNATIONAL4 = SDL_PHYSICAL_KEY(138),
   3.403 +    SDLK_INTERNATIONAL5 = SDL_PHYSICAL_KEY(139),
   3.404 +    SDLK_INTERNATIONAL6 = SDL_PHYSICAL_KEY(140),
   3.405 +    SDLK_INTERNATIONAL7 = SDL_PHYSICAL_KEY(141),
   3.406 +    SDLK_INTERNATIONAL8 = SDL_PHYSICAL_KEY(142),
   3.407 +    SDLK_INTERNATIONAL9 = SDL_PHYSICAL_KEY(143),
   3.408 +    SDLK_LANG1 = SDL_PHYSICAL_KEY(144), /**< Hangul/English toggle */
   3.409 +    SDLK_LANG2 = SDL_PHYSICAL_KEY(145), /**< Hanja conversion */
   3.410 +    SDLK_LANG3 = SDL_PHYSICAL_KEY(146), /**< Katakana */
   3.411 +    SDLK_LANG4 = SDL_PHYSICAL_KEY(147), /**< Hiragana */
   3.412 +    SDLK_LANG5 = SDL_PHYSICAL_KEY(148), /**< Zenkaku/Hankaku */
   3.413 +    SDLK_LANG6 = SDL_PHYSICAL_KEY(149), /**< reserved */
   3.414 +    SDLK_LANG7 = SDL_PHYSICAL_KEY(150), /**< reserved */
   3.415 +    SDLK_LANG8 = SDL_PHYSICAL_KEY(151), /**< reserved */
   3.416 +    SDLK_LANG9 = SDL_PHYSICAL_KEY(152), /**< reserved */
   3.417 +
   3.418 +    SDLK_ALTERASE = SDL_PHYSICAL_KEY(153), /**< Erase-Eaze */
   3.419 +    SDLK_SYSREQ = SDL_PHYSICAL_KEY(154),
   3.420 +    SDLK_CANCEL = SDL_PHYSICAL_KEY(155),
   3.421 +    SDLK_CLEAR = SDL_PHYSICAL_KEY(156),
   3.422 +    SDLK_PRIOR = SDL_PHYSICAL_KEY(157),
   3.423 +    SDLK_RETURN2 = SDL_PHYSICAL_KEY(158),
   3.424 +    SDLK_SEPARATOR = SDL_PHYSICAL_KEY(159),
   3.425 +    SDLK_OUT = SDL_PHYSICAL_KEY(160),
   3.426 +    SDLK_OPER = SDL_PHYSICAL_KEY(161),
   3.427 +    SDLK_CLEARAGAIN = SDL_PHYSICAL_KEY(162),
   3.428 +    SDLK_CRSELPROPS = SDL_PHYSICAL_KEY(163),
   3.429 +    SDLK_EXSEL = SDL_PHYSICAL_KEY(164),
   3.430  
   3.431 -    /* Function keys */
   3.432 -    SDLK_F1 = 282,
   3.433 -    SDLK_F2 = 283,
   3.434 -    SDLK_F3 = 284,
   3.435 -    SDLK_F4 = 285,
   3.436 -    SDLK_F5 = 286,
   3.437 -    SDLK_F6 = 287,
   3.438 -    SDLK_F7 = 288,
   3.439 -    SDLK_F8 = 289,
   3.440 -    SDLK_F9 = 290,
   3.441 -    SDLK_F10 = 291,
   3.442 -    SDLK_F11 = 292,
   3.443 -    SDLK_F12 = 293,
   3.444 -    SDLK_F13 = 294,
   3.445 -    SDLK_F14 = 295,
   3.446 -    SDLK_F15 = 296,
   3.447 +    SDLK_KP_00 = SDL_PHYSICAL_KEY(176) | SDL_KEY_KEYPAD_BIT,
   3.448 +    SDLK_KP_000 = SDL_PHYSICAL_KEY(177) | SDL_KEY_KEYPAD_BIT,
   3.449 +    SDLK_THOUSANDSSEPARATOR = SDL_PHYSICAL_KEY(178),
   3.450 +    SDLK_DECIMALSEPARATOR = SDL_PHYSICAL_KEY(179),
   3.451 +    SDLK_CURRENCYUNIT = SDL_PHYSICAL_KEY(180),
   3.452 +    SDLK_CURRENCYSUBUNIT = SDL_PHYSICAL_KEY(181),
   3.453 +    SDLK_KP_LEFTPAREN = SDL_PHYSICAL_KEY(182) | SDL_KEY_KEYPAD_BIT,
   3.454 +    SDLK_KP_RIGHTPAREN = SDL_PHYSICAL_KEY(183) | SDL_KEY_KEYPAD_BIT,
   3.455 +    SDLK_KP_LEFTBRACE = SDL_PHYSICAL_KEY(184) | SDL_KEY_KEYPAD_BIT,
   3.456 +    SDLK_KP_RIGHTBRACE = SDL_PHYSICAL_KEY(185) | SDL_KEY_KEYPAD_BIT,
   3.457 +    SDLK_KP_TAB = SDL_PHYSICAL_KEY(186) | SDL_KEY_KEYPAD_BIT,
   3.458 +    SDLK_KP_BACKSPACE = SDL_PHYSICAL_KEY(187) | SDL_KEY_KEYPAD_BIT,
   3.459 +    SDLK_KP_A = SDL_PHYSICAL_KEY(188) | SDL_KEY_KEYPAD_BIT,
   3.460 +    SDLK_KP_B = SDL_PHYSICAL_KEY(189) | SDL_KEY_KEYPAD_BIT,
   3.461 +    SDLK_KP_C = SDL_PHYSICAL_KEY(190) | SDL_KEY_KEYPAD_BIT,
   3.462 +    SDLK_KP_D = SDL_PHYSICAL_KEY(191) | SDL_KEY_KEYPAD_BIT,
   3.463 +    SDLK_KP_E = SDL_PHYSICAL_KEY(192) | SDL_KEY_KEYPAD_BIT,
   3.464 +    SDLK_KP_F = SDL_PHYSICAL_KEY(193) | SDL_KEY_KEYPAD_BIT,
   3.465 +    SDLK_KP_XOR = SDL_PHYSICAL_KEY(194) | SDL_KEY_KEYPAD_BIT,
   3.466 +    SDLK_KP_POWER = SDL_PHYSICAL_KEY(195) | SDL_KEY_KEYPAD_BIT,
   3.467 +    SDLK_KP_PERCENT = SDL_PHYSICAL_KEY(196) | SDL_KEY_KEYPAD_BIT,
   3.468 +    SDLK_KP_LESS = SDL_PHYSICAL_KEY(197) | SDL_KEY_KEYPAD_BIT,
   3.469 +    SDLK_KP_GREATER = SDL_PHYSICAL_KEY(198) | SDL_KEY_KEYPAD_BIT,
   3.470 +    SDLK_KP_AMPERSAND = SDL_PHYSICAL_KEY(199) | SDL_KEY_KEYPAD_BIT,
   3.471 +    SDLK_KP_DBLAMPERSAND = SDL_PHYSICAL_KEY(200) | SDL_KEY_KEYPAD_BIT,
   3.472 +    SDLK_KP_VERTICALBAR = SDL_PHYSICAL_KEY(201) | SDL_KEY_KEYPAD_BIT,
   3.473 +    SDLK_KP_DBLVERTICALBAR = SDL_PHYSICAL_KEY(202) | SDL_KEY_KEYPAD_BIT,
   3.474 +    SDLK_KP_COLON = SDL_PHYSICAL_KEY(203) | SDL_KEY_KEYPAD_BIT,
   3.475 +    SDLK_KP_HASH = SDL_PHYSICAL_KEY(204) | SDL_KEY_KEYPAD_BIT,
   3.476 +    SDLK_KP_SPACE = SDL_PHYSICAL_KEY(205) | SDL_KEY_KEYPAD_BIT,
   3.477 +    SDLK_KP_AT = SDL_PHYSICAL_KEY(206) | SDL_KEY_KEYPAD_BIT,
   3.478 +    SDLK_KP_EXCLAM = SDL_PHYSICAL_KEY(207) | SDL_KEY_KEYPAD_BIT,
   3.479 +    SDLK_KP_MEMSTORE = SDL_PHYSICAL_KEY(208) | SDL_KEY_KEYPAD_BIT,
   3.480 +    SDLK_KP_MEMRECALL = SDL_PHYSICAL_KEY(209) | SDL_KEY_KEYPAD_BIT,
   3.481 +    SDLK_KP_MEMCLEAR = SDL_PHYSICAL_KEY(210) | SDL_KEY_KEYPAD_BIT,
   3.482 +    SDLK_KP_MEMADD = SDL_PHYSICAL_KEY(211) | SDL_KEY_KEYPAD_BIT,
   3.483 +    SDLK_KP_MEMSUBTRACT = SDL_PHYSICAL_KEY(212) | SDL_KEY_KEYPAD_BIT,
   3.484 +    SDLK_KP_MEMMULTIPLY = SDL_PHYSICAL_KEY(213) | SDL_KEY_KEYPAD_BIT,
   3.485 +    SDLK_KP_MEMDIVIDE = SDL_PHYSICAL_KEY(214) | SDL_KEY_KEYPAD_BIT,
   3.486 +    SDLK_KP_PLUSMINUS = SDL_PHYSICAL_KEY(215) | SDL_KEY_KEYPAD_BIT,
   3.487 +    SDLK_KP_CLEAR = SDL_PHYSICAL_KEY(216) | SDL_KEY_KEYPAD_BIT,
   3.488 +    SDLK_KP_CLEARENTRY = SDL_PHYSICAL_KEY(217) | SDL_KEY_KEYPAD_BIT,
   3.489 +    SDLK_KP_BINARY = SDL_PHYSICAL_KEY(218) | SDL_KEY_KEYPAD_BIT,
   3.490 +    SDLK_KP_OCTAL = SDL_PHYSICAL_KEY(219) | SDL_KEY_KEYPAD_BIT,
   3.491 +    SDLK_KP_DECIMAL = SDL_PHYSICAL_KEY(220) | SDL_KEY_KEYPAD_BIT,
   3.492 +    SDLK_KP_HEXADECIMAL = SDL_PHYSICAL_KEY(221) | SDL_KEY_KEYPAD_BIT,
   3.493  
   3.494 -    /* Key state modifier keys */
   3.495 -    SDLK_NUMLOCK = 300,
   3.496 -    SDLK_CAPSLOCK = 301,
   3.497 -    SDLK_SCROLLOCK = 302,
   3.498 -    SDLK_RSHIFT = 303,
   3.499 -    SDLK_LSHIFT = 304,
   3.500 -    SDLK_RCTRL = 305,
   3.501 -    SDLK_LCTRL = 306,
   3.502 -    SDLK_RALT = 307,
   3.503 -    SDLK_LALT = 308,
   3.504 -    SDLK_RMETA = 309,
   3.505 -    SDLK_LMETA = 310,
   3.506 -    SDLK_LSUPER = 311,          /**< Left "Windows" key */
   3.507 -    SDLK_RSUPER = 312,          /**< Right "Windows" key */
   3.508 -    SDLK_MODE = 313,            /**< "Alt Gr" key */
   3.509 -    SDLK_COMPOSE = 314,         /**< Multi-key compose key */
   3.510 +    SDLK_LCTRL = SDL_PHYSICAL_KEY(224),
   3.511 +    SDLK_LSHIFT = SDL_PHYSICAL_KEY(225),
   3.512 +    SDLK_LALT = SDL_PHYSICAL_KEY(226), /**< alt, option */
   3.513 +    SDLK_LMETA = SDL_PHYSICAL_KEY(227), /**< windows, command (apple), meta */
   3.514 +    SDLK_RCTRL = SDL_PHYSICAL_KEY(228),
   3.515 +    SDLK_RSHIFT = SDL_PHYSICAL_KEY(229),
   3.516 +    SDLK_RALT = SDL_PHYSICAL_KEY(230), /**< alt gr, option */
   3.517 +    SDLK_RMETA = SDL_PHYSICAL_KEY(231), /**< windows, command (apple), meta */
   3.518 +
   3.519 +    /* Everything below here is not from the USB spec */
   3.520 +
   3.521 +    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 */
   3.522  
   3.523 -    /* Miscellaneous function keys */
   3.524 -    SDLK_HELP = 315,
   3.525 -    SDLK_PRINT = 316,
   3.526 -    SDLK_SYSREQ = 317,
   3.527 -    SDLK_BREAK = 318,
   3.528 -    SDLK_MENU = 319,
   3.529 -    SDLK_POWER = 320,           /**< Power Macintosh power key */
   3.530 -    SDLK_EURO = 321,            /**< Some european keyboards */
   3.531 -    SDLK_UNDO = 322,            /**< Atari keyboard has Undo */
   3.532 +    SDLK_BRIGHTNESSDOWN = SDL_PHYSICAL_KEY(236),
   3.533 +    SDLK_BRIGHTNESSUP = SDL_PHYSICAL_KEY(237),
   3.534 +    SDLK_DISPLAYSWITCH = SDL_PHYSICAL_KEY(238), /**< display mirroring/dual display switch, video mode switch */
   3.535 +    SDLK_KBDILLUMTOGGLE = SDL_PHYSICAL_KEY(239),
   3.536 +    SDLK_KBDILLUMDOWN = SDL_PHYSICAL_KEY(240),
   3.537 +    SDLK_KBDILLUMUP = SDL_PHYSICAL_KEY(241),
   3.538 +    SDLK_EJECT = SDL_PHYSICAL_KEY(242),
   3.539 +    SDLK_SLEEP = SDL_PHYSICAL_KEY(243),
   3.540 +
   3.541 +    /* Some of the more common and more standardized "multimedia"/"internet" keyboard keys */
   3.542 +    SDLK_AUDIOPLAY = SDL_PHYSICAL_KEY(244),
   3.543 +    SDLK_AUDIOSTOP = SDL_PHYSICAL_KEY(245),
   3.544 +    SDLK_AUDIOPREV = SDL_PHYSICAL_KEY(246),
   3.545 +    SDLK_AUDIONEXT = SDL_PHYSICAL_KEY(247),
   3.546 +    SDLK_CALC = SDL_PHYSICAL_KEY(248),
   3.547 +    SDLK_WWW = SDL_PHYSICAL_KEY(249),
   3.548 +    SDLK_EMAIL = SDL_PHYSICAL_KEY(250),
   3.549 +    SDLK_MEDIA = SDL_PHYSICAL_KEY(251),
   3.550 +    SDLK_COMPUTER = SDL_PHYSICAL_KEY(252),
   3.551 +    SDLK_SEARCH = SDL_PHYSICAL_KEY(253),
   3.552 +    SDLK_BOOKMARKS = SDL_PHYSICAL_KEY(254),
   3.553 +    SDLK_BROWSERBACK = SDL_PHYSICAL_KEY(255),
   3.554 +    SDLK_BROWSERFORWARD = SDL_PHYSICAL_KEY(256),
   3.555 +    SDLK_BROWSERRELOAD = SDL_PHYSICAL_KEY(257),
   3.556 +    SDLK_BROWSERSTOP = SDL_PHYSICAL_KEY(258),
   3.557  
   3.558      /* Add any other keys here */
   3.559  
   3.560 -    SDLK_LAST
   3.561 -} SDLKey;
   3.562 +    SDLK_LAST_PHYSICAL /**< (not a key, just marks the highest used value in this enum) */
   3.563 +};
   3.564 +
   3.565 +#define SDLK_FIRST SDLK_INDEX(SDLK_FIRST_PHYSICAL)
   3.566 +#define SDLK_LAST SDLK_INDEX(SDLK_LAST_PHYSICAL)
   3.567 +
   3.568 +
   3.569  
   3.570  /**
   3.571   * \enum SDLMod
     4.1 --- a/src/events/SDL_keyboard.c	Sat Aug 18 05:39:09 2007 +0000
     4.2 +++ b/src/events/SDL_keyboard.c	Sun Aug 19 14:52:52 2007 +0000
     4.3 @@ -27,6 +27,7 @@
     4.4  #include "SDL_events.h"
     4.5  #include "SDL_events_c.h"
     4.6  #include "SDL_sysevents.h"
     4.7 +#include "SDL_keynames.h"
     4.8  
     4.9  
    4.10  /* Global keyboard information */
    4.11 @@ -35,246 +36,13 @@
    4.12  static int SDL_current_keyboard;
    4.13  static SDL_Keyboard **SDL_keyboards;
    4.14  
    4.15 -static const char *SDL_keynames[SDLK_LAST];     /* Array of keycode names */
    4.16 -
    4.17  /* Public functions */
    4.18  int
    4.19  SDL_KeyboardInit(void)
    4.20  {
    4.21 -    int i;
    4.22 -
    4.23      /* Set default mode of UNICODE translation */
    4.24      SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
    4.25  
    4.26 -    /* Initialize the tables */
    4.27 -    for (i = 0; i < SDL_arraysize(SDL_keynames); ++i) {
    4.28 -        switch (i) {
    4.29 -        case SDLK_BACKSPACE:
    4.30 -            SDL_keynames[i] = "backspace";
    4.31 -            break;
    4.32 -        case SDLK_TAB:
    4.33 -            SDL_keynames[i] = "tab";
    4.34 -            break;
    4.35 -        case SDLK_CLEAR:
    4.36 -            SDL_keynames[i] = "clear";
    4.37 -            break;
    4.38 -        case SDLK_RETURN:
    4.39 -            SDL_keynames[i] = "return";
    4.40 -            break;
    4.41 -        case SDLK_PAUSE:
    4.42 -            SDL_keynames[i] = "pause";
    4.43 -            break;
    4.44 -        case SDLK_ESCAPE:
    4.45 -            SDL_keynames[i] = "escape";
    4.46 -            break;
    4.47 -        case SDLK_SPACE:
    4.48 -            SDL_keynames[i] = "space";
    4.49 -            break;
    4.50 -
    4.51 -        case SDLK_KP0:
    4.52 -            SDL_keynames[i] = "[0]";
    4.53 -            break;
    4.54 -        case SDLK_KP1:
    4.55 -            SDL_keynames[i] = "[1]";
    4.56 -            break;
    4.57 -        case SDLK_KP2:
    4.58 -            SDL_keynames[i] = "[2]";
    4.59 -            break;
    4.60 -        case SDLK_KP3:
    4.61 -            SDL_keynames[i] = "[3]";
    4.62 -            break;
    4.63 -        case SDLK_KP4:
    4.64 -            SDL_keynames[i] = "[4]";
    4.65 -            break;
    4.66 -        case SDLK_KP5:
    4.67 -            SDL_keynames[i] = "[5]";
    4.68 -            break;
    4.69 -        case SDLK_KP6:
    4.70 -            SDL_keynames[i] = "[6]";
    4.71 -            break;
    4.72 -        case SDLK_KP7:
    4.73 -            SDL_keynames[i] = "[7]";
    4.74 -            break;
    4.75 -        case SDLK_KP8:
    4.76 -            SDL_keynames[i] = "[8]";
    4.77 -            break;
    4.78 -        case SDLK_KP9:
    4.79 -            SDL_keynames[i] = "[9]";
    4.80 -            break;
    4.81 -        case SDLK_KP_PERIOD:
    4.82 -            SDL_keynames[i] = "[.]";
    4.83 -            break;
    4.84 -        case SDLK_KP_DIVIDE:
    4.85 -            SDL_keynames[i] = "[/]";
    4.86 -            break;
    4.87 -        case SDLK_KP_MULTIPLY:
    4.88 -            SDL_keynames[i] = "[*]";
    4.89 -            break;
    4.90 -        case SDLK_KP_MINUS:
    4.91 -            SDL_keynames[i] = "[-]";
    4.92 -            break;
    4.93 -        case SDLK_KP_PLUS:
    4.94 -            SDL_keynames[i] = "[+]";
    4.95 -            break;
    4.96 -        case SDLK_KP_ENTER:
    4.97 -            SDL_keynames[i] = "enter";
    4.98 -            break;
    4.99 -        case SDLK_KP_EQUALS:
   4.100 -            SDL_keynames[i] = "equals";
   4.101 -            break;
   4.102 -
   4.103 -        case SDLK_UP:
   4.104 -            SDL_keynames[i] = "up";
   4.105 -            break;
   4.106 -        case SDLK_DOWN:
   4.107 -            SDL_keynames[i] = "down";
   4.108 -            break;
   4.109 -        case SDLK_RIGHT:
   4.110 -            SDL_keynames[i] = "right";
   4.111 -            break;
   4.112 -        case SDLK_LEFT:
   4.113 -            SDL_keynames[i] = "left";
   4.114 -            break;
   4.115 -        case SDLK_INSERT:
   4.116 -            SDL_keynames[i] = "insert";
   4.117 -            break;
   4.118 -        case SDLK_HOME:
   4.119 -            SDL_keynames[i] = "home";
   4.120 -            break;
   4.121 -        case SDLK_END:
   4.122 -            SDL_keynames[i] = "end";
   4.123 -            break;
   4.124 -        case SDLK_PAGEUP:
   4.125 -            SDL_keynames[i] = "page up";
   4.126 -            break;
   4.127 -        case SDLK_PAGEDOWN:
   4.128 -            SDL_keynames[i] = "page down";
   4.129 -            break;
   4.130 -
   4.131 -        case SDLK_F1:
   4.132 -            SDL_keynames[i] = "f1";
   4.133 -            break;
   4.134 -        case SDLK_F2:
   4.135 -            SDL_keynames[i] = "f2";
   4.136 -            break;
   4.137 -        case SDLK_F3:
   4.138 -            SDL_keynames[i] = "f3";
   4.139 -            break;
   4.140 -        case SDLK_F4:
   4.141 -            SDL_keynames[i] = "f4";
   4.142 -            break;
   4.143 -        case SDLK_F5:
   4.144 -            SDL_keynames[i] = "f5";
   4.145 -            break;
   4.146 -        case SDLK_F6:
   4.147 -            SDL_keynames[i] = "f6";
   4.148 -            break;
   4.149 -        case SDLK_F7:
   4.150 -            SDL_keynames[i] = "f7";
   4.151 -            break;
   4.152 -        case SDLK_F8:
   4.153 -            SDL_keynames[i] = "f8";
   4.154 -            break;
   4.155 -        case SDLK_F9:
   4.156 -            SDL_keynames[i] = "f9";
   4.157 -            break;
   4.158 -        case SDLK_F10:
   4.159 -            SDL_keynames[i] = "f10";
   4.160 -            break;
   4.161 -        case SDLK_F11:
   4.162 -            SDL_keynames[i] = "f11";
   4.163 -            break;
   4.164 -        case SDLK_F12:
   4.165 -            SDL_keynames[i] = "f12";
   4.166 -            break;
   4.167 -        case SDLK_F13:
   4.168 -            SDL_keynames[i] = "f13";
   4.169 -            break;
   4.170 -        case SDLK_F14:
   4.171 -            SDL_keynames[i] = "f14";
   4.172 -            break;
   4.173 -        case SDLK_F15:
   4.174 -            SDL_keynames[i] = "f15";
   4.175 -            break;
   4.176 -
   4.177 -        case SDLK_NUMLOCK:
   4.178 -            SDL_keynames[i] = "numlock";
   4.179 -            break;
   4.180 -        case SDLK_CAPSLOCK:
   4.181 -            SDL_keynames[i] = "caps lock";
   4.182 -            break;
   4.183 -        case SDLK_SCROLLOCK:
   4.184 -            SDL_keynames[i] = "scroll lock";
   4.185 -            break;
   4.186 -        case SDLK_RSHIFT:
   4.187 -            SDL_keynames[i] = "right shift";
   4.188 -            break;
   4.189 -        case SDLK_LSHIFT:
   4.190 -            SDL_keynames[i] = "left shift";
   4.191 -            break;
   4.192 -        case SDLK_RCTRL:
   4.193 -            SDL_keynames[i] = "right ctrl";
   4.194 -            break;
   4.195 -        case SDLK_LCTRL:
   4.196 -            SDL_keynames[i] = "left ctrl";
   4.197 -            break;
   4.198 -        case SDLK_RALT:
   4.199 -            SDL_keynames[i] = "right alt";
   4.200 -            break;
   4.201 -        case SDLK_LALT:
   4.202 -            SDL_keynames[i] = "left alt";
   4.203 -            break;
   4.204 -        case SDLK_RMETA:
   4.205 -            SDL_keynames[i] = "right meta";
   4.206 -            break;
   4.207 -        case SDLK_LMETA:
   4.208 -            SDL_keynames[i] = "left meta";
   4.209 -            break;
   4.210 -        case SDLK_LSUPER:
   4.211 -            SDL_keynames[i] = "left super";     /* "Windows" keys */
   4.212 -            break;
   4.213 -        case SDLK_RSUPER:
   4.214 -            SDL_keynames[i] = "right super";
   4.215 -            break;
   4.216 -        case SDLK_MODE:
   4.217 -            SDL_keynames[i] = "alt gr";
   4.218 -            break;
   4.219 -        case SDLK_COMPOSE:
   4.220 -            SDL_keynames[i] = "compose";
   4.221 -            break;
   4.222 -
   4.223 -        case SDLK_HELP:
   4.224 -            SDL_keynames[i] = "help";
   4.225 -            break;
   4.226 -        case SDLK_PRINT:
   4.227 -            SDL_keynames[i] = "print screen";
   4.228 -            break;
   4.229 -        case SDLK_SYSREQ:
   4.230 -            SDL_keynames[i] = "sys req";
   4.231 -            break;
   4.232 -        case SDLK_BREAK:
   4.233 -            SDL_keynames[i] = "break";
   4.234 -            break;
   4.235 -        case SDLK_MENU:
   4.236 -            SDL_keynames[i] = "menu";
   4.237 -            break;
   4.238 -        case SDLK_POWER:
   4.239 -            SDL_keynames[i] = "power";
   4.240 -            break;
   4.241 -        case SDLK_EURO:
   4.242 -            SDL_keynames[i] = "euro";
   4.243 -            break;
   4.244 -        case SDLK_UNDO:
   4.245 -            SDL_keynames[i] = "undo";
   4.246 -            break;
   4.247 -
   4.248 -        default:
   4.249 -            SDL_keynames[i] = NULL;
   4.250 -            break;
   4.251 -        }
   4.252 -    }
   4.253 -
   4.254 -    /* Done.  Whew. */
   4.255      return (0);
   4.256  }
   4.257  
   4.258 @@ -338,7 +106,7 @@
   4.259  SDL_ResetKeyboard(int index)
   4.260  {
   4.261      SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   4.262 -    SDLKey key;
   4.263 +    int key;
   4.264  
   4.265      if (!keyboard) {
   4.266          return;
   4.267 @@ -346,7 +114,8 @@
   4.268  
   4.269      for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   4.270          if (keyboard->keystate[key] == SDL_PRESSED) {
   4.271 -            SDL_SendKeyboardKey(index, SDL_RELEASED, 0, key);
   4.272 +            SDL_SendKeyboardKey(index, SDL_RELEASED, 0,
   4.273 +                                key | SDL_KEY_CAN_BE_PHYSICAL_BIT);
   4.274          }
   4.275      }
   4.276  }
   4.277 @@ -432,36 +201,81 @@
   4.278      keyboard->modstate = modstate;
   4.279  }
   4.280  
   4.281 -const char *
   4.282 -SDL_GetKeyName(SDLKey key)
   4.283 +SDLKey
   4.284 +SDL_GetLayoutKey(SDLKey physicalKey)
   4.285  {
   4.286 -    const char *keyname;
   4.287 -
   4.288 -    if (key < SDL_arraysize(SDL_keynames)) {
   4.289 -        keyname = SDL_keynames[key];
   4.290 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   4.291 +    if (_this && _this->GetLayoutKey) {
   4.292 +        return _this->GetLayoutKey(_this, physicalKey)
   4.293 +            | (physicalKey & SDL_KEY_KEYPAD_BIT);
   4.294      } else {
   4.295 -        keyname = NULL;
   4.296 +        return physicalKey;
   4.297      }
   4.298 -    if (keyname == NULL) {
   4.299 -        if (key < 256) {
   4.300 -            static char temp[4];
   4.301 -            char *cvt;
   4.302 -            temp[0] = (char) key;
   4.303 -            temp[1] = '\0';
   4.304 -            cvt = SDL_iconv_string("UTF-8", "ISO-8859-1", temp, 1);
   4.305 -            if (cvt) {
   4.306 -                SDL_strlcpy(temp, cvt, SDL_arraysize(temp));
   4.307 -                SDL_free(cvt);
   4.308 -            }
   4.309 -            keyname = temp;
   4.310 +}
   4.311 +
   4.312 +const char *
   4.313 +SDL_GetKeyName(SDLKey layoutKey)
   4.314 +{
   4.315 +    const char *keyname = NULL;
   4.316 +
   4.317 +    if ((layoutKey & SDL_KEY_LAYOUT_SPECIAL_BIT) != 0) {
   4.318 +        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   4.319 +        if (_this && _this->GetSpecialKeyName) {
   4.320 +            keyname = _this->GetSpecialKeyName(_this, layoutKey);
   4.321 +        }
   4.322 +    } else if ((layoutKey & SDL_KEY_CAN_BE_PHYSICAL_BIT) == 0) {
   4.323 +        /* SDLK_INDEX(layoutKey) is the unicode code point of the character generated by the key */
   4.324 +        static char buffer[9];  /* 6 (maximal UTF-8 char length) + 2 ([] for keypad) + 1 (null teminator) */
   4.325 +        char *bufferPtr = &buffer[1];
   4.326 +        SDL_iconv_t cd;
   4.327 +        size_t inbytesleft = 4, outbytesleft = 8;
   4.328 +        Uint32 codepoint = SDLK_INDEX(layoutKey);
   4.329 +        const char *codepointPtr = (const char *) &codepoint;
   4.330 +
   4.331 +        /* 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). */
   4.332 +        if (codepoint >= 'a' && codepoint <= 'z') {
   4.333 +            codepoint -= 32;
   4.334 +        }
   4.335 +
   4.336 +        cd = SDL_iconv_open("UTF-8", "UCS-4");
   4.337 +        if (cd == (SDL_iconv_t) (-1))
   4.338 +            return "";
   4.339 +        SDL_iconv(cd, &codepointPtr, &inbytesleft, &bufferPtr, &outbytesleft);
   4.340 +        SDL_iconv_close(cd);
   4.341 +        *bufferPtr = '\0';
   4.342 +
   4.343 +        if ((layoutKey & SDL_KEY_KEYPAD_BIT) != 0) {
   4.344 +            buffer[0] = '[';
   4.345 +            *bufferPtr++ = ']';
   4.346 +            *bufferPtr = '\0';
   4.347 +            keyname = buffer;
   4.348          } else {
   4.349 -            keyname = "unknown key";
   4.350 +            keyname = &buffer[1];
   4.351 +        }
   4.352 +    } else {
   4.353 +        /* SDLK_INDEX(layoutKey) is a physical key number */
   4.354 +        if (SDLK_INDEX(layoutKey) < SDL_arraysize(SDL_keynames)) {
   4.355 +            keyname = SDL_keynames[SDLK_INDEX(layoutKey)];
   4.356          }
   4.357      }
   4.358 +
   4.359 +    if (keyname == NULL) {
   4.360 +        keyname = SDL_keynames[SDLK_INDEX(SDLK_UNKNOWN)];
   4.361 +    }
   4.362 +
   4.363      return keyname;
   4.364  }
   4.365  
   4.366  void
   4.367 +SDL_SetKeyName(SDLKey physicalKey, const char *name)
   4.368 +{
   4.369 +    physicalKey = SDLK_INDEX(physicalKey);
   4.370 +    if (physicalKey < SDL_arraysize(SDL_keynames)) {
   4.371 +        SDL_keynames[physicalKey] = name;
   4.372 +    }
   4.373 +}
   4.374 +
   4.375 +void
   4.376  SDL_SetKeyboardFocus(int index, SDL_WindowID windowID)
   4.377  {
   4.378      SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   4.379 @@ -513,26 +327,27 @@
   4.380  }
   4.381  
   4.382  int
   4.383 -SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
   4.384 +SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode,
   4.385 +                    SDLKey physicalKey)
   4.386  {
   4.387      SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   4.388      int posted;
   4.389      Uint16 modstate;
   4.390      Uint8 type;
   4.391  
   4.392 -    if (!keyboard) {
   4.393 +    if (!keyboard || physicalKey == SDLK_NONE) {
   4.394          return 0;
   4.395      }
   4.396  #if 0
   4.397 -    printf("The '%s' key has been %s\n", SDL_GetKeyName(key),
   4.398 +    printf("The '%s' key has been %s\n", SDL_GetKeyName(physicalKey),
   4.399             state == SDL_PRESSED ? "pressed" : "released");
   4.400  #endif
   4.401      if (state == SDL_PRESSED) {
   4.402          modstate = keyboard->modstate;
   4.403 -        switch (key) {
   4.404 +        switch (physicalKey) {
   4.405          case SDLK_UNKNOWN:
   4.406              break;
   4.407 -        case SDLK_NUMLOCK:
   4.408 +        case SDLK_KP_NUMLOCKCLEAR:
   4.409              keyboard->modstate ^= KMOD_NUM;
   4.410              break;
   4.411          case SDLK_CAPSLOCK:
   4.412 @@ -569,10 +384,10 @@
   4.413              break;
   4.414          }
   4.415      } else {
   4.416 -        switch (key) {
   4.417 +        switch (physicalKey) {
   4.418          case SDLK_UNKNOWN:
   4.419              break;
   4.420 -        case SDLK_NUMLOCK:
   4.421 +        case SDLK_KP_NUMLOCKCLEAR:
   4.422          case SDLK_CAPSLOCK:
   4.423              break;
   4.424          case SDLK_LCTRL:
   4.425 @@ -621,9 +436,9 @@
   4.426          return 0;
   4.427      }
   4.428  
   4.429 -    if (key != SDLK_UNKNOWN) {
   4.430 +    if (physicalKey != SDLK_UNKNOWN) {
   4.431          /* Drop events that don't change state */
   4.432 -        if (keyboard->keystate[key] == state) {
   4.433 +        if (keyboard->keystate[SDLK_INDEX(physicalKey)] == state) {
   4.434  #if 0
   4.435              printf("Keyboard event didn't change state - dropped!\n");
   4.436  #endif
   4.437 @@ -631,7 +446,7 @@
   4.438          }
   4.439  
   4.440          /* Update internal keyboard state */
   4.441 -        keyboard->keystate[key] = state;
   4.442 +        keyboard->keystate[SDLK_INDEX(physicalKey)] = state;
   4.443      }
   4.444  
   4.445      /* Post the event, if desired */
   4.446 @@ -642,7 +457,7 @@
   4.447          event.key.which = (Uint8) index;
   4.448          event.key.state = state;
   4.449          event.key.keysym.scancode = scancode;
   4.450 -        event.key.keysym.sym = (Uint16) key;
   4.451 +        event.key.keysym.sym = physicalKey;
   4.452          event.key.keysym.mod = modstate;
   4.453          event.key.keysym.unicode = 0;
   4.454          event.key.windowID = keyboard->focus;
     5.1 --- a/src/events/SDL_keyboard_c.h	Sat Aug 18 05:39:09 2007 +0000
     5.2 +++ b/src/events/SDL_keyboard_c.h	Sun Aug 19 14:52:52 2007 +0000
     5.3 @@ -65,6 +65,12 @@
     5.4  /* Clear the state of a keyboard at an index */
     5.5  extern void SDL_ResetKeyboard(int index);
     5.6  
     5.7 +/* Set a platform-dependent key name, overriding the default platform-agnostic
     5.8 +   name. Encoded as UTF-8. The string is not copied, thus the pointer given to
     5.9 +   this function must stay valid forever (or at least until the call to
    5.10 +   VideoQuit()). */
    5.11 +extern void SDL_SetKeyName(SDLKey physicalKey, const char *name);
    5.12 +
    5.13  /* Set the keyboard focus window */
    5.14  extern void SDL_SetKeyboardFocus(int index, SDL_WindowID windowID);
    5.15  
     6.1 --- a/src/video/SDL_sysvideo.h	Sat Aug 18 05:39:09 2007 +0000
     6.2 +++ b/src/video/SDL_sysvideo.h	Sun Aug 19 14:52:52 2007 +0000
     6.3 @@ -25,6 +25,7 @@
     6.4  #define _SDL_sysvideo_h
     6.5  
     6.6  #include "SDL_mouse.h"
     6.7 +#include "SDL_keysym.h"
     6.8  
     6.9  /* The SDL video driver */
    6.10  
    6.11 @@ -256,6 +257,45 @@
    6.12       */
    6.13      void (*PumpEvents) (_THIS);
    6.14  
    6.15 +    /* Get the layout key code corresponding to the given physical key code
    6.16 +     * according to the OS' current keyboard layout.
    6.17 +     *
    6.18 +     * - For character keys, this should return the Unicode code point of the
    6.19 +     * character that is generated when the key is pressed without shift or
    6.20 +     * any other modifiers.
    6.21 +     * - For non-character keys, this should return one of the SDLK_* constants
    6.22 +     * (usually the argument itself since these keys are typically layout-
    6.23 +     * independent). Make sure that all of these values returned by this
    6.24 +     * function have a suitable name defined, either the default from
    6.25 +     * SDL_keynames.h, or one set using SDL_SetKeyName() in VideoInit(). In
    6.26 +     * particular, if this function can return any of the codes whose default
    6.27 +     * names start with "SDLK_" (usually, it shouldn't, since these are layout-
    6.28 +     * dependent character keys), these names should be replaced by proper
    6.29 +     * user-readable names.
    6.30 +     * - If there are keys that cannot be adequately described by either a
    6.31 +     * single Unicode character or an SDLK_* constant, this function may return
    6.32 +     * a code with SDL_KEY_LAYOUT_SPECIAL_BIT set in the most significant byte
    6.33 +     * and an arbitrary value in the less significant 3 bytes. The
    6.34 +     * GetSpecialKeyName() function must then be implemented to take this code
    6.35 +     * and return a human-readable key name for it.
    6.36 +     * If the argument is not a physical key code or if translation of the key
    6.37 +     * code by the OS' keyboard layout fails for any reason, the argument must
    6.38 +     * be returned unchanged.
    6.39 +     *
    6.40 +     * On platforms that don't have the notion of a user-configurable keyboard
    6.41 +     * layout, this may be left unimplemented. The default implementation of
    6.42 +     * SDL_GetLayoutKey() then acts as the identity. The note about defining
    6.43 +     * key names above particularly applies in this case.
    6.44 +     */
    6.45 +      SDLKey(*GetLayoutKey) (_THIS, SDLKey physicalKey);
    6.46 +
    6.47 +    /* Get a human-readable name for a special layout key code.
    6.48 +     * This only needs to be implemented if this driver's implementation of
    6.49 +     * GetLayoutKey() generates such codes (with SDL_KEY_LAYOUT_SPECIAL_BIT
    6.50 +     * set) - see above.
    6.51 +     */
    6.52 +    const char *(*GetSpecialKeyName) (_THIS, SDLKey layoutKey);
    6.53 +
    6.54      /* * * */
    6.55      /* Data common to all drivers */
    6.56      int num_displays;
     7.1 --- a/src/video/cocoa/SDL_cocoakeyboard.h	Sat Aug 18 05:39:09 2007 +0000
     7.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.h	Sun Aug 19 14:52:52 2007 +0000
     7.3 @@ -26,6 +26,7 @@
     7.4  
     7.5  extern void Cocoa_InitKeyboard(_THIS);
     7.6  extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
     7.7 +extern SDLKey Cocoa_GetLayoutKey(_THIS, SDLKey physicalKey);
     7.8  extern void Cocoa_QuitKeyboard(_THIS);
     7.9  
    7.10  #endif /* _SDL_cocoakeyboard_h */
     8.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Sat Aug 18 05:39:09 2007 +0000
     8.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Sun Aug 19 14:52:52 2007 +0000
     8.3 @@ -26,6 +26,8 @@
     8.4  
     8.5  #include "../../events/SDL_keyboard_c.h"
     8.6  
     8.7 +#include <Carbon/Carbon.h>
     8.8 +
     8.9  
    8.10  #ifndef NX_DEVICERCTLKEYMASK
    8.11      #define NX_DEVICELCTLKEYMASK    0x00000001
    8.12 @@ -52,192 +54,6 @@
    8.13      #define NX_DEVICERCTLKEYMASK    0x00002000
    8.14  #endif
    8.15  
    8.16 -static void
    8.17 -InitKeymap (SDLKey *keymap)
    8.18 -{
    8.19 -    const void *KCHRPtr;
    8.20 -    UInt32 state;
    8.21 -    UInt32 value;
    8.22 -    int i;
    8.23 -
    8.24 -    for ( i=0; i<256; ++i )
    8.25 -        keymap[i] = SDLK_UNKNOWN;
    8.26 -
    8.27 -    /* This keymap is almost exactly the same as the OS 9 one */
    8.28 -    keymap[KEY_ESCAPE] = SDLK_ESCAPE;
    8.29 -    keymap[KEY_F1] = SDLK_F1;
    8.30 -    keymap[KEY_F2] = SDLK_F2;
    8.31 -    keymap[KEY_F3] = SDLK_F3;
    8.32 -    keymap[KEY_F4] = SDLK_F4;
    8.33 -    keymap[KEY_F5] = SDLK_F5;
    8.34 -    keymap[KEY_F6] = SDLK_F6;
    8.35 -    keymap[KEY_F7] = SDLK_F7;
    8.36 -    keymap[KEY_F8] = SDLK_F8;
    8.37 -    keymap[KEY_F9] = SDLK_F9;
    8.38 -    keymap[KEY_F10] = SDLK_F10;
    8.39 -    keymap[KEY_F11] = SDLK_F11;
    8.40 -    keymap[KEY_F12] = SDLK_F12;
    8.41 -    keymap[KEY_F13] = SDLK_F13;
    8.42 -    keymap[KEY_F14] = SDLK_F14;
    8.43 -    keymap[KEY_F15] = SDLK_F15;
    8.44 -/*
    8.45 -    keymap[KEY_PRINT] = SDLK_PRINT;
    8.46 -    keymap[KEY_SCROLLOCK] = SDLK_SCROLLOCK;
    8.47 -    keymap[KEY_PAUSE] = SDLK_PAUSE;
    8.48 -*/
    8.49 -    keymap[KEY_POWER] = SDLK_POWER;
    8.50 -    keymap[KEY_BACKQUOTE] = SDLK_BACKQUOTE;
    8.51 -    keymap[KEY_1] = SDLK_1;
    8.52 -    keymap[KEY_2] = SDLK_2;
    8.53 -    keymap[KEY_3] = SDLK_3;
    8.54 -    keymap[KEY_4] = SDLK_4;
    8.55 -    keymap[KEY_5] = SDLK_5;
    8.56 -    keymap[KEY_6] = SDLK_6;
    8.57 -    keymap[KEY_7] = SDLK_7;
    8.58 -    keymap[KEY_8] = SDLK_8;
    8.59 -    keymap[KEY_9] = SDLK_9;
    8.60 -    keymap[KEY_0] = SDLK_0;
    8.61 -    keymap[KEY_MINUS] = SDLK_MINUS;
    8.62 -    keymap[KEY_EQUALS] = SDLK_EQUALS;
    8.63 -    keymap[KEY_BACKSPACE] = SDLK_BACKSPACE;
    8.64 -    keymap[KEY_INSERT] = SDLK_INSERT;
    8.65 -    keymap[KEY_HOME] = SDLK_HOME;
    8.66 -    keymap[KEY_PAGEUP] = SDLK_PAGEUP;
    8.67 -    keymap[KEY_NUMLOCK] = SDLK_NUMLOCK;
    8.68 -    keymap[KEY_KP_EQUALS] = SDLK_KP_EQUALS;
    8.69 -    keymap[KEY_KP_DIVIDE] = SDLK_KP_DIVIDE;
    8.70 -    keymap[KEY_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
    8.71 -    keymap[KEY_TAB] = SDLK_TAB;
    8.72 -    keymap[KEY_q] = SDLK_q;
    8.73 -    keymap[KEY_w] = SDLK_w;
    8.74 -    keymap[KEY_e] = SDLK_e;
    8.75 -    keymap[KEY_r] = SDLK_r;
    8.76 -    keymap[KEY_t] = SDLK_t;
    8.77 -    keymap[KEY_y] = SDLK_y;
    8.78 -    keymap[KEY_u] = SDLK_u;
    8.79 -    keymap[KEY_i] = SDLK_i;
    8.80 -    keymap[KEY_o] = SDLK_o;
    8.81 -    keymap[KEY_p] = SDLK_p;
    8.82 -    keymap[KEY_LEFTBRACKET] = SDLK_LEFTBRACKET;
    8.83 -    keymap[KEY_RIGHTBRACKET] = SDLK_RIGHTBRACKET;
    8.84 -    keymap[KEY_BACKSLASH] = SDLK_BACKSLASH;
    8.85 -    keymap[KEY_DELETE] = SDLK_DELETE;
    8.86 -    keymap[KEY_END] = SDLK_END;
    8.87 -    keymap[KEY_PAGEDOWN] = SDLK_PAGEDOWN;
    8.88 -    keymap[KEY_KP7] = SDLK_KP7;
    8.89 -    keymap[KEY_KP8] = SDLK_KP8;
    8.90 -    keymap[KEY_KP9] = SDLK_KP9;
    8.91 -    keymap[KEY_KP_MINUS] = SDLK_KP_MINUS;
    8.92 -    keymap[KEY_CAPSLOCK] = SDLK_CAPSLOCK;
    8.93 -    keymap[KEY_a] = SDLK_a;
    8.94 -    keymap[KEY_s] = SDLK_s;
    8.95 -    keymap[KEY_d] = SDLK_d;
    8.96 -    keymap[KEY_f] = SDLK_f;
    8.97 -    keymap[KEY_g] = SDLK_g;
    8.98 -    keymap[KEY_h] = SDLK_h;
    8.99 -    keymap[KEY_j] = SDLK_j;
   8.100 -    keymap[KEY_k] = SDLK_k;
   8.101 -    keymap[KEY_l] = SDLK_l;
   8.102 -    keymap[KEY_SEMICOLON] = SDLK_SEMICOLON;
   8.103 -    keymap[KEY_QUOTE] = SDLK_QUOTE;
   8.104 -    keymap[KEY_RETURN] = SDLK_RETURN;
   8.105 -    keymap[KEY_KP4] = SDLK_KP4;
   8.106 -    keymap[KEY_KP5] = SDLK_KP5;
   8.107 -    keymap[KEY_KP6] = SDLK_KP6;
   8.108 -    keymap[KEY_KP_PLUS] = SDLK_KP_PLUS;
   8.109 -    keymap[KEY_LSHIFT] = SDLK_LSHIFT;
   8.110 -    keymap[KEY_RSHIFT] = SDLK_RSHIFT;
   8.111 -    keymap[KEY_z] = SDLK_z;
   8.112 -    keymap[KEY_x] = SDLK_x;
   8.113 -    keymap[KEY_c] = SDLK_c;
   8.114 -    keymap[KEY_v] = SDLK_v;
   8.115 -    keymap[KEY_b] = SDLK_b;
   8.116 -    keymap[KEY_n] = SDLK_n;
   8.117 -    keymap[KEY_m] = SDLK_m;
   8.118 -    keymap[KEY_COMMA] = SDLK_COMMA;
   8.119 -    keymap[KEY_PERIOD] = SDLK_PERIOD;
   8.120 -    keymap[KEY_SLASH] = SDLK_SLASH;
   8.121 -    keymap[KEY_UP] = SDLK_UP;
   8.122 -    keymap[KEY_KP1] = SDLK_KP1;
   8.123 -    keymap[KEY_KP2] = SDLK_KP2;
   8.124 -    keymap[KEY_KP3] = SDLK_KP3;
   8.125 -    keymap[KEY_KP_ENTER] = SDLK_KP_ENTER;
   8.126 -    keymap[KEY_LCTRL] = SDLK_LCTRL;
   8.127 -    keymap[KEY_LALT] = SDLK_LALT;
   8.128 -    keymap[KEY_LMETA] = SDLK_LMETA;
   8.129 -    keymap[KEY_RCTRL] = SDLK_RCTRL;
   8.130 -    keymap[KEY_RALT] = SDLK_RALT;
   8.131 -    keymap[KEY_RMETA] = SDLK_RMETA;
   8.132 -    keymap[KEY_SPACE] = SDLK_SPACE;
   8.133 -    keymap[KEY_LEFT] = SDLK_LEFT;
   8.134 -    keymap[KEY_DOWN] = SDLK_DOWN;
   8.135 -    keymap[KEY_RIGHT] = SDLK_RIGHT;
   8.136 -    keymap[KEY_KP0] = SDLK_KP0;
   8.137 -    keymap[KEY_KP_PERIOD] = SDLK_KP_PERIOD;
   8.138 -    keymap[KEY_IBOOK_ENTER] = SDLK_KP_ENTER;
   8.139 -    keymap[KEY_IBOOK_RIGHT] = SDLK_RIGHT;
   8.140 -    keymap[KEY_IBOOK_DOWN] = SDLK_DOWN;
   8.141 -    keymap[KEY_IBOOK_UP]      = SDLK_UP;
   8.142 -    keymap[KEY_IBOOK_LEFT] = SDLK_LEFT;
   8.143 -
   8.144 -    /* 
   8.145 -        Up there we setup a static scancode->keysym map. However, it will not
   8.146 -        work very well on international keyboard. Hence we now query Mac OS X
   8.147 -        for its own keymap to adjust our own mapping table. However, this is
   8.148 -        basically only useful for ascii char keys. This is also the reason
   8.149 -        why we keep the static table, too.
   8.150 -     */
   8.151 -
   8.152 -    /* Get a pointer to the systems cached KCHR */
   8.153 -    KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
   8.154 -    if (KCHRPtr) {
   8.155 -        /* Loop over all 127 possible scan codes */
   8.156 -        for (i = 0; i < 0x7F; i++) {
   8.157 -            /* We pretend a clean start to begin with (i.e. no dead keys active */
   8.158 -            state = 0;
   8.159 -
   8.160 -            /* Now translate the key code to a key value */
   8.161 -            value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   8.162 -
   8.163 -            /* If the state become 0, it was a dead key. We need to translate again,
   8.164 -                passing in the new state, to get the actual key value */
   8.165 -            if (state != 0)
   8.166 -                value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
   8.167 -
   8.168 -            /* Now we should have a latin1 value, which are SDL keysyms */
   8.169 -            if (value >= 32 && value <= 255) {
   8.170 -                keymap[i] = value;
   8.171 -            }
   8.172 -        }
   8.173 -    }
   8.174 -
   8.175 -    /* 
   8.176 -        The keypad codes are re-setup here, because the loop above cannot
   8.177 -        distinguish between a key on the keypad and a regular key. We maybe
   8.178 -        could get around this problem in another fashion: NSEvent's flags
   8.179 -        include a "NSNumericPadKeyMask" bit; we could check that and modify
   8.180 -        the symbol we return on the fly. However, this flag seems to exhibit
   8.181 -        some weird behaviour related to the num lock key
   8.182 -    */
   8.183 -    keymap[KEY_KP0] = SDLK_KP0;
   8.184 -    keymap[KEY_KP1] = SDLK_KP1;
   8.185 -    keymap[KEY_KP2] = SDLK_KP2;
   8.186 -    keymap[KEY_KP3] = SDLK_KP3;
   8.187 -    keymap[KEY_KP4] = SDLK_KP4;
   8.188 -    keymap[KEY_KP5] = SDLK_KP5;
   8.189 -    keymap[KEY_KP6] = SDLK_KP6;
   8.190 -    keymap[KEY_KP7] = SDLK_KP7;
   8.191 -    keymap[KEY_KP8] = SDLK_KP8;
   8.192 -    keymap[KEY_KP9] = SDLK_KP9;
   8.193 -    keymap[KEY_KP_MINUS] = SDLK_KP_MINUS;
   8.194 -    keymap[KEY_KP_PLUS] = SDLK_KP_PLUS;
   8.195 -    keymap[KEY_KP_PERIOD] = SDLK_KP_PERIOD;
   8.196 -    keymap[KEY_KP_EQUALS] = SDLK_KP_EQUALS;
   8.197 -    keymap[KEY_KP_DIVIDE] = SDLK_KP_DIVIDE;
   8.198 -    keymap[KEY_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
   8.199 -    keymap[KEY_KP_ENTER] = SDLK_KP_ENTER;
   8.200 -}
   8.201 -
   8.202  /* This is the original behavior, before support was added for 
   8.203   * differentiating between left and right versions of the keys.
   8.204   */
   8.205 @@ -433,8 +249,8 @@
   8.206      newMask = newMods & NSNumericPadKeyMask;
   8.207  
   8.208      if (oldMask != newMask) {
   8.209 -        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_NUMLOCK);
   8.210 -        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_NUMLOCK);
   8.211 +        SDL_SendKeyboardKey(keyboard, SDL_PRESSED, (Uint8)scancode, SDLK_KP_NUMLOCKCLEAR);
   8.212 +        SDL_SendKeyboardKey(keyboard, SDL_RELEASED, (Uint8)scancode, SDLK_KP_NUMLOCKCLEAR);
   8.213      }
   8.214  }
   8.215  
   8.216 @@ -513,14 +329,19 @@
   8.217      SDL_Keyboard keyboard;
   8.218      NSAutoreleasePool *pool;
   8.219  
   8.220 -    InitKeymap(data->keymap);
   8.221 -
   8.222      pool = [[NSAutoreleasePool alloc] init];
   8.223      data->fieldEdit = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 0.0, 0.0)];
   8.224      [pool release];
   8.225      
   8.226      SDL_zero(keyboard);
   8.227      data->keyboard = SDL_AddKeyboard(&keyboard, -1);
   8.228 +    
   8.229 +    /* Set our own names for the platform-dependent but layout-independent keys */
   8.230 +    SDL_SetKeyName(SDLK_KP_NUMLOCKCLEAR, "clear");
   8.231 +    SDL_SetKeyName(SDLK_LALT, "left option");
   8.232 +    SDL_SetKeyName(SDLK_LMETA, "left command");
   8.233 +    SDL_SetKeyName(SDLK_RALT, "right option");
   8.234 +    SDL_SetKeyName(SDLK_RMETA, "right command");
   8.235  }
   8.236  
   8.237  void
   8.238 @@ -528,20 +349,33 @@
   8.239  {
   8.240      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   8.241      unsigned short scancode = [event keyCode];
   8.242 +    SDLKey physicalKey;
   8.243      const char *text;
   8.244  
   8.245 -    if (scancode >= 256) {
   8.246 +    if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
   8.247 +        /* see comments in SDL_cocoakeys.h */
   8.248 +        scancode = 60 - scancode;
   8.249 +    }
   8.250 +    if (scancode < SDL_arraysize(macToSDLKey)) {
   8.251 +        physicalKey = macToSDLKey[scancode];
   8.252 +    }
   8.253 +    else {
   8.254          /* Hmm, does this ever happen?  If so, need to extend the keymap... */
   8.255 -        return;
   8.256 +        physicalKey = SDLK_UNKNOWN;
   8.257      }
   8.258  
   8.259      switch ([event type]) {
   8.260      case NSKeyDown:
   8.261          if (![event isARepeat]) {
   8.262 -            SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, (Uint8)scancode,
   8.263 -                                data->keymap[scancode]);
   8.264 +            SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, (Uint8)scancode, physicalKey);
   8.265 +#if 1
   8.266 +            if (physicalKey == SDLK_UNKNOWN) {
   8.267 +                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);
   8.268 +            }
   8.269 +#endif
   8.270          }
   8.271          if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
   8.272 +            /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */
   8.273              [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
   8.274              text = [[event characters] UTF8String];
   8.275              if(text && *text) {
   8.276 @@ -550,12 +384,136 @@
   8.277          }
   8.278          break;
   8.279      case NSKeyUp:
   8.280 -        SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, (Uint8)scancode,
   8.281 -                            data->keymap[scancode]);
   8.282 +        SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, (Uint8)scancode, physicalKey);
   8.283          break;
   8.284      case NSFlagsChanged:
   8.285 +        /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */
   8.286          HandleModifiers(_this, scancode, [event modifierFlags]);
   8.287          break;
   8.288 +    default: /* just to avoid compiler warnings */
   8.289 +        break;
   8.290 +    }
   8.291 +}
   8.292 +
   8.293 +SDLKey
   8.294 +Cocoa_GetLayoutKey(_THIS, SDLKey physicalKey)
   8.295 +{
   8.296 +    switch (physicalKey) {
   8.297 +        /* Many of these keys would generate a character in the translation by keyboard layout, but an inappropriate one, so we catch them before. */
   8.298 +        case SDLK_UNKNOWN:
   8.299 +        case SDLK_RETURN:
   8.300 +        case SDLK_ESCAPE:
   8.301 +        case SDLK_BACKSPACE:
   8.302 +        case SDLK_TAB:
   8.303 +        case SDLK_SPACE:
   8.304 +        case SDLK_CAPSLOCK:
   8.305 +        case SDLK_F1:
   8.306 +        case SDLK_F2:
   8.307 +        case SDLK_F3:
   8.308 +        case SDLK_F4:
   8.309 +        case SDLK_F5:
   8.310 +        case SDLK_F6:
   8.311 +        case SDLK_F7:
   8.312 +        case SDLK_F8:
   8.313 +        case SDLK_F9:
   8.314 +        case SDLK_F10:
   8.315 +        case SDLK_F11:
   8.316 +        case SDLK_F12:
   8.317 +        case SDLK_PRINTSCREEN:
   8.318 +        case SDLK_SCROLLLOCK:
   8.319 +        case SDLK_PAUSE:
   8.320 +        case SDLK_INSERT:
   8.321 +        case SDLK_HOME:
   8.322 +        case SDLK_PAGEUP:
   8.323 +        case SDLK_DELETE:
   8.324 +        case SDLK_END:
   8.325 +        case SDLK_PAGEDOWN:
   8.326 +        case SDLK_RIGHT:
   8.327 +        case SDLK_LEFT:
   8.328 +        case SDLK_DOWN:
   8.329 +        case SDLK_UP:
   8.330 +        case SDLK_KP_NUMLOCKCLEAR:
   8.331 +        case SDLK_KP_ENTER:
   8.332 +        case SDLK_APPLICATION:
   8.333 +        case SDLK_POWER:
   8.334 +        case SDLK_F13:
   8.335 +        case SDLK_F14:
   8.336 +        case SDLK_F15:
   8.337 +        case SDLK_F16:
   8.338 +        case SDLK_LCTRL:
   8.339 +        case SDLK_LSHIFT:
   8.340 +        case SDLK_LALT:
   8.341 +        case SDLK_LMETA:
   8.342 +        case SDLK_RCTRL:
   8.343 +        case SDLK_RSHIFT:
   8.344 +        case SDLK_RALT:
   8.345 +        case SDLK_RMETA:
   8.346 +            return physicalKey;
   8.347 +        
   8.348 +        /* For the rest, we try the translation first. */
   8.349 +        default: {
   8.350 +            UInt16 vkey = 0;
   8.351 +            KeyboardLayoutRef layout;
   8.352 +            KeyboardLayoutKind kind;
   8.353 +            UInt32 keyboardType = LMGetKbdType();
   8.354 +            
   8.355 +            /* Look up pkey to get a Mac virtual key code - linear search isn't terribly efficient, this might have to be optimized. */
   8.356 +            while (vkey < 128 && physicalKey != macToSDLKey[vkey]) vkey++;
   8.357 +            if (vkey == 128) return physicalKey;
   8.358 +            if ((vkey == 10 || vkey == 50) && KBGetLayoutType(keyboardType) == kKeyboardISO) vkey = 60 - vkey; /* see comments in SDL_cocoakeys.h */
   8.359 +            
   8.360 +            if (KLGetCurrentKeyboardLayout(&layout) != noErr) return physicalKey;
   8.361 +            if (KLGetKeyboardLayoutProperty(layout, kKLKind, (const void **)&kind) != noErr) return physicalKey;
   8.362 +            if (kind == kKLKCHRuchrKind || kind == kKLuchrKind) {
   8.363 +                UniChar utf16String[4];
   8.364 +                UInt32 deadKeyState = 0;
   8.365 +                UniCharCount actualStringLength;
   8.366 +                const UCKeyboardLayout *uchrData;
   8.367 +                
   8.368 +                if (KLGetKeyboardLayoutProperty(layout, kKLuchrData, (const void **)&uchrData) != noErr) return physicalKey;
   8.369 +                if (UCKeyTranslate(uchrData, vkey, kUCKeyActionDisplay, 0, keyboardType, 0, &deadKeyState, 4, &actualStringLength, utf16String) != noErr) return physicalKey;
   8.370 +                /* 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 */
   8.371 +                
   8.372 +                if (actualStringLength == 0) return physicalKey;
   8.373 +                
   8.374 +                /* 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. */
   8.375 +                if (utf16String[0] < 0xD800 || utf16String[0] > 0xDFFF) {
   8.376 +                    return utf16String[0];
   8.377 +                }
   8.378 +                else if (utf16String[0] > 0xDBFF || utf16String[1] < 0xDC00 || utf16String[1] > 0xDFFF) {
   8.379 +                    /* invalid UTF-16 */
   8.380 +                    return physicalKey;
   8.381 +                }
   8.382 +                else {
   8.383 +                    return (((utf16String[0] & 0x3FF) << 10) | (utf16String[1] & 0x3FF)) + 0x10000;
   8.384 +                }
   8.385 +            }
   8.386 +            else { /* kind == kKLKCHRKind */
   8.387 +                const void *kchrData;
   8.388 +                UInt32 state = 0;
   8.389 +                UInt8 charCode;
   8.390 +                SInt32 scriptCode;
   8.391 +                TextEncoding keyboardEncoding;
   8.392 +                CFStringRef conversionString;
   8.393 +                UniChar codepoint;
   8.394 +                
   8.395 +                if (KLGetKeyboardLayoutProperty(layout, kKLKCHRData, &kchrData) != noErr) return physicalKey;
   8.396 +                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 */
   8.397 +                if (charCode == 0) {
   8.398 +                    /* It's a dead key, so simulate a second key press */
   8.399 +                    charCode = KeyTranslate(kchrData, vkey, &state) & 0xFF;
   8.400 +                    /* Still zero? Give up. */
   8.401 +                    if (charCode == 0) return physicalKey;
   8.402 +                }
   8.403 +                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> */
   8.404 +                if (UpgradeScriptInfoToTextEncoding(scriptCode, kTextLanguageDontCare, kTextRegionDontCare, NULL, &keyboardEncoding) != noErr) return physicalKey;
   8.405 +                
   8.406 +                conversionString = CFStringCreateWithBytes(kCFAllocatorDefault, &charCode, 1, keyboardEncoding, FALSE);
   8.407 +                codepoint = CFStringGetCharacterAtIndex(conversionString, 0);
   8.408 +                CFRelease(conversionString);
   8.409 +                return codepoint;
   8.410 +            }
   8.411 +        }
   8.412      }
   8.413  }
   8.414  
     9.1 --- a/src/video/cocoa/SDL_cocoakeys.h	Sat Aug 18 05:39:09 2007 +0000
     9.2 +++ b/src/video/cocoa/SDL_cocoakeys.h	Sun Aug 19 14:52:52 2007 +0000
     9.3 @@ -19,128 +19,142 @@
     9.4      Sam Lantinga
     9.5      slouken@libsdl.org
     9.6  */
     9.7 -#include "SDL_config.h"
     9.8  
     9.9 -/* These are the Macintosh key scancode constants -- from Inside Macintosh */
    9.10 -
    9.11 -#define KEY_ESCAPE		0x35
    9.12 -#define KEY_F1			0x7A
    9.13 -#define KEY_F2			0x78
    9.14 -#define KEY_F3			0x63
    9.15 -#define KEY_F4			0x76
    9.16 -#define KEY_F5			0x60
    9.17 -#define KEY_F6			0x61
    9.18 -#define KEY_F7			0x62
    9.19 -#define KEY_F8			0x64
    9.20 -#define KEY_F9			0x65
    9.21 -#define KEY_F10			0x6D
    9.22 -#define KEY_F11			0x67
    9.23 -#define KEY_F12			0x6F
    9.24 -#define KEY_F13			0x69
    9.25 -#define KEY_F14			0x6B
    9.26 -#define KEY_F15			0x71
    9.27 -/*
    9.28 -#define KEY_PRINT		0x69
    9.29 -#define KEY_SCROLLOCK    0x6B
    9.30 -#define KEY_PAUSE		0x71
    9.31 +/* Mac virtual key code to SDLKey mapping table
    9.32 +   Sources:
    9.33 +   - Inside Macintosh: Text <http://developer.apple.com/documentation/mac/Text/Text-571.html>
    9.34 +   - Apple USB keyboard driver source <http://darwinsource.opendarwin.org/10.4.6.ppc/IOHIDFamily-172.8/IOHIDFamily/Cosmo_USB2ADB.c>
    9.35 +   - experimentation on various ADB and USB ISO keyboards and one ADB ANSI keyboard
    9.36  */
    9.37 -#define KEY_POWER		0x7F
    9.38 -#define KEY_BACKQUOTE	0x32
    9.39 -#define KEY_1			0x12
    9.40 -#define KEY_2			0x13
    9.41 -#define KEY_3			0x14
    9.42 -#define KEY_4			0x15
    9.43 -#define KEY_5			0x17
    9.44 -#define KEY_6			0x16
    9.45 -#define KEY_7			0x1A
    9.46 -#define KEY_8			0x1C
    9.47 -#define KEY_9			0x19
    9.48 -#define KEY_0			0x1D
    9.49 -#define KEY_MINUS		0x1B
    9.50 -#define KEY_EQUALS		0x18
    9.51 -#define KEY_BACKSPACE	0x33
    9.52 -#define KEY_INSERT		0x72
    9.53 -#define KEY_HOME			0x73
    9.54 -#define KEY_PAGEUP		0x74
    9.55 -#define KEY_NUMLOCK		0x47
    9.56 -#define KEY_KP_EQUALS	0x51
    9.57 -#define KEY_KP_DIVIDE	0x4B
    9.58 -#define KEY_KP_MULTIPLY	0x43
    9.59 -#define KEY_TAB			0x30
    9.60 -#define KEY_q			0x0C
    9.61 -#define KEY_w			0x0D
    9.62 -#define KEY_e			0x0E
    9.63 -#define KEY_r			0x0F
    9.64 -#define KEY_t			0x11
    9.65 -#define KEY_y			0x10
    9.66 -#define KEY_u			0x20
    9.67 -#define KEY_i			0x22
    9.68 -#define KEY_o			0x1F
    9.69 -#define KEY_p			0x23
    9.70 -#define KEY_LEFTBRACKET	0x21
    9.71 -#define KEY_RIGHTBRACKET	0x1E
    9.72 -#define KEY_BACKSLASH	0x2A
    9.73 -#define KEY_DELETE		0x75
    9.74 -#define KEY_END			0x77
    9.75 -#define KEY_PAGEDOWN		0x79
    9.76 -#define KEY_KP7			0x59
    9.77 -#define KEY_KP8			0x5B
    9.78 -#define KEY_KP9			0x5C
    9.79 -#define KEY_KP_MINUS		0x4E
    9.80 -#define KEY_CAPSLOCK		0x39
    9.81 -#define KEY_a			0x00
    9.82 -#define KEY_s			0x01
    9.83 -#define KEY_d			0x02
    9.84 -#define KEY_f			0x03
    9.85 -#define KEY_g			0x05
    9.86 -#define KEY_h			0x04
    9.87 -#define KEY_j			0x26
    9.88 -#define KEY_k			0x28
    9.89 -#define KEY_l			0x25
    9.90 -#define KEY_SEMICOLON	0x29
    9.91 -#define KEY_QUOTE		0x27
    9.92 -#define KEY_RETURN		0x24
    9.93 -#define KEY_KP4			0x56
    9.94 -#define KEY_KP5			0x57
    9.95 -#define KEY_KP6			0x58
    9.96 -#define KEY_KP_PLUS		0x45
    9.97 -#define KEY_LSHIFT		0x38
    9.98 -#define KEY_z			0x06
    9.99 -#define KEY_x			0x07
   9.100 -#define KEY_c			0x08
   9.101 -#define KEY_v			0x09
   9.102 -#define KEY_b			0x0B
   9.103 -#define KEY_n			0x2D
   9.104 -#define KEY_m			0x2E
   9.105 -#define KEY_COMMA		0x2B
   9.106 -#define KEY_PERIOD		0x2F
   9.107 -#define KEY_SLASH		0x2C
   9.108 -#if 1                           /* Panther now defines right side keys */
   9.109 -#define KEY_RSHIFT		0x3C
   9.110 -#endif
   9.111 -#define KEY_UP			0x7E
   9.112 -#define KEY_KP1			0x53
   9.113 -#define KEY_KP2			0x54
   9.114 -#define KEY_KP3			0x55
   9.115 -#define KEY_KP_ENTER		0x4C
   9.116 -#define KEY_LCTRL		0x3B
   9.117 -#define KEY_LALT			0x3A
   9.118 -#define KEY_LMETA		0x37
   9.119 -#define KEY_SPACE		0x31
   9.120 -#if 1                           /* Panther now defines right side keys */
   9.121 -#define KEY_RMETA		0x36
   9.122 -#define KEY_RALT			0x3D
   9.123 -#define KEY_RCTRL		0x3E
   9.124 -#endif
   9.125 -#define KEY_LEFT			0x7B
   9.126 -#define KEY_DOWN			0x7D
   9.127 -#define KEY_RIGHT		0x7C
   9.128 -#define KEY_KP0			0x52
   9.129 -#define KEY_KP_PERIOD	0x41
   9.130 -
   9.131 -/* Wierd, these keys are on my iBook under Mac OS X */
   9.132 -#define KEY_IBOOK_ENTER		0x34
   9.133 -#define KEY_IBOOK_LEFT		0x3B
   9.134 -#define KEY_IBOOK_RIGHT		0x3C
   9.135 -#define KEY_IBOOK_DOWN		0x3D
   9.136 -#define KEY_IBOOK_UP			0x3E
   9.137 +/* *INDENT-OFF* */
   9.138 +static SDLKey macToSDLKey[128] = {
   9.139 +    /*   0 */   SDLK_A,
   9.140 +    /*   1 */   SDLK_S,
   9.141 +    /*   2 */   SDLK_D,
   9.142 +    /*   3 */   SDLK_F,
   9.143 +    /*   4 */   SDLK_H,
   9.144 +    /*   5 */   SDLK_G,
   9.145 +    /*   6 */   SDLK_Z,
   9.146 +    /*   7 */   SDLK_X,
   9.147 +    /*   8 */   SDLK_C,
   9.148 +    /*   9 */   SDLK_V,
   9.149 +    /*  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.) */
   9.150 +    /*  11 */   SDLK_B,
   9.151 +    /*  12 */   SDLK_Q,
   9.152 +    /*  13 */   SDLK_W,
   9.153 +    /*  14 */   SDLK_E,
   9.154 +    /*  15 */   SDLK_R,
   9.155 +    /*  16 */   SDLK_Y,
   9.156 +    /*  17 */   SDLK_T,
   9.157 +    /*  18 */   SDLK_1,
   9.158 +    /*  19 */   SDLK_2,
   9.159 +    /*  20 */   SDLK_3,
   9.160 +    /*  21 */   SDLK_4,
   9.161 +    /*  22 */   SDLK_6,
   9.162 +    /*  23 */   SDLK_5,
   9.163 +    /*  24 */   SDLK_EQUALS,
   9.164 +    /*  25 */   SDLK_9,
   9.165 +    /*  26 */   SDLK_7,
   9.166 +    /*  27 */   SDLK_HYPHENMINUS,
   9.167 +    /*  28 */   SDLK_8,
   9.168 +    /*  29 */   SDLK_0,
   9.169 +    /*  30 */   SDLK_RIGHTBRACKET,
   9.170 +    /*  31 */   SDLK_O,
   9.171 +    /*  32 */   SDLK_U,
   9.172 +    /*  33 */   SDLK_LEFTBRACKET,
   9.173 +    /*  34 */   SDLK_I,
   9.174 +    /*  35 */   SDLK_P,
   9.175 +    /*  36 */   SDLK_RETURN,
   9.176 +    /*  37 */   SDLK_L,
   9.177 +    /*  38 */   SDLK_J,
   9.178 +    /*  39 */   SDLK_APOSTROPHE,
   9.179 +    /*  40 */   SDLK_K,
   9.180 +    /*  41 */   SDLK_SEMICOLON,
   9.181 +    /*  42 */   SDLK_BACKSLASH,
   9.182 +    /*  43 */   SDLK_COMMA,
   9.183 +    /*  44 */   SDLK_SLASH,
   9.184 +    /*  45 */   SDLK_N,
   9.185 +    /*  46 */   SDLK_M,
   9.186 +    /*  47 */   SDLK_PERIOD,
   9.187 +    /*  48 */   SDLK_TAB,
   9.188 +    /*  49 */   SDLK_SPACE,
   9.189 +    /*  50 */   SDLK_GRAVE, /* SDLK_GRAVE on ANSI and JIS keyboards, SDLK_NONUSBACKSLASH on ISO (see comment about virtual key code 10 above) */
   9.190 +    /*  51 */   SDLK_BACKSPACE,
   9.191 +    /*  52 */   SDLK_KP_ENTER, /* keyboard enter on portables */
   9.192 +    /*  53 */   SDLK_ESCAPE,
   9.193 +    /*  54 */   SDLK_RMETA,
   9.194 +    /*  55 */   SDLK_LMETA,
   9.195 +    /*  56 */   SDLK_LSHIFT,
   9.196 +    /*  57 */   SDLK_CAPSLOCK,
   9.197 +    /*  58 */   SDLK_LALT,
   9.198 +    /*  59 */   SDLK_LCTRL,
   9.199 +    /*  60 */   SDLK_RSHIFT,
   9.200 +    /*  61 */   SDLK_RALT,
   9.201 +    /*  62 */   SDLK_RCTRL,
   9.202 +    /*  63 */   SDLK_NONE, /* fn on portables, acts as a hardware-level modifier already, so we don't generate events for it */
   9.203 +    /*  64 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.204 +    /*  65 */   SDLK_KP_PERIOD,
   9.205 +    /*  66 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.206 +    /*  67 */   SDLK_KP_MULTIPLY,
   9.207 +    /*  68 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.208 +    /*  69 */   SDLK_KP_PLUS,
   9.209 +    /*  70 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.210 +    /*  71 */   SDLK_KP_NUMLOCKCLEAR,
   9.211 +    /*  72 */   SDLK_VOLUMEUP,
   9.212 +    /*  73 */   SDLK_VOLUMEDOWN,
   9.213 +    /*  74 */   SDLK_MUTE,
   9.214 +    /*  75 */   SDLK_KP_DIVIDE,
   9.215 +    /*  76 */   SDLK_KP_ENTER, /* keypad enter on external keyboards, fn-return on portables */
   9.216 +    /*  77 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.217 +    /*  78 */   SDLK_KP_MINUS,
   9.218 +    /*  79 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.219 +    /*  80 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.220 +    /*  81 */   SDLK_KP_EQUALS,
   9.221 +    /*  82 */   SDLK_KP_0,
   9.222 +    /*  83 */   SDLK_KP_1,
   9.223 +    /*  84 */   SDLK_KP_2,
   9.224 +    /*  85 */   SDLK_KP_3,
   9.225 +    /*  86 */   SDLK_KP_4,
   9.226 +    /*  87 */   SDLK_KP_5,
   9.227 +    /*  88 */   SDLK_KP_6,
   9.228 +    /*  89 */   SDLK_KP_7,
   9.229 +    /*  90 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.230 +    /*  91 */   SDLK_KP_8,
   9.231 +    /*  92 */   SDLK_KP_9,
   9.232 +    /*  93 */   SDLK_INTERNATIONAL3, /* Cosmo_USB2ADB.c says "Yen (JIS)" */
   9.233 +    /*  94 */   SDLK_INTERNATIONAL1, /* Cosmo_USB2ADB.c says "Ro (JIS)" */
   9.234 +    /*  95 */   SDLK_KP_COMMA, /* Cosmo_USB2ADB.c says ", JIS only" */
   9.235 +    /*  96 */   SDLK_F5,
   9.236 +    /*  97 */   SDLK_F6,
   9.237 +    /*  98 */   SDLK_F7,
   9.238 +    /*  99 */   SDLK_F3,
   9.239 +    /* 100 */   SDLK_F8,
   9.240 +    /* 101 */   SDLK_F9,
   9.241 +    /* 102 */   SDLK_LANG2, /* Cosmo_USB2ADB.c says "Eisu" */
   9.242 +    /* 103 */   SDLK_F11,
   9.243 +    /* 104 */   SDLK_LANG1, /* Cosmo_USB2ADB.c says "Kana" */
   9.244 +    /* 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. */
   9.245 +    /* 106 */   SDLK_F16,
   9.246 +    /* 107 */   SDLK_SCROLLLOCK, /* F14/scroll lock, see comment about F13/print screen above */
   9.247 +    /* 108 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.248 +    /* 109 */   SDLK_F10,
   9.249 +    /* 110 */   SDLK_APPLICATION, /* windows contextual menu key, fn-enter on portables */
   9.250 +    /* 111 */   SDLK_F12,
   9.251 +    /* 112 */   SDLK_UNKNOWN, /* unknown (unused?) */
   9.252 +    /* 113 */   SDLK_PAUSE, /* F15/pause, see comment about F13/print screen above */
   9.253 +    /* 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 */
   9.254 +    /* 115 */   SDLK_HOME,
   9.255 +    /* 116 */   SDLK_PAGEUP,
   9.256 +    /* 117 */   SDLK_DELETE,
   9.257 +    /* 118 */   SDLK_F4,
   9.258 +    /* 119 */   SDLK_END,
   9.259 +    /* 120 */   SDLK_F2,
   9.260 +    /* 121 */   SDLK_PAGEDOWN,
   9.261 +    /* 122 */   SDLK_F1,
   9.262 +    /* 123 */   SDLK_LEFT,
   9.263 +    /* 124 */   SDLK_RIGHT,
   9.264 +    /* 125 */   SDLK_DOWN,
   9.265 +    /* 126 */   SDLK_UP,
   9.266 +    /* 127 */   SDLK_POWER
   9.267 +};
   9.268 +/* *INDENT-ON* */
    10.1 --- a/src/video/cocoa/SDL_cocoavideo.h	Sat Aug 18 05:39:09 2007 +0000
    10.2 +++ b/src/video/cocoa/SDL_cocoavideo.h	Sun Aug 19 14:52:52 2007 +0000
    10.3 @@ -42,7 +42,6 @@
    10.4  typedef struct SDL_VideoData
    10.5  {
    10.6      SInt32 osversion;
    10.7 -    SDLKey keymap[256];
    10.8      unsigned int modifierFlags;
    10.9      int mouse;
   10.10      int keyboard;
    11.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Sat Aug 18 05:39:09 2007 +0000
    11.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Sun Aug 19 14:52:52 2007 +0000
    11.3 @@ -75,6 +75,7 @@
    11.4      device->GetDisplayModes = Cocoa_GetDisplayModes;
    11.5      device->SetDisplayMode = Cocoa_SetDisplayMode;
    11.6      device->PumpEvents = Cocoa_PumpEvents;
    11.7 +    device->GetLayoutKey = Cocoa_GetLayoutKey;
    11.8  
    11.9      device->CreateWindow = Cocoa_CreateWindow;
   11.10      device->CreateWindowFrom = Cocoa_CreateWindowFrom;
    12.1 --- a/test/common.c	Sat Aug 18 05:39:09 2007 +0000
    12.2 +++ b/test/common.c	Sun Aug 19 14:52:52 2007 +0000
    12.3 @@ -803,14 +803,20 @@
    12.4          }
    12.5          break;
    12.6      case SDL_KEYDOWN:
    12.7 -        fprintf(stderr, "Keyboard %d: key %s pressed in window %d",
    12.8 -                event->key.which, SDL_GetKeyName(event->key.keysym.sym),
    12.9 -                event->key.windowID);
   12.10 +        fprintf(stderr,
   12.11 +                "Keyboard %d: key pressed  in window %d: physical 0x%08X = %s, layout 0x%08X = %s",
   12.12 +                event->key.which, event->key.windowID, event->key.keysym.sym,
   12.13 +                SDL_GetKeyName(event->key.keysym.sym),
   12.14 +                SDL_GetLayoutKey(event->key.keysym.sym),
   12.15 +                SDL_GetKeyName(SDL_GetLayoutKey(event->key.keysym.sym)));
   12.16          break;
   12.17      case SDL_KEYUP:
   12.18 -        fprintf(stderr, "Keyboard %d: key %s released in window %d",
   12.19 -                event->key.which, SDL_GetKeyName(event->key.keysym.sym),
   12.20 -                event->key.windowID);
   12.21 +        fprintf(stderr,
   12.22 +                "Keyboard %d: key released in window %d: physical 0x%08X = %s, layout 0x%08X = %s",
   12.23 +                event->key.which, event->key.windowID, event->key.keysym.sym,
   12.24 +                SDL_GetKeyName(event->key.keysym.sym),
   12.25 +                SDL_GetLayoutKey(event->key.keysym.sym),
   12.26 +                SDL_GetKeyName(SDL_GetLayoutKey(event->key.keysym.sym)));
   12.27          break;
   12.28      case SDL_TEXTINPUT:
   12.29          fprintf(stderr, "Keyboard %d: text input \"%s\" in window %d",