include/SDL_keyboard.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 19 Sep 2009 13:29:40 +0000
changeset 3280 00cace2d9080
parent 2859 99210400e8b9
child 3407 d3baf5ac4e37
permissions -rw-r--r--
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 /**
    24  * \file SDL_keyboard.h
    25  *
    26  * Include file for SDL keyboard event handling
    27  */
    28 
    29 #ifndef _SDL_keyboard_h
    30 #define _SDL_keyboard_h
    31 
    32 #include "SDL_stdinc.h"
    33 #include "SDL_error.h"
    34 #include "SDL_keysym.h"
    35 
    36 #include "begin_code.h"
    37 /* Set up for C function definitions, even when using C++ */
    38 #ifdef __cplusplus
    39 /* *INDENT-OFF* */
    40 extern "C" {
    41 /* *INDENT-ON* */
    42 #endif
    43 
    44 /**
    45  * \struct SDL_keysym
    46  *
    47  * \brief The SDL keysym structure, used in key events.
    48  */
    49 typedef struct SDL_keysym
    50 {
    51     SDL_scancode scancode;      /**< SDL physical key code - see ::SDL_scancode for details */
    52     SDLKey sym;                 /**< SDL virtual key code - see ::SDLKey for details */
    53     Uint16 mod;                 /**< current key modifiers */
    54     Uint32 unicode;             /**< OBSOLETE, use SDL_TextInputEvent instead */
    55 } SDL_keysym;
    56 
    57 /* Function prototypes */
    58 
    59 /**
    60  * \fn int SDL_GetNumKeyboards(void)
    61  *
    62  * \brief Get the number of keyboard input devices available.
    63  *
    64  * \sa SDL_SelectKeyboard()
    65  */
    66 extern DECLSPEC int SDLCALL SDL_GetNumKeyboards(void);
    67 
    68 /**
    69  * \fn int SDL_SelectKeyboard(int index)
    70  *
    71  * \brief Set the index of the currently selected keyboard.
    72  *
    73  * \return The index of the previously selected keyboard.
    74  *
    75  * \note You can query the currently selected keyboard by passing an index of -1.
    76  *
    77  * \sa SDL_GetNumKeyboards()
    78  */
    79 extern DECLSPEC int SDLCALL SDL_SelectKeyboard(int index);
    80 
    81 /**
    82  * \fn Uint8 *SDL_GetKeyboardState(int *numkeys)
    83  *
    84  * \brief Get a snapshot of the current state of the selected keyboard.
    85  *
    86  * \param numkeys if non-NULL, receives the length of the returned array.
    87  *
    88  * \return An array of key states. Indexes into this array are obtained by using ::SDL_scancode values.
    89  *
    90  * Example:
    91  * 	Uint8 *state = SDL_GetKeyboardState(NULL);
    92  *	if ( state[SDL_SCANCODE_RETURN)] ) ... <RETURN> is pressed.
    93  */
    94 extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
    95 
    96 /**
    97  * \fn SDLMod SDL_GetModState(void)
    98  *
    99  * \brief Get the current key modifier state for the selected keyboard.
   100  */
   101 extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void);
   102 
   103 /**
   104  * \fn void SDL_SetModState(SDLMod modstate)
   105  *
   106  * \brief Set the current key modifier state for the selected keyboard.
   107  *
   108  * \note This does not change the keyboard state, only the key modifier flags.
   109  */
   110 extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);
   111 
   112 /**
   113  * \fn SDLKey SDL_GetKeyFromScancode(SDL_scancode scancode)
   114  * 
   115  * \brief Get the key code corresponding to the given scancode according to the current keyboard layout.
   116  *
   117  * See ::SDLKey for details.
   118  *
   119  * \sa SDL_GetKeyName()
   120  */
   121 extern DECLSPEC SDLKey SDLCALL SDL_GetKeyFromScancode(SDL_scancode scancode);
   122 
   123 /**
   124  * \fn SDL_scancode SDL_GetScancodeFromKey(SDLKey key)
   125  * 
   126  * \brief Get the scancode corresponding to the given key code according to the current keyboard layout.
   127  *
   128  * See ::SDL_scancode for details.
   129  *
   130  * \sa SDL_GetScancodeName()
   131  */
   132 extern DECLSPEC SDL_scancode SDLCALL SDL_GetScancodeFromKey(SDLKey key);
   133 
   134 /**
   135  * \fn const char *SDL_GetScancodeName(SDL_scancode scancode)
   136  * 
   137  * \brief Get a human-readable name for a scancode.
   138  *
   139  * \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 "".
   140  *
   141  * \sa SDL_scancode
   142  */
   143 extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_scancode
   144                                                         scancode);
   145 
   146 /**
   147  * \fn const char *SDL_GetKeyName(SDLKey key)
   148  * 
   149  * \brief Get a human-readable name for a key.
   150  *
   151  * \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 "".
   152  *
   153  * \sa SDLKey
   154  */
   155 extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);
   156 
   157 /**
   158  * \fn void SDL_StartTextInput(void)
   159  *
   160  * \brief Start accepting Unicode text input events.
   161  *
   162  * \sa SDL_StopTextInput()
   163  * \sa SDL_SetTextInputRect()
   164  */
   165 extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
   166 
   167 /**
   168  * \fn void SDL_StopTextInput(void)
   169  *
   170  * \brief Stop receiving any text input events.
   171  *
   172  * \sa SDL_StartTextInput()
   173  */
   174 extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
   175 
   176 /**
   177  * \fn void SDL_SetTextInputRect(SDL_Rect *rect)
   178  *
   179  * \brief Set the rectangle used to type Unicode text inputs.
   180  *
   181  * \sa SDL_StartTextInput()
   182  */
   183 extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);
   184 
   185 
   186 /* Ends C function definitions when using C++ */
   187 #ifdef __cplusplus
   188 /* *INDENT-OFF* */
   189 }
   190 /* *INDENT-ON* */
   191 #endif
   192 #include "close_code.h"
   193 
   194 #endif /* _SDL_keyboard_h */
   195 
   196 /* vi: set ts=4 sw=4 expandtab: */