1b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/* 2b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet SDL - Simple DirectMedia Layer 34458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall Copyright (C) 1997-2012 Sam Lantinga 4b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 5b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet This library is free software; you can redistribute it and/or 6b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet modify it under the terms of the GNU Lesser General Public 7b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet License as published by the Free Software Foundation; either 8b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet version 2.1 of the License, or (at your option) any later version. 9b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 10b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet This library is distributed in the hope that it will be useful, 11b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet but WITHOUT ANY WARRANTY; without even the implied warranty of 12b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet Lesser General Public License for more details. 14b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 15b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet You should have received a copy of the GNU Lesser General Public 16b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet License along with this library; if not, write to the Free Software 17b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 19b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet Sam Lantinga 20b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet slouken@libsdl.org 21b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet*/ 22b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 234458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** @file SDL_keyboard.h 244458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * Include file for SDL keyboard event handling 254458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall */ 26b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 27b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifndef _SDL_keyboard_h 28b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define _SDL_keyboard_h 29b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 30b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "SDL_stdinc.h" 31b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "SDL_error.h" 32b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "SDL_keysym.h" 33b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 34b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "begin_code.h" 35b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/* Set up for C function definitions, even when using C++ */ 36b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef __cplusplus 37b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern "C" { 38b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif 39b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 404458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** Keysym structure 414458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 424458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * - The scancode is hardware dependent, and should not be used by general 434458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * applications. If no hardware scancode is available, it will be 0. 444458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 454458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * - The 'unicode' translated character is only available when character 464458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * translation is enabled by the SDL_EnableUNICODE() API. If non-zero, 474458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * this is a UNICODE character corresponding to the keypress. If the 484458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * high 9 bits of the character are 0, then this maps to the equivalent 494458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * ASCII character: 504458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @code 514458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * char ch; 524458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * if ( (keysym.unicode & 0xFF80) == 0 ) { 534458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * ch = keysym.unicode & 0x7F; 544458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * } else { 554458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * An international character.. 564458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * } 574458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @endcode 58b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */ 59b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohettypedef struct SDL_keysym { 604458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall Uint8 scancode; /**< hardware specific scancode */ 614458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall SDLKey sym; /**< SDL virtual keysym */ 624458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall SDLMod mod; /**< current key modifiers */ 634458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall Uint16 unicode; /**< translated character */ 64b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet} SDL_keysym; 65b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 664458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** This is the mask which refers to all hotkey bindings */ 67b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_ALL_HOTKEYS 0xFFFFFFFF 68b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 69b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/* Function prototypes */ 704458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** 71b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Enable/Disable UNICODE translation of keyboard input. 724458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 73b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * This translation has some overhead, so translation defaults off. 744458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 754458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @param[in] enable 76b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * If 'enable' is 1, translation is enabled. 77b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * If 'enable' is 0, translation is disabled. 78b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * If 'enable' is -1, the translation state is not changed. 794458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 804458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @return It returns the previous state of keyboard translation. 81b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */ 82b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); 83b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 84b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_DEFAULT_REPEAT_DELAY 500 85b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#define SDL_DEFAULT_REPEAT_INTERVAL 30 864458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** 874458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * Enable/Disable keyboard repeat. Keyboard repeat defaults to off. 884458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 894458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @param[in] delay 904458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 'delay' is the initial delay in ms between the time when a key is 914458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * pressed, and keyboard repeat begins. 924458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 934458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @param[in] interval 944458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 'interval' is the time in ms between keyboard repeat events. 954458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * 964458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * If 'delay' is set to 0, keyboard repeat is disabled. 97b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */ 98b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); 99b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); 100b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 1014458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** 102b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get a snapshot of the current state of the keyboard. 103b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Returns an array of keystates, indexed by the SDLK_* syms. 1044458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * Usage: 1054458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @code 106b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Uint8 *keystate = SDL_GetKeyState(NULL); 1074458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * if ( keystate[SDLK_RETURN] ) //... \<RETURN> is pressed. 1084458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * @endcode 109b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */ 110b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC Uint8 * SDLCALL SDL_GetKeyState(int *numkeys); 111b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 1124458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** 113b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the current key modifier state 114b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */ 115b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC SDLMod SDLCALL SDL_GetModState(void); 116b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 1174458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** 1184458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall * Set the current key modifier state. 119b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * This does not change the keyboard state, only the key modifier flags. 120b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */ 121b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC void SDLCALL SDL_SetModState(SDLMod modstate); 122b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 1234458c4364a99c5d8d124b19eec146b0998c4895aJesse Hall/** 124b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet * Get the name of an SDL virtual keysym 125b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet */ 126b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohetextern DECLSPEC char * SDLCALL SDL_GetKeyName(SDLKey key); 127b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 128b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 129b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet/* Ends C function definitions when using C++ */ 130b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#ifdef __cplusplus 131b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet} 132b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif 133b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#include "close_code.h" 134b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet 135b565d46b836401fa5dac23f9f8f0841c7a41e58eXavier Ducrohet#endif /* _SDL_keyboard_h */ 136