19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** @file SDL_keyboard.h 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Include file for SDL keyboard event handling 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef _SDL_keyboard_h 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define _SDL_keyboard_h 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_stdinc.h" 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_error.h" 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_keysym.h" 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "begin_code.h" 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Set up for C function definitions, even when using C++ */ 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __cplusplus 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern "C" { 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** Keysym structure 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * - The scancode is hardware dependent, and should not be used by general 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * applications. If no hardware scancode is available, it will be 0. 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * - The 'unicode' translated character is only available when character 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * translation is enabled by the SDL_EnableUNICODE() API. If non-zero, 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * this is a UNICODE character corresponding to the keypress. If the 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * high 9 bits of the character are 0, then this maps to the equivalent 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * ASCII character: 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @code 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * char ch; 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * if ( (keysym.unicode & 0xFF80) == 0 ) { 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * ch = keysym.unicode & 0x7F; 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * } else { 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * An international character.. 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * } 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @endcode 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltypedef struct SDL_keysym { 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 scancode; /**< hardware specific scancode */ 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDLKey sym; /**< SDL virtual keysym */ 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDLMod mod; /**< current key modifiers */ 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint16 unicode; /**< translated character */ 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} SDL_keysym; 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** This is the mask which refers to all hotkey bindings */ 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_ALL_HOTKEYS 0xFFFFFFFF 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Function prototypes */ 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Enable/Disable UNICODE translation of keyboard input. 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This translation has some overhead, so translation defaults off. 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @param[in] enable 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * If 'enable' is 1, translation is enabled. 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * If 'enable' is 0, translation is disabled. 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * If 'enable' is -1, the translation state is not changed. 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @return It returns the previous state of keyboard translation. 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_DEFAULT_REPEAT_DELAY 500 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define SDL_DEFAULT_REPEAT_INTERVAL 30 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Enable/Disable keyboard repeat. Keyboard repeat defaults to off. 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @param[in] delay 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 'delay' is the initial delay in ms between the time when a key is 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * pressed, and keyboard repeat begins. 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @param[in] interval 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 'interval' is the time in ms between keyboard repeat events. 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * If 'delay' is set to 0, keyboard repeat is disabled. 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Get a snapshot of the current state of the keyboard. 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Returns an array of keystates, indexed by the SDLK_* syms. 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Usage: 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @code 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Uint8 *keystate = SDL_GetKeyState(NULL); 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * if ( keystate[SDLK_RETURN] ) //... \<RETURN> is pressed. 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * @endcode 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern DECLSPEC Uint8 * SDLCALL SDL_GetKeyState(int *numkeys); 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Get the current key modifier state 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern DECLSPEC SDLMod SDLCALL SDL_GetModState(void); 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Set the current key modifier state. 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * This does not change the keyboard state, only the key modifier flags. 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate); 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/** 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * Get the name of an SDL virtual keysym 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern DECLSPEC char * SDLCALL SDL_GetKeyName(SDLKey key); 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Ends C function definitions when using C++ */ 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef __cplusplus 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "close_code.h" 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* _SDL_keyboard_h */ 136