Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
First pass implementation of new SDL scancode concept, as discussed with
Browse files Browse the repository at this point in the history
Christian Walther.  Currently only implemented on Mac OS X for sanity
checking purposes.
  • Loading branch information
slouken committed Feb 5, 2008
1 parent 4c3a92f commit 525f176
Show file tree
Hide file tree
Showing 16 changed files with 1,587 additions and 1,347 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -42,7 +42,7 @@ SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@

DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS docs docs.html include INSTALL Makefile.dc Makefile.minimal Makefile.in README* sdl-config.in sdl.m4 sdl.pc.in SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualC.html VisualC VisualCE Watcom-OS2.zip Watcom-Win32.zip WhatsNew Xcode

HDRS = SDL.h SDL_audio.h SDL_cdrom.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_pixels.h SDL_platform.h SDL_quit.h SDL_rect.h SDL_rwops.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h
HDRS = SDL.h SDL_audio.h SDL_cdrom.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_pixels.h SDL_platform.h SDL_quit.h SDL_rect.h SDL_rwops.h SDL_scancode.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h

LT_AGE = @LT_AGE@
LT_CURRENT = @LT_CURRENT@
Expand Down
116 changes: 54 additions & 62 deletions include/SDL_compat.h
Expand Up @@ -130,47 +130,54 @@ typedef enum

struct SDL_SysWMinfo;

/* Key codes
Note that the correspondences defined here are approximate at best because
the meaning of the event structure field that carries these values has
changed: in SDL 1.2, it referred to the key's label in the current keyboard
layout, whereas now it refers to a specific physical key on the keyboard,
regardless of the keyboard layout setting.
To get comparable behavior to SDL 1.2, code that uses any of the codes below
in ways like "if (somekey == SDLK_EXCLAIM)" should be changed to the
equivalent of "if (SDL_GetLayoutKey(somekey) == '!')".
*/

/* These key constants were renamed for clarity or consistence. */
#define SDLK_QUOTE SDLK_APOSTROPHE
#define SDLK_MINUS SDLK_HYPHENMINUS
#define SDLK_BACKQUOTE SDLK_GRAVE
#define SDLK_a SDLK_A
#define SDLK_b SDLK_B
#define SDLK_c SDLK_C
#define SDLK_d SDLK_D
#define SDLK_e SDLK_E
#define SDLK_f SDLK_F
#define SDLK_g SDLK_G
#define SDLK_h SDLK_H
#define SDLK_i SDLK_I
#define SDLK_j SDLK_J
#define SDLK_k SDLK_K
#define SDLK_l SDLK_L
#define SDLK_m SDLK_M
#define SDLK_n SDLK_N
#define SDLK_o SDLK_O
#define SDLK_p SDLK_P
#define SDLK_q SDLK_Q
#define SDLK_r SDLK_R
#define SDLK_s SDLK_S
#define SDLK_t SDLK_T
#define SDLK_u SDLK_U
#define SDLK_v SDLK_V
#define SDLK_w SDLK_W
#define SDLK_x SDLK_X
#define SDLK_y SDLK_Y
#define SDLK_z SDLK_Z
/* Obsolete or renamed key codes */

/* These key constants were renamed for clarity or consistency. */
#define SDLK_a 'a'
#define SDLK_b 'b'
#define SDLK_c 'c'
#define SDLK_d 'd'
#define SDLK_e 'e'
#define SDLK_f 'f'
#define SDLK_g 'g'
#define SDLK_h 'h'
#define SDLK_i 'i'
#define SDLK_j 'j'
#define SDLK_k 'k'
#define SDLK_l 'l'
#define SDLK_m 'm'
#define SDLK_n 'n'
#define SDLK_o 'o'
#define SDLK_p 'p'
#define SDLK_q 'q'
#define SDLK_r 'r'
#define SDLK_s 's'
#define SDLK_t 't'
#define SDLK_u 'u'
#define SDLK_v 'v'
#define SDLK_w 'w'
#define SDLK_x 'x'
#define SDLK_y 'y'
#define SDLK_z 'z'
#define SDLK_QUOTE '\''
#define SDLK_MINUS '-'
#define SDLK_BACKQUOTE '`'
#define SDLK_EXCLAIM '!'
#define SDLK_QUOTEDBL '"'
#define SDLK_HASH '#'
#define SDLK_DOLLAR '$'
#define SDLK_AMPERSAND '&'
#define SDLK_LEFTPAREN '('
#define SDLK_RIGHTPAREN ')'
#define SDLK_ASTERISK '*'
#define SDLK_PLUS '+'
#define SDLK_COLON ':'
#define SDLK_LESS '<'
#define SDLK_GREATER '>'
#define SDLK_QUESTION '?'
#define SDLK_AT '@'
#define SDLK_CARET '^'
#define SDLK_UNDERSCORE '_'
#define SDLK_KP0 SDLK_KP_0
#define SDLK_KP1 SDLK_KP_1
#define SDLK_KP2 SDLK_KP_2
Expand All @@ -181,30 +188,14 @@ struct SDL_SysWMinfo;
#define SDLK_KP7 SDLK_KP_7
#define SDLK_KP8 SDLK_KP_8
#define SDLK_KP9 SDLK_KP_9
#define SDLK_NUMLOCK SDLK_KP_NUMLOCKCLEAR
#define SDLK_NUMLOCK SDLK_NUMLOCKCLEAR
#define SDLK_SCROLLOCK SDLK_SCROLLLOCK
#define SDLK_PRINT SDLK_PRINTSCREEN

/* These key constants are obsoleted by the new keyboard handling,
their definitions here correspond to how they appear on a US
keyboard. */

