Mercurial > sdl-ios-xcode
comparison include/SDL_keyboard.h @ 2268:4baee598306d
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
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 19 Aug 2007 14:52:52 +0000 |
parents | 047245361002 |
children | d87417504c75 |
comparison
equal
deleted
inserted
replaced
2267:c785543d1843 | 2268:4baee598306d |
---|---|
48 */ | 48 */ |
49 typedef struct SDL_keysym | 49 typedef struct SDL_keysym |
50 { | 50 { |
51 Uint8 scancode; /**< keyboard specific scancode */ | 51 Uint8 scancode; /**< keyboard specific scancode */ |
52 Uint8 padding[3]; /**< alignment padding */ | 52 Uint8 padding[3]; /**< alignment padding */ |
53 Uint16 sym; /**< SDL virtual keysym */ | 53 SDLKey sym; /**< SDL virtual key code - see ::SDLKey for details */ |
54 Uint16 mod; /**< current key modifiers */ | 54 Uint16 mod; /**< current key modifiers */ |
55 Uint32 unicode; /**< OBSOLETE, use SDL_TextInputEvent instead */ | 55 Uint32 unicode; /**< OBSOLETE, use SDL_TextInputEvent instead */ |
56 } SDL_keysym; | 56 } SDL_keysym; |
57 | 57 |
58 /* Function prototypes */ | 58 /* Function prototypes */ |
95 /** | 95 /** |
96 * \fn Uint8 *SDL_GetKeyState(int *numkeys) | 96 * \fn Uint8 *SDL_GetKeyState(int *numkeys) |
97 * | 97 * |
98 * \brief Get a snapshot of the current state of the selected keyboard. | 98 * \brief Get a snapshot of the current state of the selected keyboard. |
99 * | 99 * |
100 * \return An array of keystates, indexed by the SDLK_* syms. | 100 * \param numkeys if non-NULL, receives the length of the returned array. |
101 * | |
102 * \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. | |
101 * | 103 * |
102 * Example: | 104 * Example: |
103 * Uint8 *keystate = SDL_GetKeyState(NULL); | 105 * Uint8 *keystate = SDL_GetKeyState(NULL); |
104 * if ( keystate[SDLK_RETURN] ) ... <RETURN> is pressed. | 106 * if ( keystate[SDLK_INDEX(SDLK_RETURN)] ) ... <RETURN> is pressed. |
105 */ | 107 */ |
106 extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyState(int *numkeys); | 108 extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyState(int *numkeys); |
107 | 109 |
108 /** | 110 /** |
109 * \fn SDLMod SDL_GetModState(void) | 111 * \fn SDLMod SDL_GetModState(void) |
120 * \note This does not change the keyboard state, only the key modifier flags. | 122 * \note This does not change the keyboard state, only the key modifier flags. |
121 */ | 123 */ |
122 extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate); | 124 extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate); |
123 | 125 |
124 /** | 126 /** |
125 * \fn const char *SDL_GetKeyName(SDLKey key) | 127 * \fn SDLKey SDL_GetLayoutKey(SDLKey physicalKey) |
126 * | 128 * |
127 * \brief Get the name of an SDL virtual keysym | 129 * \brief Get the layout key code corresponding to the given physical key code according to the current keyboard layout. |
130 * | |
131 * See ::SDLKey for details. | |
132 * | |
133 * If \a physicalKey is not a physical key code, it is returned unchanged. | |
134 * | |
135 * \sa SDL_GetKeyName() | |
128 */ | 136 */ |
129 extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key); | 137 extern DECLSPEC SDLKey SDLCALL SDL_GetLayoutKey(SDLKey physicalKey); |
138 | |
139 /** | |
140 * \fn const char *SDL_GetKeyName(SDLKey layoutKey) | |
141 * | |
142 * \brief Get a human-readable name for a key. | |
143 * | |
144 * \param layoutKey An SDL layout key code. | |
145 * | |
146 * 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. | |
147 * | |
148 * \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. | |
149 * | |
150 * \sa SDLKey | |
151 */ | |
152 extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey layoutKey); | |
130 | 153 |
131 | 154 |
132 /* Ends C function definitions when using C++ */ | 155 /* Ends C function definitions when using C++ */ |
133 #ifdef __cplusplus | 156 #ifdef __cplusplus |
134 /* *INDENT-OFF* */ | 157 /* *INDENT-OFF* */ |