include/SDL_keyboard.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 18 May 2013 14:17:52 -0700
changeset 7191 75360622e65f
parent 6885 700f1b25f77f
child 7258 89d47188c9a4
permissions -rw-r--r--
File style cleanup for the SDL 2.0 release
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /**
    23  *  \file SDL_keyboard.h
    24  *
    25  *  Include file for SDL keyboard event handling
    26  */
    27 
    28 #ifndef _SDL_keyboard_h
    29 #define _SDL_keyboard_h
    30 
    31 #include "SDL_stdinc.h"
    32 #include "SDL_error.h"
    33 #include "SDL_keycode.h"
    34 #include "SDL_video.h"
    35 
    36 #include "begin_code.h"
    37 /* Set up for C function definitions, even when using C++ */
    38 #ifdef __cplusplus
    39 extern "C" {
    40 #endif
    41 
    42 /**
    43  *  \brief The SDL keysym structure, used in key events.
    44  */
    45 typedef struct SDL_Keysym
    46 {
    47     SDL_Scancode scancode;      /**< SDL physical key code - see ::SDL_Scancode for details */
    48     SDL_Keycode sym;            /**< SDL virtual key code - see ::SDL_Keycode for details */
    49     Uint16 mod;                 /**< current key modifiers */
    50     Uint32 unicode;             /**< \deprecated use SDL_TextInputEvent instead */
    51 } SDL_Keysym;
    52 
    53 /* Function prototypes */
    54 
    55 /**
    56  *  \brief Get the window which currently has keyboard focus.
    57  */
    58 extern DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
    59 
    60 /**
    61  *  \brief Get a snapshot of the current state of the keyboard.
    62  *
    63  *  \param numkeys if non-NULL, receives the length of the returned array.
    64  *
    65  *  \return An array of key states. Indexes into this array are obtained by using ::SDL_Scancode values.
    66  *
    67  *  \b Example:
    68  *  \code
    69  *  Uint8 *state = SDL_GetKeyboardState(NULL);
    70  *  if ( state[SDL_SCANCODE_RETURN] )   {
    71  *      printf("<RETURN> is pressed.\n");
    72  *  }
    73  *  \endcode
    74  */
    75 extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
    76 
    77 /**
    78  *  \brief Get the current key modifier state for the keyboard.
    79  */
    80 extern DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void);
    81 
    82 /**
    83  *  \brief Set the current key modifier state for the keyboard.
    84  *
    85  *  \note This does not change the keyboard state, only the key modifier flags.
    86  */
    87 extern DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
    88 
    89 /**
    90  *  \brief Get the key code corresponding to the given scancode according
    91  *         to the current keyboard layout.
    92  *
    93  *  See ::SDL_Keycode for details.
    94  *
    95  *  \sa SDL_GetKeyName()
    96  */
    97 extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode);
    98 
    99 /**
   100  *  \brief Get the scancode corresponding to the given key code according to the
   101  *         current keyboard layout.
   102  *
   103  *  See ::SDL_Scancode for details.
   104  *
   105  *  \sa SDL_GetScancodeName()
   106  */
   107 extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
   108 
   109 /**
   110  *  \brief Get a human-readable name for a scancode.
   111  *
   112  *  \return A pointer to the name for the scancode.
   113  *          If the scancode doesn't have a name, this function returns
   114  *          an empty string ("").
   115  *
   116  *  \sa SDL_Scancode
   117  */
   118 extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
   119 
   120 /**
   121  *  \brief Get a scancode from a human-readable name
   122  *
   123  *  \return scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized
   124  *
   125  *  \sa SDL_Scancode
   126  */
   127 extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name);
   128 
   129 /**
   130  *  \brief Get a human-readable name for a key.
   131  *
   132  *  \return A pointer to a UTF-8 string that stays valid at least until the next
   133  *          call to this function. If you need it around any longer, you must
   134  *          copy it.  If the key doesn't have a name, this function returns an
   135  *          empty string ("").
   136  *
   137  *  \sa SDL_Key
   138  */
   139 extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key);
   140 
   141 /**
   142  *  \brief Get a key code from a human-readable name
   143  *
   144  *  \return key code, or SDLK_UNKNOWN if the name wasn't recognized
   145  *
   146  *  \sa SDL_Keycode
   147  */
   148 extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
   149 
   150 /**
   151  *  \brief Start accepting Unicode text input events.
   152  *         This function will show the on-screen keyboard if supported.
   153  *
   154  *  \sa SDL_StopTextInput()
   155  *  \sa SDL_SetTextInputRect()
   156  *  \sa SDL_HasScreenKeyboardSupport()
   157  */
   158 extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
   159 
   160 /**
   161  *  \brief Return whether or not Unicode text input events are enabled.
   162  *
   163  *  \sa SDL_StartTextInput()
   164  *  \sa SDL_StopTextInput()
   165  */
   166 extern DECLSPEC SDL_bool SDLCALL SDL_IsTextInputActive(void);
   167 
   168 /**
   169  *  \brief Stop receiving any text input events.
   170  *         This function will hide the on-screen keyboard if supported.
   171  *
   172  *  \sa SDL_StartTextInput()
   173  *  \sa SDL_HasScreenKeyboardSupport()
   174  */
   175 extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
   176 
   177 /**
   178  *  \brief Set the rectangle used to type Unicode text inputs.
   179  *         This is used as a hint for IME and on-screen keyboard placement.
   180  *
   181  *  \sa SDL_StartTextInput()
   182  */
   183 extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);
   184 
   185 /**
   186  *  \brief Returns whether the platform has some screen keyboard support.
   187  *
   188  *  \return SDL_TRUE if some keyboard support is available else SDL_FALSE.
   189  *
   190  *  \note Not all screen keyboard functions are supported on all platforms.
   191  *
   192  *  \sa SDL_IsScreenKeyboardShown()
   193  */
   194 extern DECLSPEC SDL_bool SDLCALL SDL_HasScreenKeyboardSupport(void);
   195 
   196 /**
   197  *  \brief Returns whether the screen keyboard is shown for given window.
   198  *
   199  *  \param window The window for which screen keyboard should be queried.
   200  *
   201  *  \return SDL_TRUE if screen keyboard is shown else SDL_FALSE.
   202  *
   203  *  \sa SDL_HasScreenKeyboardSupport()
   204  */
   205 extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenKeyboardShown(SDL_Window *window);
   206 
   207 /* Ends C function definitions when using C++ */
   208 #ifdef __cplusplus
   209 }
   210 #endif
   211 #include "close_code.h"
   212 
   213 #endif /* _SDL_keyboard_h */
   214 
   215 /* vi: set ts=4 sw=4 expandtab: */