#define SDLK_EXCLAIM SDLK_1
#define SDLK_QUOTEDBL SDLK_APOSTROPHE
#define SDLK_HASH SDLK_3
#define SDLK_DOLLAR SDLK_4
#define SDLK_AMPERSAND SDLK_7
#define SDLK_LEFTPAREN SDLK_9
#define SDLK_RIGHTPAREN SDLK_0
#define SDLK_ASTERISK SDLK_8
#define SDLK_PLUS SDLK_EQUALS
#define SDLK_COLON SDLK_SEMICOLON
#define SDLK_LESS SDLK_COMMA
#define SDLK_GREATER SDLK_PERIOD
#define SDLK_QUESTION SDLK_SLASH
#define SDLK_AT SDLK_2
#define SDLK_CARET SDLK_6
#define SDLK_UNDERSCORE SDLK_HYPHENMINUS
/* The META modifier is equivalent to the GUI modifier from the USB standard */
#define KMOD_LMETA KMOD_LGUI
#define KMOD_RMETA KMOD_RGUI
#define KMOD_META KMOD_GUI

/* These keys don't appear in the USB specification (or at least not under those names). I'm unsure if the following assignments make sense or if these codes should be defined as actual additional SDLK_ constants. */
#define SDLK_LSUPER SDLK_LMETA
Expand Down Expand Up @@ -268,6 +259,7 @@ extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay);
extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
65 changes: 34 additions & 31 deletions include/SDL_keyboard.h
Expand Up @@ -48,8 +48,7 @@ extern "C" {
*/
typedef struct SDL_keysym
{
Uint8 scancode; /**< keyboard specific scancode */
Uint8 padding[3]; /**< alignment padding */
SDL_scancode scancode; /**< SDL physical key code - see ::SDL_scancode for details */
SDLKey sym; /**< SDL virtual key code - see ::SDLKey for details */
Uint16 mod; /**< current key modifiers */
Uint32 unicode; /**< OBSOLETE, use SDL_TextInputEvent instead */
Expand Down Expand Up @@ -80,32 +79,19 @@ extern DECLSPEC int SDLCALL SDL_GetNumKeyboards(void);
extern DECLSPEC int SDLCALL SDL_SelectKeyboard(int index);

/**
* \fn int SDL_EnableUNICODE(int enable)
*
* \brief Enable/Disable UNICODE translation of keyboard input.
*
* \param enable 1 to enable translation, 0 to disable translation, -1 to query translation
*
* \return The previous state of keyboard translation
*
* \note This translation has some overhead, so translation defaults off.
*/
extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);

/**
* \fn Uint8 *SDL_GetKeyState(int *numkeys)
* \fn Uint8 *SDL_GetKeyboardState(int *numkeys)
*
* \brief Get a snapshot of the current state of the selected keyboard.
*
* \param numkeys if non-NULL, receives the length of the returned array.
*
* \return An array of key states. Indexes into this array are obtained by using the SDLK_INDEX() macro on the \link ::SDLPhysicalKey SDLK_* \endlink syms.
* \return An array of key states. Indexes into this array are obtained by using ::SDL_scancode values.
*
* Example:
* Uint8 *keystate = SDL_GetKeyState(NULL);
* if ( keystate[SDLK_INDEX(SDLK_RETURN)] ) ... <RETURN> is pressed.
* Uint8 *state = SDL_GetKeyboardState(NULL);
* if ( state[SDL_SCANCODE_RETURN)] ) ... <RETURN> is pressed.
*/
extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyState(int *numkeys);
extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);

/**
* \fn SDLMod SDL_GetModState(void)
Expand All @@ -124,32 +110,49 @@ extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void);
extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);

/**
* \fn SDLKey SDL_GetLayoutKey(SDLKey physicalKey)
* \fn SDLKey SDL_GetKeyFromScancode(SDL_scancode scancode)
*
* \brief Get the layout key code corresponding to the given physical key code according to the current keyboard layout.
* \brief Get the key code corresponding to the given scancode according to the current keyboard layout.
*
* See ::SDLKey for details.
*
* If \a physicalKey is not a physical key code, it is returned unchanged.
*
* \sa SDL_GetKeyName()
*/
extern DECLSPEC SDLKey SDLCALL SDL_GetLayoutKey(SDLKey physicalKey);
extern DECLSPEC SDLKey SDLCALL SDL_GetKeyFromScancode(SDL_scancode scancode);

/**
* \fn const char *SDL_GetKeyName(SDLKey layoutKey)
* \fn SDL_scancode SDL_GetScancodeFromKey(SDLKey key)
*
* \brief Get a human-readable name for a key.
* \brief Get the scancode corresponding to the given key code according to the current keyboard layout.
*
* See ::SDL_scancode for details.
*
* \param layoutKey An SDL layout key code.
* \sa SDL_GetScancodeName()
*/
extern DECLSPEC SDL_scancode SDLCALL SDL_GetScancodeFromKey(SDLKey key);

/**
* \fn const char *SDL_GetScancodeName(SDL_scancode scancode)
*
* \brief Get a human-readable name for a scancode.
*
* \return A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it. If the scancode doesn't have a name, this function returns "".
*
* 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.
* \sa SDL_scancode
*/
extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_scancode
scancode);

/**
* \fn const char *SDL_GetKeyName(SDLKey key)
*
* \brief Get a human-readable name for a key.
*
* \return A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it. Always non-NULL.
* \return A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it. If the key doesn't have a name, this function returns "".
*
* \sa SDLKey
*/
extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey layoutKey);
extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);


/* Ends C function definitions when using C++ */
Expand Down

0 comments on commit 525f176

Please sign in to comment.