SDL_keyboard.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. SDL - Simple DirectMedia Layer
  3. Copyright (C) 1997-2009 Sam Lantinga
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. Sam Lantinga
  16. slouken@libsdl.org
  17. */
  18. /** @file SDL_keyboard.h
  19. * Include file for SDL keyboard event handling
  20. */
  21. #ifndef _SDL_keyboard_h
  22. #define _SDL_keyboard_h
  23. #include "SDL_stdinc.h"
  24. #include "SDL_error.h"
  25. #include "SDL_keysym.h"
  26. #include "begin_code.h"
  27. /* Set up for C function definitions, even when using C++ */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /** Keysym structure
  32. *
  33. * - The scancode is hardware dependent, and should not be used by general
  34. * applications. If no hardware scancode is available, it will be 0.
  35. *
  36. * - The 'unicode' translated character is only available when character
  37. * translation is enabled by the SDL_EnableUNICODE() API. If non-zero,
  38. * this is a UNICODE character corresponding to the keypress. If the
  39. * high 9 bits of the character are 0, then this maps to the equivalent
  40. * ASCII character:
  41. * @code
  42. * char ch;
  43. * if ( (keysym.unicode & 0xFF80) == 0 ) {
  44. * ch = keysym.unicode & 0x7F;
  45. * } else {
  46. * An international character..
  47. * }
  48. * @endcode
  49. */
  50. typedef struct SDL_keysym {
  51. Uint8 scancode; /**< hardware specific scancode */
  52. SDLKey sym; /**< SDL virtual keysym */
  53. SDLMod mod; /**< current key modifiers */
  54. Uint16 unicode; /**< translated character */
  55. } SDL_keysym;
  56. /** This is the mask which refers to all hotkey bindings */
  57. #define SDL_ALL_HOTKEYS 0xFFFFFFFF
  58. /* Function prototypes */
  59. /**
  60. * Enable/Disable UNICODE translation of keyboard input.
  61. *
  62. * This translation has some overhead, so translation defaults off.
  63. *
  64. * @param[in] enable
  65. * If 'enable' is 1, translation is enabled.
  66. * If 'enable' is 0, translation is disabled.
  67. * If 'enable' is -1, the translation state is not changed.
  68. *
  69. * @return It returns the previous state of keyboard translation.
  70. */
  71. extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
  72. #define SDL_DEFAULT_REPEAT_DELAY 500
  73. #define SDL_DEFAULT_REPEAT_INTERVAL 30
  74. /**
  75. * Enable/Disable keyboard repeat. Keyboard repeat defaults to off.
  76. *
  77. * @param[in] delay
  78. * 'delay' is the initial delay in ms between the time when a key is
  79. * pressed, and keyboard repeat begins.
  80. *
  81. * @param[in] interval
  82. * 'interval' is the time in ms between keyboard repeat events.
  83. *
  84. * If 'delay' is set to 0, keyboard repeat is disabled.
  85. */
  86. extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
  87. extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
  88. /**
  89. * Get a snapshot of the current state of the keyboard.
  90. * Returns an array of keystates, indexed by the SDLK_* syms.
  91. * Usage:
  92. * @code
  93. * Uint8 *keystate = SDL_GetKeyState(NULL);
  94. * if ( keystate[SDLK_RETURN] ) //... \<RETURN> is pressed.
  95. * @endcode
  96. */
  97. extern DECLSPEC Uint8 * SDLCALL SDL_GetKeyState(int *numkeys);
  98. /**
  99. * Get the current key modifier state
  100. */
  101. extern DECLSPEC SDLMod SDLCALL SDL_GetModState(void);
  102. /**
  103. * Set the current key modifier state.
  104. * This does not change the keyboard state, only the key modifier flags.
  105. */
  106. extern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate);
  107. /**
  108. * Get the name of an SDL virtual keysym
  109. */
  110. extern DECLSPEC char * SDLCALL SDL_GetKeyName(SDLKey key);
  111. /* Ends C function definitions when using C++ */
  112. #ifdef __cplusplus
  113. }
  114. #endif
  115. #include "close_code.h"
  116. #endif /* _SDL_keyboard_h */