Keyboard code update in progress SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Sat, 10 Jun 2006 09:11:59 +0000
branchSDL-1.3
changeset 1673624e1412fbba
parent 1672 8e754b82cecc
child 1674 7688a73b25b1
Keyboard code update in progress
include/SDL_keyboard.h
include/SDL_keysym.h
include/SDL_mouse.h
src/events/SDL_keyboard.c
src/events/SDL_keyboard_c.h
src/video/SDL_sysvideo.h
     1.1 --- a/include/SDL_keyboard.h	Fri Jun 09 07:06:12 2006 +0000
     1.2 +++ b/include/SDL_keyboard.h	Sat Jun 10 09:11:59 2006 +0000
     1.3 @@ -41,82 +41,116 @@
     1.4  /* *INDENT-ON* */
     1.5  #endif
     1.6  
     1.7 -/* Keysym structure
     1.8 -   - The scancode is hardware dependent, and should not be used by general
     1.9 -     applications.  If no hardware scancode is available, it will be 0.
    1.10 -
    1.11 -   - The 'unicode' translated character is only available when character
    1.12 -     translation is enabled by the SDL_EnableUNICODE() API.  If non-zero,
    1.13 -     this is a UNICODE character corresponding to the keypress.  If the
    1.14 -     high 9 bits of the character are 0, then this maps to the equivalent
    1.15 -     ASCII character:
    1.16 -	char ch;
    1.17 -	if ( (keysym.unicode & 0xFF80) == 0 ) {
    1.18 -		ch = keysym.unicode & 0x7F;
    1.19 -	} else {
    1.20 -		An international character..
    1.21 -	}
    1.22 +/**
    1.23 + * \struct SDL_keysym
    1.24 + *
    1.25 + * \brief The SDL keysym structure, used in key events.
    1.26   */
    1.27  typedef struct SDL_keysym
    1.28  {
    1.29 -    Uint8 scancode;             /* hardware specific scancode */
    1.30 -    SDLKey sym;                 /* SDL virtual keysym */
    1.31 -    SDLMod mod;                 /* current key modifiers */
    1.32 -    Uint16 unicode;             /* translated character */
    1.33 +    Uint8 scancode;             /**< keyboard specific scancode */
    1.34 +    SDLKey sym;                 /**< SDL virtual keysym */
    1.35 +    SDLMod mod;                 /**< current key modifiers */
    1.36  } SDL_keysym;
    1.37  
    1.38 -/* This is the mask which refers to all hotkey bindings */
    1.39 -#define SDL_ALL_HOTKEYS		0xFFFFFFFF
    1.40 +/* Function prototypes */
    1.41  
    1.42 -/* Function prototypes */
    1.43 -/*
    1.44 - * Enable/Disable UNICODE translation of keyboard input.
    1.45 - * This translation has some overhead, so translation defaults off.
    1.46 - * If 'enable' is 1, translation is enabled.
    1.47 - * If 'enable' is 0, translation is disabled.
    1.48 - * If 'enable' is -1, the translation state is not changed.
    1.49 - * It returns the previous state of keyboard translation.
    1.50 +/**
    1.51 + * \fn int SDL_GetNumKeyboards(void)
    1.52 + *
    1.53 + * \brief Get the number of keyboard input devices available.
    1.54 + *
    1.55 + * \sa SDL_SelectKeyboard()
    1.56 + */
    1.57 +extern DECLSPEC int SDLCALL SDL_GetNumKeyboards(void);
    1.58 +
    1.59 +/**
    1.60 + * \fn int SDL_SelectKeyboard(int index)
    1.61 + *
    1.62 + * \brief Set the index of the currently selected keyboard.
    1.63 + *
    1.64 + * \return The index of the previously selected keyboard.
    1.65 + *
    1.66 + * \note You can query the currently selected keyboard by passing an index of -1.
    1.67 + *
    1.68 + * \sa SDL_GetNumKeyboards()
    1.69 + */
    1.70 +extern DECLSPEC int SDLCALL SDL_SelectKeyboard(int index);
    1.71 +
    1.72 +/**
    1.73 + * \fn int SDL_EnableUNICODE(int enable)
    1.74 + *
    1.75 + * \brief Enable/Disable UNICODE translation of keyboard input.
    1.76 + *
    1.77 + * \param enable 1 to enable translation, 0 to disable translation, -1 to query translation
    1.78 + *
    1.79 + * \return The previous state of keyboard translation
    1.80 + *
    1.81 + * \note This translation has some overhead, so translation defaults off.
    1.82   */
    1.83  extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
    1.84  
    1.85 -/*
    1.86 - * Enable/Disable keyboard repeat.  Keyboard repeat defaults to off.
    1.87 - * 'delay' is the initial delay in ms between the time when a key is
    1.88 - * pressed, and keyboard repeat begins.
    1.89 - * 'interval' is the time in ms between keyboard repeat events.
    1.90 +/**
    1.91 + * \fn int SDL_EnableKeyRepeat(int delay, int interval)
    1.92 + * 
    1.93 + * \brief Enable keyboard repeat for the selected keyboard.
    1.94 + *
    1.95 + * \param delay The initial delay in milliseconds between the time when a
    1.96 + *              key is pressed and keyboard repeat begins.  Setting a delay
    1.97 + *              of 0 will disable keyboard repeat.
    1.98 + * \param interval The time in milliseconds between keyboard repeat events.
    1.99 + *
   1.100 + * \return 0 on success, or -1 if there was an error.
   1.101 + *
   1.102 + * \note Keyboard repeat defaults to off.
   1.103   */
   1.104  #define SDL_DEFAULT_REPEAT_DELAY	500
   1.105  #define SDL_DEFAULT_REPEAT_INTERVAL	30
   1.106 -/*
   1.107 - * If 'delay' is set to 0, keyboard repeat is disabled.
   1.108 + /**/
   1.109 +    extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
   1.110 +
   1.111 +/**
   1.112 + * \fn void SDL_GetKeyRepeat(int *delay, int *interval)
   1.113 + *
   1.114 + * \brief Get the current keyboard repeat setting for the selected keyboard.
   1.115   */
   1.116 -extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
   1.117  extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
   1.118  
   1.119 -/*
   1.120 - * Get a snapshot of the current state of the keyboard.
   1.121 - * Returns an array of keystates, indexed by the SDLK_* syms.
   1.122 - * Used:
   1.123 +/**
   1.124 + * \fn Uint8 *SDL_GetKeyState(int *numkeys)
   1.125 + *
   1.126 + * \brief Get a snapshot of the current state of the selected keyboard.
   1.127 + *
   1.128 + * \return An array of keystates, indexed by the SDLK_* syms.
   1.129 + *
   1.130 + * Example:
   1.131   * 	Uint8 *keystate = SDL_GetKeyState(NULL);
   1.132   *	if ( keystate[SDLK_RETURN] ) ... <RETURN> is pressed.
   1.133   */
   1.134  extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyState(int *numkeys);
   1.135  
   1.136 -/*
   1.137 - * Get the current key modifier state
   1.138 +/**
   1.139 + * \fn SDLMod SDL_GetModState(void)
   1.140 + *
   1.141 + * \brief Get the current key modifier state for the selected keyboard.
   1.142   */
   1.143  extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void);
   1.144  
   1.145 -/*
   1.146 - * Set the current key modifier state
   1.147 - * This does not change the keyboard state, only the key modifier flags.
   1.148 +/**
   1.149 + * \fn void SDL_SetModState(SDLMod modstate)
   1.150 + *
   1.151 + * \brief Set the current key modifier state for the selected keyboard.
   1.152 + *
   1.153 + * \note This does not change the keyboard state, only the key modifier flags.
   1.154   */
   1.155  extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);
   1.156  
   1.157 -/*
   1.158 - * Get the name of an SDL virtual keysym
   1.159 +/**
   1.160 + * \fn const char *SDL_GetKeyName(SDLKey key)
   1.161 + * 
   1.162 + * \brief Get the name of an SDL virtual keysym
   1.163   */
   1.164 -extern DECLSPEC char *SDLCALL SDL_GetKeyName(SDLKey key);
   1.165 +extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);
   1.166  
   1.167  
   1.168  /* Ends C function definitions when using C++ */
     2.1 --- a/include/SDL_keysym.h	Fri Jun 09 07:06:12 2006 +0000
     2.2 +++ b/include/SDL_keysym.h	Sat Jun 10 09:11:59 2006 +0000
     2.3 @@ -27,12 +27,16 @@
     2.4  #ifndef _SDL_keysym_h
     2.5  #define _SDL_keysym_h
     2.6  
     2.7 -/* What we really want is a mapping of every raw key on the keyboard.
     2.8 -   To support international keyboards, we use the range 0xA1 - 0xFF
     2.9 -   as international virtual keycodes.  We'll follow in the footsteps of X11...
    2.10 -   The names of the keys
    2.11 +/**
    2.12 + * \enum SDLKey
    2.13 + *
    2.14 + * \brief The SDL virtual key representation
    2.15 + *
    2.16 + * The SDLKey represents the unmodified character printed on the key
    2.17 + * for the current keyboard layout.  The first 255 characters are used
    2.18 + * unchanged from Latin-1, e.g. a key with 'a' on it will have the value "a".
    2.19 + * The rest of the keys are named below, and fall into the range above 255.
    2.20   */
    2.21 -
    2.22  typedef enum
    2.23  {
    2.24      /* The keyboard syms have been cleverly chosen to map to ASCII */
    2.25 @@ -114,104 +118,6 @@
    2.26      SDLK_DELETE = 127,
    2.27      /* End of ASCII mapped keysyms */
    2.28  
    2.29 -    /* International keyboard syms */
    2.30 -    SDLK_WORLD_0 = 160,         /* 0xA0 */
    2.31 -    SDLK_WORLD_1 = 161,
    2.32 -    SDLK_WORLD_2 = 162,
    2.33 -    SDLK_WORLD_3 = 163,
    2.34 -    SDLK_WORLD_4 = 164,
    2.35 -    SDLK_WORLD_5 = 165,
    2.36 -    SDLK_WORLD_6 = 166,
    2.37 -    SDLK_WORLD_7 = 167,
    2.38 -    SDLK_WORLD_8 = 168,
    2.39 -    SDLK_WORLD_9 = 169,
    2.40 -    SDLK_WORLD_10 = 170,
    2.41 -    SDLK_WORLD_11 = 171,
    2.42 -    SDLK_WORLD_12 = 172,
    2.43 -    SDLK_WORLD_13 = 173,
    2.44 -    SDLK_WORLD_14 = 174,
    2.45 -    SDLK_WORLD_15 = 175,
    2.46 -    SDLK_WORLD_16 = 176,
    2.47 -    SDLK_WORLD_17 = 177,
    2.48 -    SDLK_WORLD_18 = 178,
    2.49 -    SDLK_WORLD_19 = 179,
    2.50 -    SDLK_WORLD_20 = 180,
    2.51 -    SDLK_WORLD_21 = 181,
    2.52 -    SDLK_WORLD_22 = 182,
    2.53 -    SDLK_WORLD_23 = 183,
    2.54 -    SDLK_WORLD_24 = 184,
    2.55 -    SDLK_WORLD_25 = 185,
    2.56 -    SDLK_WORLD_26 = 186,
    2.57 -    SDLK_WORLD_27 = 187,
    2.58 -    SDLK_WORLD_28 = 188,
    2.59 -    SDLK_WORLD_29 = 189,
    2.60 -    SDLK_WORLD_30 = 190,
    2.61 -    SDLK_WORLD_31 = 191,
    2.62 -    SDLK_WORLD_32 = 192,
    2.63 -    SDLK_WORLD_33 = 193,
    2.64 -    SDLK_WORLD_34 = 194,
    2.65 -    SDLK_WORLD_35 = 195,
    2.66 -    SDLK_WORLD_36 = 196,
    2.67 -    SDLK_WORLD_37 = 197,
    2.68 -    SDLK_WORLD_38 = 198,
    2.69 -    SDLK_WORLD_39 = 199,
    2.70 -    SDLK_WORLD_40 = 200,
    2.71 -    SDLK_WORLD_41 = 201,
    2.72 -    SDLK_WORLD_42 = 202,
    2.73 -    SDLK_WORLD_43 = 203,
    2.74 -    SDLK_WORLD_44 = 204,
    2.75 -    SDLK_WORLD_45 = 205,
    2.76 -    SDLK_WORLD_46 = 206,
    2.77 -    SDLK_WORLD_47 = 207,
    2.78 -    SDLK_WORLD_48 = 208,
    2.79 -    SDLK_WORLD_49 = 209,
    2.80 -    SDLK_WORLD_50 = 210,
    2.81 -    SDLK_WORLD_51 = 211,
    2.82 -    SDLK_WORLD_52 = 212,
    2.83 -    SDLK_WORLD_53 = 213,
    2.84 -    SDLK_WORLD_54 = 214,
    2.85 -    SDLK_WORLD_55 = 215,
    2.86 -    SDLK_WORLD_56 = 216,
    2.87 -    SDLK_WORLD_57 = 217,
    2.88 -    SDLK_WORLD_58 = 218,
    2.89 -    SDLK_WORLD_59 = 219,
    2.90 -    SDLK_WORLD_60 = 220,
    2.91 -    SDLK_WORLD_61 = 221,
    2.92 -    SDLK_WORLD_62 = 222,
    2.93 -    SDLK_WORLD_63 = 223,
    2.94 -    SDLK_WORLD_64 = 224,
    2.95 -    SDLK_WORLD_65 = 225,
    2.96 -    SDLK_WORLD_66 = 226,
    2.97 -    SDLK_WORLD_67 = 227,
    2.98 -    SDLK_WORLD_68 = 228,
    2.99 -    SDLK_WORLD_69 = 229,
   2.100 -    SDLK_WORLD_70 = 230,
   2.101 -    SDLK_WORLD_71 = 231,
   2.102 -    SDLK_WORLD_72 = 232,
   2.103 -    SDLK_WORLD_73 = 233,
   2.104 -    SDLK_WORLD_74 = 234,
   2.105 -    SDLK_WORLD_75 = 235,
   2.106 -    SDLK_WORLD_76 = 236,
   2.107 -    SDLK_WORLD_77 = 237,
   2.108 -    SDLK_WORLD_78 = 238,
   2.109 -    SDLK_WORLD_79 = 239,
   2.110 -    SDLK_WORLD_80 = 240,
   2.111 -    SDLK_WORLD_81 = 241,
   2.112 -    SDLK_WORLD_82 = 242,
   2.113 -    SDLK_WORLD_83 = 243,
   2.114 -    SDLK_WORLD_84 = 244,
   2.115 -    SDLK_WORLD_85 = 245,
   2.116 -    SDLK_WORLD_86 = 246,
   2.117 -    SDLK_WORLD_87 = 247,
   2.118 -    SDLK_WORLD_88 = 248,
   2.119 -    SDLK_WORLD_89 = 249,
   2.120 -    SDLK_WORLD_90 = 250,
   2.121 -    SDLK_WORLD_91 = 251,
   2.122 -    SDLK_WORLD_92 = 252,
   2.123 -    SDLK_WORLD_93 = 253,
   2.124 -    SDLK_WORLD_94 = 254,
   2.125 -    SDLK_WORLD_95 = 255,        /* 0xFF */
   2.126 -
   2.127      /* Numeric keypad */
   2.128      SDLK_KP0 = 256,
   2.129      SDLK_KP1 = 257,
   2.130 @@ -271,10 +177,10 @@
   2.131      SDLK_LALT = 308,
   2.132      SDLK_RMETA = 309,
   2.133      SDLK_LMETA = 310,
   2.134 -    SDLK_LSUPER = 311,          /* Left "Windows" key */
   2.135 -    SDLK_RSUPER = 312,          /* Right "Windows" key */
   2.136 -    SDLK_MODE = 313,            /* "Alt Gr" key */
   2.137 -    SDLK_COMPOSE = 314,         /* Multi-key compose key */
   2.138 +    SDLK_LSUPER = 311,          /**< Left "Windows" key */
   2.139 +    SDLK_RSUPER = 312,          /**< Right "Windows" key */
   2.140 +    SDLK_MODE = 313,            /**< "Alt Gr" key */
   2.141 +    SDLK_COMPOSE = 314,         /**< Multi-key compose key */
   2.142  
   2.143      /* Miscellaneous function keys */
   2.144      SDLK_HELP = 315,
   2.145 @@ -282,16 +188,20 @@
   2.146      SDLK_SYSREQ = 317,
   2.147      SDLK_BREAK = 318,
   2.148      SDLK_MENU = 319,
   2.149 -    SDLK_POWER = 320,           /* Power Macintosh power key */
   2.150 -    SDLK_EURO = 321,            /* Some european keyboards */
   2.151 -    SDLK_UNDO = 322,            /* Atari keyboard has Undo */
   2.152 +    SDLK_POWER = 320,           /**< Power Macintosh power key */
   2.153 +    SDLK_EURO = 321,            /**< Some european keyboards */
   2.154 +    SDLK_UNDO = 322,            /**< Atari keyboard has Undo */
   2.155  
   2.156      /* Add any other keys here */
   2.157  
   2.158      SDLK_LAST
   2.159  } SDLKey;
   2.160  
   2.161 -/* Enumeration of valid key mods (possibly OR'd together) */
   2.162 +/**
   2.163 + * \enum SDLMod
   2.164 + *
   2.165 + * \brief Enumeration of valid key mods (possibly OR'd together)
   2.166 + */
   2.167  typedef enum
   2.168  {
   2.169      KMOD_NONE = 0x0000,
     3.1 --- a/include/SDL_mouse.h	Fri Jun 09 07:06:12 2006 +0000
     3.2 +++ b/include/SDL_mouse.h	Sat Jun 10 09:11:59 2006 +0000
     3.3 @@ -45,7 +45,8 @@
     3.4  
     3.5  /* Function prototypes */
     3.6  
     3.7 -/* \fn int SDL_GetNumMice(void)
     3.8 +/**
     3.9 + * \fn int SDL_GetNumMice(void)
    3.10   *
    3.11   * \brief Get the number of mouse input devices available.
    3.12   *
    3.13 @@ -53,7 +54,8 @@
    3.14   */
    3.15  extern DECLSPEC int SDLCALL SDL_GetNumMice(void);
    3.16  
    3.17 -/* \fn int SDL_SelectMouse(int index)
    3.18 +/**
    3.19 + * \fn int SDL_SelectMouse(int index)
    3.20   *
    3.21   * \brief Set the index of the currently selected mouse.
    3.22   *
    3.23 @@ -65,13 +67,14 @@
    3.24   */
    3.25  extern DECLSPEC int SDLCALL SDL_SelectMouse(int index);
    3.26  
    3.27 -/* \fn SDL_WindowID SDL_GetMouseFocusWindow(void)
    3.28 +/**
    3.29 + * \fn SDL_WindowID SDL_GetMouseFocusWindow(void)
    3.30   *
    3.31   * \brief Get the window which currently has focus for the currently selected mouse.
    3.32   */
    3.33  extern DECLSPEC SDL_WindowID SDLCALL SDL_GetMouseFocusWindow(void);
    3.34  
    3.35 -/*
    3.36 +/**
    3.37   * \fn Uint8 SDL_GetMouseState(int *x, int *y)
    3.38   *
    3.39   * \brief Retrieve the current state of the mouse.
    3.40 @@ -83,7 +86,7 @@
    3.41   */
    3.42  extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
    3.43  
    3.44 -/*
    3.45 +/**
    3.46   * \fn Uint8 SDL_GetRelativeMouseState(int *x, int *y)
    3.47   *
    3.48   * \brief Retrieve the current state of the mouse.
    3.49 @@ -94,7 +97,7 @@
    3.50   */
    3.51  extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
    3.52  
    3.53 -/*
    3.54 +/**
    3.55   * \fn void SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
    3.56   *
    3.57   * \brief Moves the currently selected mouse to the given position within the window.
    3.58 @@ -108,7 +111,7 @@
    3.59  extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_WindowID windowID,
    3.60                                                     int x, int y);
    3.61  
    3.62 -/*
    3.63 +/**
    3.64   * \fn SDL_Cursor *SDL_CreateCursor (const Uint8 * data, const Uint8 * mask, int w, int h, int hot_x, int hot_y)
    3.65   *
    3.66   * \brief Create a cursor for the currently selected mouse, using the
    3.67 @@ -130,7 +133,7 @@
    3.68                                                       int w, int h, int hot_x,
    3.69                                                       int hot_y);
    3.70  
    3.71 -/*
    3.72 +/**
    3.73   * \fn void SDL_SetCursor(SDL_Cursor * cursor)
    3.74   *
    3.75   * \brief Set the active cursor for the currently selected mouse.
    3.76 @@ -139,14 +142,14 @@
    3.77   */
    3.78  extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
    3.79  
    3.80 -/*
    3.81 +/**
    3.82   * \fn SDL_Cursor *SDL_GetCursor(void)
    3.83   *
    3.84   * \brief Return the active cursor for the currently selected mouse.
    3.85   */
    3.86  extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
    3.87  
    3.88 -/*
    3.89 +/**
    3.90   * \fn void SDL_FreeCursor(SDL_Cursor * cursor)
    3.91   *
    3.92   * \brief Frees a cursor created with SDL_CreateCursor().
    3.93 @@ -155,7 +158,7 @@
    3.94   */
    3.95  extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
    3.96  
    3.97 -/*
    3.98 +/**
    3.99   * \fn int SDL_ShowCursor(int toggle)
   3.100   *
   3.101   * \brief Toggle whether or not the cursor is shown for the currently selected mouse.
     4.1 --- a/src/events/SDL_keyboard.c	Fri Jun 09 07:06:12 2006 +0000
     4.2 +++ b/src/events/SDL_keyboard.c	Sat Jun 10 09:11:59 2006 +0000
     4.3 @@ -29,307 +29,370 @@
     4.4  #include "SDL_sysevents.h"
     4.5  
     4.6  
     4.7 -/* Global keystate information */
     4.8 -static Uint8 SDL_KeyState[SDLK_LAST];
     4.9 -static SDLMod SDL_ModState;
    4.10 +/* Global keyboard information */
    4.11 +static int SDL_num_keyboards;
    4.12 +static int SDL_current_keyboard;
    4.13 +static SDL_Keyboard **SDL_keyboards;
    4.14  int SDL_TranslateUNICODE = 0;
    4.15  
    4.16 -static const char *keynames[SDLK_LAST]; /* Array of keycode names */
    4.17 -
    4.18 -/*
    4.19 - * jk 991215 - added
    4.20 - */
    4.21 -struct
    4.22 -{
    4.23 -    int firsttime;              /* if we check against the delay or repeat value */
    4.24 -    int delay;                  /* the delay before we start repeating */
    4.25 -    int interval;               /* the delay between key repeat events */
    4.26 -    Uint32 timestamp;           /* the time the first keydown event occurred */
    4.27 -
    4.28 -    SDL_Event evt;              /* the event we are supposed to repeat */
    4.29 -} SDL_KeyRepeat;
    4.30 +static const char *SDL_keynames[SDLK_LAST];     /* Array of keycode names */
    4.31  
    4.32  /* Public functions */
    4.33  int
    4.34  SDL_KeyboardInit(void)
    4.35  {
    4.36 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    4.37 +    int i;
    4.38  
    4.39      /* Set default mode of UNICODE translation */
    4.40      SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
    4.41  
    4.42 -    /* Initialize the tables */
    4.43 -    SDL_ModState = KMOD_NONE;
    4.44 -    SDL_memset((void *) keynames, 0, sizeof(keynames));
    4.45 -    SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
    4.46 -    _this->InitOSKeymap(_this);
    4.47 -
    4.48 +    /* Set default keyboard repeat setting */
    4.49      SDL_EnableKeyRepeat(0, 0);
    4.50  
    4.51 -    /* Fill in the blanks in keynames */
    4.52 -    keynames[SDLK_BACKSPACE] = "backspace";
    4.53 -    keynames[SDLK_TAB] = "tab";
    4.54 -    keynames[SDLK_CLEAR] = "clear";
    4.55 -    keynames[SDLK_RETURN] = "return";
    4.56 -    keynames[SDLK_PAUSE] = "pause";
    4.57 -    keynames[SDLK_ESCAPE] = "escape";
    4.58 -    keynames[SDLK_SPACE] = "space";
    4.59 -    keynames[SDLK_EXCLAIM] = "!";
    4.60 -    keynames[SDLK_QUOTEDBL] = "\"";
    4.61 -    keynames[SDLK_HASH] = "#";
    4.62 -    keynames[SDLK_DOLLAR] = "$";
    4.63 -    keynames[SDLK_AMPERSAND] = "&";
    4.64 -    keynames[SDLK_QUOTE] = "'";
    4.65 -    keynames[SDLK_LEFTPAREN] = "(";
    4.66 -    keynames[SDLK_RIGHTPAREN] = ")";
    4.67 -    keynames[SDLK_ASTERISK] = "*";
    4.68 -    keynames[SDLK_PLUS] = "+";
    4.69 -    keynames[SDLK_COMMA] = ",";
    4.70 -    keynames[SDLK_MINUS] = "-";
    4.71 -    keynames[SDLK_PERIOD] = ".";
    4.72 -    keynames[SDLK_SLASH] = "/";
    4.73 -    keynames[SDLK_0] = "0";
    4.74 -    keynames[SDLK_1] = "1";
    4.75 -    keynames[SDLK_2] = "2";
    4.76 -    keynames[SDLK_3] = "3";
    4.77 -    keynames[SDLK_4] = "4";
    4.78 -    keynames[SDLK_5] = "5";
    4.79 -    keynames[SDLK_6] = "6";
    4.80 -    keynames[SDLK_7] = "7";
    4.81 -    keynames[SDLK_8] = "8";
    4.82 -    keynames[SDLK_9] = "9";
    4.83 -    keynames[SDLK_COLON] = ":";
    4.84 -    keynames[SDLK_SEMICOLON] = ";";
    4.85 -    keynames[SDLK_LESS] = "<";
    4.86 -    keynames[SDLK_EQUALS] = "=";
    4.87 -    keynames[SDLK_GREATER] = ">";
    4.88 -    keynames[SDLK_QUESTION] = "?";
    4.89 -    keynames[SDLK_AT] = "@";
    4.90 -    keynames[SDLK_LEFTBRACKET] = "[";
    4.91 -    keynames[SDLK_BACKSLASH] = "\\";
    4.92 -    keynames[SDLK_RIGHTBRACKET] = "]";
    4.93 -    keynames[SDLK_CARET] = "^";
    4.94 -    keynames[SDLK_UNDERSCORE] = "_";
    4.95 -    keynames[SDLK_BACKQUOTE] = "`";
    4.96 -    keynames[SDLK_a] = "a";
    4.97 -    keynames[SDLK_b] = "b";
    4.98 -    keynames[SDLK_c] = "c";
    4.99 -    keynames[SDLK_d] = "d";
   4.100 -    keynames[SDLK_e] = "e";
   4.101 -    keynames[SDLK_f] = "f";
   4.102 -    keynames[SDLK_g] = "g";
   4.103 -    keynames[SDLK_h] = "h";
   4.104 -    keynames[SDLK_i] = "i";
   4.105 -    keynames[SDLK_j] = "j";
   4.106 -    keynames[SDLK_k] = "k";
   4.107 -    keynames[SDLK_l] = "l";
   4.108 -    keynames[SDLK_m] = "m";
   4.109 -    keynames[SDLK_n] = "n";
   4.110 -    keynames[SDLK_o] = "o";
   4.111 -    keynames[SDLK_p] = "p";
   4.112 -    keynames[SDLK_q] = "q";
   4.113 -    keynames[SDLK_r] = "r";
   4.114 -    keynames[SDLK_s] = "s";
   4.115 -    keynames[SDLK_t] = "t";
   4.116 -    keynames[SDLK_u] = "u";
   4.117 -    keynames[SDLK_v] = "v";
   4.118 -    keynames[SDLK_w] = "w";
   4.119 -    keynames[SDLK_x] = "x";
   4.120 -    keynames[SDLK_y] = "y";
   4.121 -    keynames[SDLK_z] = "z";
   4.122 -    keynames[SDLK_DELETE] = "delete";
   4.123 +    /* Initialize the tables */
   4.124 +    for (i = 0; i < SDL_arraysize(SDL_keynames); ++i) {
   4.125 +        switch (i) {
   4.126 +        case SDLK_BACKSPACE:
   4.127 +            SDL_keynames[i] = "backspace";
   4.128 +            break;
   4.129 +        case SDLK_TAB:
   4.130 +            SDL_keynames[i] = "tab";
   4.131 +            break;
   4.132 +        case SDLK_CLEAR:
   4.133 +            SDL_keynames[i] = "clear";
   4.134 +            break;
   4.135 +        case SDLK_RETURN:
   4.136 +            SDL_keynames[i] = "return";
   4.137 +            break;
   4.138 +        case SDLK_PAUSE:
   4.139 +            SDL_keynames[i] = "pause";
   4.140 +            break;
   4.141 +        case SDLK_ESCAPE:
   4.142 +            SDL_keynames[i] = "escape";
   4.143 +            break;
   4.144 +        case SDLK_SPACE:
   4.145 +            SDL_keynames[i] = "space";
   4.146 +            break;
   4.147  
   4.148 -    keynames[SDLK_WORLD_0] = "world 0";
   4.149 -    keynames[SDLK_WORLD_1] = "world 1";
   4.150 -    keynames[SDLK_WORLD_2] = "world 2";
   4.151 -    keynames[SDLK_WORLD_3] = "world 3";
   4.152 -    keynames[SDLK_WORLD_4] = "world 4";
   4.153 -    keynames[SDLK_WORLD_5] = "world 5";
   4.154 -    keynames[SDLK_WORLD_6] = "world 6";
   4.155 -    keynames[SDLK_WORLD_7] = "world 7";
   4.156 -    keynames[SDLK_WORLD_8] = "world 8";
   4.157 -    keynames[SDLK_WORLD_9] = "world 9";
   4.158 -    keynames[SDLK_WORLD_10] = "world 10";
   4.159 -    keynames[SDLK_WORLD_11] = "world 11";
   4.160 -    keynames[SDLK_WORLD_12] = "world 12";
   4.161 -    keynames[SDLK_WORLD_13] = "world 13";
   4.162 -    keynames[SDLK_WORLD_14] = "world 14";
   4.163 -    keynames[SDLK_WORLD_15] = "world 15";
   4.164 -    keynames[SDLK_WORLD_16] = "world 16";
   4.165 -    keynames[SDLK_WORLD_17] = "world 17";
   4.166 -    keynames[SDLK_WORLD_18] = "world 18";
   4.167 -    keynames[SDLK_WORLD_19] = "world 19";
   4.168 -    keynames[SDLK_WORLD_20] = "world 20";
   4.169 -    keynames[SDLK_WORLD_21] = "world 21";
   4.170 -    keynames[SDLK_WORLD_22] = "world 22";
   4.171 -    keynames[SDLK_WORLD_23] = "world 23";
   4.172 -    keynames[SDLK_WORLD_24] = "world 24";
   4.173 -    keynames[SDLK_WORLD_25] = "world 25";
   4.174 -    keynames[SDLK_WORLD_26] = "world 26";
   4.175 -    keynames[SDLK_WORLD_27] = "world 27";
   4.176 -    keynames[SDLK_WORLD_28] = "world 28";
   4.177 -    keynames[SDLK_WORLD_29] = "world 29";
   4.178 -    keynames[SDLK_WORLD_30] = "world 30";
   4.179 -    keynames[SDLK_WORLD_31] = "world 31";
   4.180 -    keynames[SDLK_WORLD_32] = "world 32";
   4.181 -    keynames[SDLK_WORLD_33] = "world 33";
   4.182 -    keynames[SDLK_WORLD_34] = "world 34";
   4.183 -    keynames[SDLK_WORLD_35] = "world 35";
   4.184 -    keynames[SDLK_WORLD_36] = "world 36";
   4.185 -    keynames[SDLK_WORLD_37] = "world 37";
   4.186 -    keynames[SDLK_WORLD_38] = "world 38";
   4.187 -    keynames[SDLK_WORLD_39] = "world 39";
   4.188 -    keynames[SDLK_WORLD_40] = "world 40";
   4.189 -    keynames[SDLK_WORLD_41] = "world 41";
   4.190 -    keynames[SDLK_WORLD_42] = "world 42";
   4.191 -    keynames[SDLK_WORLD_43] = "world 43";
   4.192 -    keynames[SDLK_WORLD_44] = "world 44";
   4.193 -    keynames[SDLK_WORLD_45] = "world 45";
   4.194 -    keynames[SDLK_WORLD_46] = "world 46";
   4.195 -    keynames[SDLK_WORLD_47] = "world 47";
   4.196 -    keynames[SDLK_WORLD_48] = "world 48";
   4.197 -    keynames[SDLK_WORLD_49] = "world 49";
   4.198 -    keynames[SDLK_WORLD_50] = "world 50";
   4.199 -    keynames[SDLK_WORLD_51] = "world 51";
   4.200 -    keynames[SDLK_WORLD_52] = "world 52";
   4.201 -    keynames[SDLK_WORLD_53] = "world 53";
   4.202 -    keynames[SDLK_WORLD_54] = "world 54";
   4.203 -    keynames[SDLK_WORLD_55] = "world 55";
   4.204 -    keynames[SDLK_WORLD_56] = "world 56";
   4.205 -    keynames[SDLK_WORLD_57] = "world 57";
   4.206 -    keynames[SDLK_WORLD_58] = "world 58";
   4.207 -    keynames[SDLK_WORLD_59] = "world 59";
   4.208 -    keynames[SDLK_WORLD_60] = "world 60";
   4.209 -    keynames[SDLK_WORLD_61] = "world 61";
   4.210 -    keynames[SDLK_WORLD_62] = "world 62";
   4.211 -    keynames[SDLK_WORLD_63] = "world 63";
   4.212 -    keynames[SDLK_WORLD_64] = "world 64";
   4.213 -    keynames[SDLK_WORLD_65] = "world 65";
   4.214 -    keynames[SDLK_WORLD_66] = "world 66";
   4.215 -    keynames[SDLK_WORLD_67] = "world 67";
   4.216 -    keynames[SDLK_WORLD_68] = "world 68";
   4.217 -    keynames[SDLK_WORLD_69] = "world 69";
   4.218 -    keynames[SDLK_WORLD_70] = "world 70";
   4.219 -    keynames[SDLK_WORLD_71] = "world 71";
   4.220 -    keynames[SDLK_WORLD_72] = "world 72";
   4.221 -    keynames[SDLK_WORLD_73] = "world 73";
   4.222 -    keynames[SDLK_WORLD_74] = "world 74";
   4.223 -    keynames[SDLK_WORLD_75] = "world 75";
   4.224 -    keynames[SDLK_WORLD_76] = "world 76";
   4.225 -    keynames[SDLK_WORLD_77] = "world 77";
   4.226 -    keynames[SDLK_WORLD_78] = "world 78";
   4.227 -    keynames[SDLK_WORLD_79] = "world 79";
   4.228 -    keynames[SDLK_WORLD_80] = "world 80";
   4.229 -    keynames[SDLK_WORLD_81] = "world 81";
   4.230 -    keynames[SDLK_WORLD_82] = "world 82";
   4.231 -    keynames[SDLK_WORLD_83] = "world 83";
   4.232 -    keynames[SDLK_WORLD_84] = "world 84";
   4.233 -    keynames[SDLK_WORLD_85] = "world 85";
   4.234 -    keynames[SDLK_WORLD_86] = "world 86";
   4.235 -    keynames[SDLK_WORLD_87] = "world 87";
   4.236 -    keynames[SDLK_WORLD_88] = "world 88";
   4.237 -    keynames[SDLK_WORLD_89] = "world 89";
   4.238 -    keynames[SDLK_WORLD_90] = "world 90";
   4.239 -    keynames[SDLK_WORLD_91] = "world 91";
   4.240 -    keynames[SDLK_WORLD_92] = "world 92";
   4.241 -    keynames[SDLK_WORLD_93] = "world 93";
   4.242 -    keynames[SDLK_WORLD_94] = "world 94";
   4.243 -    keynames[SDLK_WORLD_95] = "world 95";
   4.244 +        case SDLK_KP0:
   4.245 +            SDL_keynames[i] = "[0]";
   4.246 +            break;
   4.247 +        case SDLK_KP1:
   4.248 +            SDL_keynames[i] = "[1]";
   4.249 +            break;
   4.250 +        case SDLK_KP2:
   4.251 +            SDL_keynames[i] = "[2]";
   4.252 +            break;
   4.253 +        case SDLK_KP3:
   4.254 +            SDL_keynames[i] = "[3]";
   4.255 +            break;
   4.256 +        case SDLK_KP4:
   4.257 +            SDL_keynames[i] = "[4]";
   4.258 +            break;
   4.259 +        case SDLK_KP5:
   4.260 +            SDL_keynames[i] = "[5]";
   4.261 +            break;
   4.262 +        case SDLK_KP6:
   4.263 +            SDL_keynames[i] = "[6]";
   4.264 +            break;
   4.265 +        case SDLK_KP7:
   4.266 +            SDL_keynames[i] = "[7]";
   4.267 +            break;
   4.268 +        case SDLK_KP8:
   4.269 +            SDL_keynames[i] = "[8]";
   4.270 +            break;
   4.271 +        case SDLK_KP9:
   4.272 +            SDL_keynames[i] = "[9]";
   4.273 +            break;
   4.274 +        case SDLK_KP_PERIOD:
   4.275 +            SDL_keynames[i] = "[.]";
   4.276 +            break;
   4.277 +        case SDLK_KP_DIVIDE:
   4.278 +            SDL_keynames[i] = "[/]";
   4.279 +            break;
   4.280 +        case SDLK_KP_MULTIPLY:
   4.281 +            SDL_keynames[i] = "[*]";
   4.282 +            break;
   4.283 +        case SDLK_KP_MINUS:
   4.284 +            SDL_keynames[i] = "[-]";
   4.285 +            break;
   4.286 +        case SDLK_KP_PLUS:
   4.287 +            SDL_keynames[i] = "[+]";
   4.288 +            break;
   4.289 +        case SDLK_KP_ENTER:
   4.290 +            SDL_keynames[i] = "enter";
   4.291 +            break;
   4.292 +        case SDLK_KP_EQUALS:
   4.293 +            SDL_keynames[i] = "equals";
   4.294 +            break;
   4.295  
   4.296 -    keynames[SDLK_KP0] = "[0]";
   4.297 -    keynames[SDLK_KP1] = "[1]";
   4.298 -    keynames[SDLK_KP2] = "[2]";
   4.299 -    keynames[SDLK_KP3] = "[3]";
   4.300 -    keynames[SDLK_KP4] = "[4]";
   4.301 -    keynames[SDLK_KP5] = "[5]";
   4.302 -    keynames[SDLK_KP6] = "[6]";
   4.303 -    keynames[SDLK_KP7] = "[7]";
   4.304 -    keynames[SDLK_KP8] = "[8]";
   4.305 -    keynames[SDLK_KP9] = "[9]";
   4.306 -    keynames[SDLK_KP_PERIOD] = "[.]";
   4.307 -    keynames[SDLK_KP_DIVIDE] = "[/]";
   4.308 -    keynames[SDLK_KP_MULTIPLY] = "[*]";
   4.309 -    keynames[SDLK_KP_MINUS] = "[-]";
   4.310 -    keynames[SDLK_KP_PLUS] = "[+]";
   4.311 -    keynames[SDLK_KP_ENTER] = "enter";
   4.312 -    keynames[SDLK_KP_EQUALS] = "equals";
   4.313 +        case SDLK_UP:
   4.314 +            SDL_keynames[i] = "up";
   4.315 +            break;
   4.316 +        case SDLK_DOWN:
   4.317 +            SDL_keynames[i] = "down";
   4.318 +            break;
   4.319 +        case SDLK_RIGHT:
   4.320 +            SDL_keynames[i] = "right";
   4.321 +            break;
   4.322 +        case SDLK_LEFT:
   4.323 +            SDL_keynames[i] = "left";
   4.324 +            break;
   4.325 +        case SDLK_DOWN:
   4.326 +            SDL_keynames[i] = "down";
   4.327 +            break;
   4.328 +        case SDLK_INSERT:
   4.329 +            SDL_keynames[i] = "insert";
   4.330 +            break;
   4.331 +        case SDLK_HOME:
   4.332 +            SDL_keynames[i] = "home";
   4.333 +            break;
   4.334 +        case SDLK_END:
   4.335 +            SDL_keynames[i] = "end";
   4.336 +            break;
   4.337 +        case SDLK_PAGEUP:
   4.338 +            SDL_keynames[i] = "page up";
   4.339 +            break;
   4.340 +        case SDLK_PAGEDOWN:
   4.341 +            SDL_keynames[i] = "page down";
   4.342 +            break;
   4.343  
   4.344 -    keynames[SDLK_UP] = "up";
   4.345 -    keynames[SDLK_DOWN] = "down";
   4.346 -    keynames[SDLK_RIGHT] = "right";
   4.347 -    keynames[SDLK_LEFT] = "left";
   4.348 -    keynames[SDLK_DOWN] = "down";
   4.349 -    keynames[SDLK_INSERT] = "insert";
   4.350 -    keynames[SDLK_HOME] = "home";
   4.351 -    keynames[SDLK_END] = "end";
   4.352 -    keynames[SDLK_PAGEUP] = "page up";
   4.353 -    keynames[SDLK_PAGEDOWN] = "page down";
   4.354 +        case SDLK_F1:
   4.355 +            SDL_keynames[i] = "f1";
   4.356 +            break;
   4.357 +        case SDLK_F2:
   4.358 +            SDL_keynames[i] = "f2";
   4.359 +            break;
   4.360 +        case SDLK_F3:
   4.361 +            SDL_keynames[i] = "f3";
   4.362 +            break;
   4.363 +        case SDLK_F4:
   4.364 +            SDL_keynames[i] = "f4";
   4.365 +            break;
   4.366 +        case SDLK_F5:
   4.367 +            SDL_keynames[i] = "f5";
   4.368 +            break;
   4.369 +        case SDLK_F6:
   4.370 +            SDL_keynames[i] = "f6";
   4.371 +            break;
   4.372 +        case SDLK_F7:
   4.373 +            SDL_keynames[i] = "f7";
   4.374 +            break;
   4.375 +        case SDLK_F8:
   4.376 +            SDL_keynames[i] = "f8";
   4.377 +            break;
   4.378 +        case SDLK_F9:
   4.379 +            SDL_keynames[i] = "f9";
   4.380 +            break;
   4.381 +        case SDLK_F10:
   4.382 +            SDL_keynames[i] = "f10";
   4.383 +            break;
   4.384 +        case SDLK_F11:
   4.385 +            SDL_keynames[i] = "f11";
   4.386 +            break;
   4.387 +        case SDLK_F12:
   4.388 +            SDL_keynames[i] = "f12";
   4.389 +            break;
   4.390 +        case SDLK_F13:
   4.391 +            SDL_keynames[i] = "f13";
   4.392 +            break;
   4.393 +        case SDLK_F14:
   4.394 +            SDL_keynames[i] = "f14";
   4.395 +            break;
   4.396 +        case SDLK_F15:
   4.397 +            SDL_keynames[i] = "f15";
   4.398 +            break;
   4.399  
   4.400 -    keynames[SDLK_F1] = "f1";
   4.401 -    keynames[SDLK_F2] = "f2";
   4.402 -    keynames[SDLK_F3] = "f3";
   4.403 -    keynames[SDLK_F4] = "f4";
   4.404 -    keynames[SDLK_F5] = "f5";
   4.405 -    keynames[SDLK_F6] = "f6";
   4.406 -    keynames[SDLK_F7] = "f7";
   4.407 -    keynames[SDLK_F8] = "f8";
   4.408 -    keynames[SDLK_F9] = "f9";
   4.409 -    keynames[SDLK_F10] = "f10";
   4.410 -    keynames[SDLK_F11] = "f11";
   4.411 -    keynames[SDLK_F12] = "f12";
   4.412 -    keynames[SDLK_F13] = "f13";
   4.413 -    keynames[SDLK_F14] = "f14";
   4.414 -    keynames[SDLK_F15] = "f15";
   4.415 +        case SDLK_NUMLOCK:
   4.416 +            SDL_keynames[i] = "numlock";
   4.417 +            break;
   4.418 +        case SDLK_CAPSLOCK:
   4.419 +            SDL_keynames[i] = "caps lock";
   4.420 +            break;
   4.421 +        case SDLK_SCROLLOCK:
   4.422 +            SDL_keynames[i] = "scroll lock";
   4.423 +            break;
   4.424 +        case SDLK_RSHIFT:
   4.425 +            SDL_keynames[i] = "right shift";
   4.426 +            break;
   4.427 +        case SDLK_LSHIFT:
   4.428 +            SDL_keynames[i] = "left shift";
   4.429 +            break;
   4.430 +        case SDLK_RCTRL:
   4.431 +            SDL_keynames[i] = "right ctrl";
   4.432 +            break;
   4.433 +        case SDLK_LCTRL:
   4.434 +            SDL_keynames[i] = "left ctrl";
   4.435 +            break;
   4.436 +        case SDLK_RALT:
   4.437 +            SDL_keynames[i] = "right alt";
   4.438 +            break;
   4.439 +        case SDLK_LALT:
   4.440 +            SDL_keynames[i] = "left alt";
   4.441 +            break;
   4.442 +        case SDLK_RMETA:
   4.443 +            SDL_keynames[i] = "right meta";
   4.444 +            break;
   4.445 +        case SDLK_LMETA:
   4.446 +            SDL_keynames[i] = "left meta";
   4.447 +            break;
   4.448 +        case SDLK_LSUPER:
   4.449 +            SDL_keynames[i] = "left super";     /* "Windows" keys */
   4.450 +            break;
   4.451 +        case SDLK_RSUPER:
   4.452 +            SDL_keynames[i] = "right super";
   4.453 +            break;
   4.454 +        case SDLK_MODE:
   4.455 +            SDL_keynames[i] = "alt gr";
   4.456 +            break;
   4.457 +        case SDLK_COMPOSE:
   4.458 +            SDL_keynames[i] = "compose";
   4.459 +            break;
   4.460  
   4.461 -    keynames[SDLK_NUMLOCK] = "numlock";
   4.462 -    keynames[SDLK_CAPSLOCK] = "caps lock";
   4.463 -    keynames[SDLK_SCROLLOCK] = "scroll lock";
   4.464 -    keynames[SDLK_RSHIFT] = "right shift";
   4.465 -    keynames[SDLK_LSHIFT] = "left shift";
   4.466 -    keynames[SDLK_RCTRL] = "right ctrl";
   4.467 -    keynames[SDLK_LCTRL] = "left ctrl";
   4.468 -    keynames[SDLK_RALT] = "right alt";
   4.469 -    keynames[SDLK_LALT] = "left alt";
   4.470 -    keynames[SDLK_RMETA] = "right meta";
   4.471 -    keynames[SDLK_LMETA] = "left meta";
   4.472 -    keynames[SDLK_LSUPER] = "left super";       /* "Windows" keys */
   4.473 -    keynames[SDLK_RSUPER] = "right super";
   4.474 -    keynames[SDLK_MODE] = "alt gr";
   4.475 -    keynames[SDLK_COMPOSE] = "compose";
   4.476 +        case SDLK_HELP:
   4.477 +            SDL_keynames[i] = "help";
   4.478 +            break;
   4.479 +        case SDLK_PRINT:
   4.480 +            SDL_keynames[i] = "print screen";
   4.481 +            break;
   4.482 +        case SDLK_SYSREQ:
   4.483 +            SDL_keynames[i] = "sys req";
   4.484 +            break;
   4.485 +        case SDLK_BREAK:
   4.486 +            SDL_keynames[i] = "break";
   4.487 +            break;
   4.488 +        case SDLK_MENU:
   4.489 +            SDL_keynames[i] = "menu";
   4.490 +            break;
   4.491 +        case SDLK_POWER:
   4.492 +            SDL_keynames[i] = "power";
   4.493 +            break;
   4.494 +        case SDLK_EURO:
   4.495 +            SDL_keynames[i] = "euro";
   4.496 +            break;
   4.497 +        case SDLK_UNDO:
   4.498 +            SDL_keynames[i] = "undo";
   4.499 +            break;
   4.500  
   4.501 -    keynames[SDLK_HELP] = "help";
   4.502 -    keynames[SDLK_PRINT] = "print screen";
   4.503 -    keynames[SDLK_SYSREQ] = "sys req";
   4.504 -    keynames[SDLK_BREAK] = "break";
   4.505 -    keynames[SDLK_MENU] = "menu";
   4.506 -    keynames[SDLK_POWER] = "power";
   4.507 -    keynames[SDLK_EURO] = "euro";
   4.508 -    keynames[SDLK_UNDO] = "undo";
   4.509 +        default:
   4.510 +            SDL_keynames[i] = NULL;
   4.511 +            break;
   4.512 +        }
   4.513 +    }
   4.514  
   4.515      /* Done.  Whew. */
   4.516      return (0);
   4.517  }
   4.518  
   4.519 +SDL_Keyboard *
   4.520 +SDL_GetKeyboard(int index)
   4.521 +{
   4.522 +    if (index < 0 || index >= SDL_num_keyboards) {
   4.523 +        return NULL;
   4.524 +    }
   4.525 +    return SDL_keyboards[index];
   4.526 +}
   4.527 +
   4.528 +int
   4.529 +SDL_AddKeyboard(const SDL_Keyboard * keyboard, int index)
   4.530 +{
   4.531 +    SDL_Keyboard **keyboards;
   4.532 +    SDL_Cursor *cursor;
   4.533 +    int selected_keyboard;
   4.534 +
   4.535 +    /* Add the keyboard to the list of keyboards */
   4.536 +    if (index < 0 || index >= SDL_num_keyboards || SDL_keyboards[index]) {
   4.537 +        keyboards =
   4.538 +            (SDL_Keyboard **) SDL_realloc(SDL_keyboards,
   4.539 +                                          (SDL_num_keyboards +
   4.540 +                                           1) * sizeof(*keyboards));
   4.541 +        if (!keyboards) {
   4.542 +            SDL_OutOfMemory();
   4.543 +            return -1;
   4.544 +        }
   4.545 +
   4.546 +        SDL_keyboards = keyboards;
   4.547 +        index = SDL_num_keyboards++;
   4.548 +    }
   4.549 +    SDL_keyboards[index] =
   4.550 +        (SDL_Keyboard *) SDL_malloc(sizeof(*SDL_keyboards[index]));
   4.551 +    if (!SDL_keyboards[index]) {
   4.552 +        SDL_OutOfMemory();
   4.553 +        return -1;
   4.554 +    }
   4.555 +    *SDL_keyboards[index] = *keyboard;
   4.556 +
   4.557 +    return index;
   4.558 +}
   4.559 +
   4.560 +void
   4.561 +SDL_DelKeyboard(int index)
   4.562 +{
   4.563 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   4.564 +
   4.565 +    if (!keyboard) {
   4.566 +        return;
   4.567 +    }
   4.568 +
   4.569 +    if (keyboard->FreeKeyboard) {
   4.570 +        keyboard->FreeKeyboard(keyboard);
   4.571 +    }
   4.572 +    SDL_free(keyboard);
   4.573 +
   4.574 +    SDL_keyboards[index] = NULL;
   4.575 +}
   4.576 +
   4.577 +void
   4.578 +SDL_ResetKeyboard(int index)
   4.579 +{
   4.580 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   4.581 +    SDL_keysym keysym;
   4.582 +    SDLKey key;
   4.583 +
   4.584 +    if (!keyboard) {
   4.585 +        return;
   4.586 +    }
   4.587 +
   4.588 +    SDL_memset(&keysym, 0, (sizeof keysym));
   4.589 +    for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   4.590 +        if (keyboard->keystate[key] == SDL_PRESSED) {
   4.591 +            keysym.sym = key;
   4.592 +            SDL_SendKeyboardKey(index, SDL_RELEASED, &keysym);
   4.593 +        }
   4.594 +    }
   4.595 +    keyboard->keyrepeat.timestamp = 0;
   4.596 +}
   4.597 +
   4.598  void
   4.599  SDL_KeyboardQuit(void)
   4.600  {
   4.601 +    int i;
   4.602 +
   4.603 +    for (i = 0; i < SDL_num_keyboards; ++i) {
   4.604 +        SDL_DelKeyboard(i);
   4.605 +    }
   4.606 +    SDL_num_keyboards = 0;
   4.607 +    SDL_current_keyboard = 0;
   4.608 +
   4.609 +    if (SDL_keyboards) {
   4.610 +        SDL_free(SDL_keyboards);
   4.611 +        SDL_keyboards = NULL;
   4.612 +    }
   4.613  }
   4.614  
   4.615 -/* We lost the keyboard, so post key up messages for all pressed keys */
   4.616 -void
   4.617 -SDL_ResetKeyboard(void)
   4.618 +int
   4.619 +SDL_GetNumKeyboards(void)
   4.620  {
   4.621 -    SDL_keysym keysym;
   4.622 -    SDLKey key;
   4.623 +    return SDL_num_keyboards;
   4.624 +}
   4.625  
   4.626 -    SDL_memset(&keysym, 0, (sizeof keysym));
   4.627 -    for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   4.628 -        if (SDL_KeyState[key] == SDL_PRESSED) {
   4.629 -            keysym.sym = key;
   4.630 -            SDL_SendKeyboard(SDL_RELEASED, &keysym);
   4.631 -        }
   4.632 +int
   4.633 +SDL_SelectKeyboard(int index)
   4.634 +{
   4.635 +    if (index >= 0 && index < SDL_num_keyboards) {
   4.636 +        SDL_current_keyboard = index;
   4.637      }
   4.638 -    SDL_KeyRepeat.timestamp = 0;
   4.639 +    return SDL_current_keyboard;
   4.640  }
   4.641  
   4.642  int
   4.643 @@ -355,34 +418,45 @@
   4.644  SDLMod
   4.645  SDL_GetModState(void)
   4.646  {
   4.647 -    return (SDL_ModState);
   4.648 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   4.649 +
   4.650 +    if (!keyboard) {
   4.651 +        return KMOD_NONE;
   4.652 +    }
   4.653 +    return keyboard->modstate;
   4.654  }
   4.655  
   4.656  void
   4.657  SDL_SetModState(SDLMod modstate)
   4.658  {
   4.659 -    SDL_ModState = modstate;
   4.660 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   4.661 +
   4.662 +    if (!keyboard) {
   4.663 +        return;
   4.664 +    }
   4.665 +    keyboard->modstate = modstate;
   4.666  }
   4.667  
   4.668 -char *
   4.669 +const char *
   4.670  SDL_GetKeyName(SDLKey key)
   4.671  {
   4.672      const char *keyname;
   4.673  
   4.674 -    keyname = NULL;
   4.675 -    if (key < SDLK_LAST) {
   4.676 -        keyname = keynames[key];
   4.677 +    keyname = keynames[key];
   4.678 +    if (keyname == NULL) {
   4.679 +        if (key < 256) {
   4.680 +            static char temp[4];
   4.681 +          FIXME:Convert to UTF - 8 keyname = temp;
   4.682 +        } else {
   4.683 +            keyname = "unknown key";
   4.684 +        }
   4.685      }
   4.686 -    if (keyname == NULL) {
   4.687 -        keyname = "unknown key";
   4.688 -    }
   4.689 -    /* FIXME: make this function const in 1.3 */
   4.690 -    return (char *) (keyname);
   4.691 +    return keyname;
   4.692  }
   4.693  
   4.694  /* These are global for SDL_eventloop.c */
   4.695  int
   4.696 -SDL_SendKeyboard(Uint8 state, SDL_keysym * keysym)
   4.697 +SDL_SendKeyboardKey(int index, Uint8 state, const SDL_keysym * keysym)
   4.698  {
   4.699      SDL_Event event;
   4.700      int posted, repeatable;
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/events/SDL_keyboard_c.h	Sat Jun 10 09:11:59 2006 +0000
     5.3 @@ -0,0 +1,77 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2006 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +#include "SDL_config.h"
    5.26 +
    5.27 +#ifndef _SDL_keyboard_c_h
    5.28 +#define _SDL_keyboard_c_h
    5.29 +
    5.30 +typedef struct SDL_Keyboard SDL_Keyboard;
    5.31 +
    5.32 +struct SDL_Keyboard
    5.33 +{
    5.34 +    /* Free the keyboard when it's time */
    5.35 +    void (*FreeKeyboard) (SDL_Keyboard * keyboard);
    5.36 +
    5.37 +    SDLMod modstate;
    5.38 +    Uint8 keystate[SDLK_LAST];
    5.39 +
    5.40 +    struct
    5.41 +    {
    5.42 +        int firsttime;          /* if we check against the delay or repeat value */
    5.43 +        int delay;              /* the delay before we start repeating */
    5.44 +        int interval;           /* the delay between key repeat events */
    5.45 +        Uint32 timestamp;       /* the time the first keydown event occurred */
    5.46 +
    5.47 +        SDL_Event evt;          /* the event we are supposed to repeat */
    5.48 +    } keyrepeat;
    5.49 +
    5.50 +    void *driverdata;
    5.51 +};
    5.52 +
    5.53 +
    5.54 +/* Initialize the keyboard subsystem */
    5.55 +extern int SDL_KeyboardInit(void);
    5.56 +
    5.57 +/* Get the keyboard at an index */
    5.58 +extern SDL_Keyboard *SDL_GetKeyboard(int index);
    5.59 +
    5.60 +/* Add a keyboard, possibly reattaching at a particular index (or -1),
    5.61 +   returning the index of the keyboard, or -1 if there was an error.
    5.62 + */
    5.63 +extern int SDL_AddKeyboard(const SDL_Keyboard * keyboard, int index);
    5.64 +
    5.65 +/* Remove a keyboard at an index, clearing the slot for later */
    5.66 +extern void SDL_DelKeyboard(int index);
    5.67 +
    5.68 +/* Clear the state of a keyboard at an index */
    5.69 +extern void SDL_ResetKeyboard(int index);
    5.70 +
    5.71 +/* Send a keyboard event for a keyboard at an index */
    5.72 +extern int SDL_SendKeyboardKey(int index, Uint8 state,
    5.73 +                               const SDL_keysym * keysym);
    5.74 +
    5.75 +/* Shutdown the keyboard subsystem */
    5.76 +extern void SDL_KeyboardQuit(void);
    5.77 +
    5.78 +#endif /* _SDL_keyboard_c_h */
    5.79 +
    5.80 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/video/SDL_sysvideo.h	Fri Jun 09 07:06:12 2006 +0000
     6.2 +++ b/src/video/SDL_sysvideo.h	Sat Jun 10 09:11:59 2006 +0000
     6.3 @@ -213,37 +213,6 @@
     6.4      void (*VideoQuit) (_THIS);
     6.5  
     6.6      /* * * */
     6.7 -    /* Hardware acceleration functions */
     6.8 -
     6.9 -    /* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */
    6.10 -    SDL_PixelFormat *displayformatalphapixel;
    6.11 -
    6.12 -    /* Allocates a surface in video memory */
    6.13 -    int (*AllocHWSurface) (_THIS, SDL_Surface * surface);
    6.14 -
    6.15 -    /* Sets the hardware accelerated blit function, if any, based
    6.16 -       on the current flags of the surface (colorkey, alpha, etc.)
    6.17 -     */
    6.18 -    int (*CheckHWBlit) (_THIS, SDL_Surface * src, SDL_Surface * dst);
    6.19 -
    6.20 -    /* Fills a surface rectangle with the given color */
    6.21 -    int (*FillHWRect) (_THIS, SDL_Surface * dst, SDL_Rect * rect,
    6.22 -                       Uint32 color);
    6.23 -
    6.24 -    /* Sets video mem colorkey and accelerated blit function */
    6.25 -    int (*SetHWColorKey) (_THIS, SDL_Surface * surface, Uint32 key);
    6.26 -
    6.27 -    /* Sets per surface hardware alpha value */
    6.28 -    int (*SetHWAlpha) (_THIS, SDL_Surface * surface, Uint8 value);
    6.29 -
    6.30 -    /* Returns a readable/writable surface */
    6.31 -    int (*LockHWSurface) (_THIS, SDL_Surface * surface);
    6.32 -    void (*UnlockHWSurface) (_THIS, SDL_Surface * surface);
    6.33 -
    6.34 -    /* Frees a previously allocated video surface */
    6.35 -    void (*FreeHWSurface) (_THIS, SDL_Surface * surface);
    6.36 -
    6.37 -    /* * * */
    6.38      /* Gamma support */
    6.39  
    6.40      /* Set the gamma correction directly (emulated with gamma ramps) */
    6.41 @@ -303,9 +272,6 @@
    6.42      /* * * */
    6.43      /* Event manager functions */
    6.44  
    6.45 -    /* Initialize keyboard mapping for this driver */
    6.46 -    void (*InitOSKeymap) (_THIS);
    6.47 -
    6.48      /* Handle any queued OS events */
    6.49      void (*PumpEvents) (_THIS);
    6.50