2011-11-22 21:28:15 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Doom 3 GPL Source Code
2011-12-06 18:20:15 +00:00
Copyright ( C ) 1999 - 2011 id Software LLC , a ZeniMax Media company .
2011-11-22 21:28:15 +00:00
2011-12-06 16:14:59 +00:00
This file is part of the Doom 3 GPL Source Code ( " Doom 3 Source Code " ) .
2011-11-22 21:28:15 +00:00
Doom 3 Source Code is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
Doom 3 Source Code is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code . If not , see < http : //www.gnu.org/licenses/>.
In addition , the Doom 3 Source Code is also subject to certain additional terms . You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code . If not , please request a copy in writing from id Software at the address below .
If you have questions concerning this license or the applicable additional terms , you may contact in writing id Software LLC , c / o ZeniMax Media Inc . , Suite 120 , Rockville , Maryland 20850 USA .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
# ifndef __KEYINPUT_H__
# define __KEYINPUT_H__
2011-12-16 22:28:29 +00:00
# include "idlib/CmdArgs.h"
class idFile ;
2011-11-22 21:28:15 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Key Input
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
// these are the key numbers that are used by the key system
// normal keys should be passed as lowercased ascii
// Some high ascii (> 127) characters that are mapped directly to keys on
// western european keyboards are inserted in this table so that those keys
// are bindable (otherwise they get bound as one of the special keys in this
// table)
typedef enum {
2019-06-17 01:50:07 +00:00
// DG: please don't change any existing constants for keyboard keys below (or recreate the tables in win_input.cpp)!
2011-11-22 21:28:15 +00:00
K_TAB = 9 ,
K_ENTER = 13 ,
K_ESCAPE = 27 ,
K_SPACE = 32 ,
K_BACKSPACE = 127 ,
K_COMMAND = 128 ,
K_CAPSLOCK ,
K_SCROLL ,
K_POWER ,
K_PAUSE ,
K_UPARROW = 133 ,
K_DOWNARROW ,
K_LEFTARROW ,
K_RIGHTARROW ,
// The 3 windows keys
K_LWIN = 137 ,
K_RWIN ,
K_MENU ,
K_ALT = 140 ,
K_CTRL ,
K_SHIFT ,
K_INS ,
K_DEL ,
K_PGDN ,
K_PGUP ,
K_HOME ,
K_END ,
K_F1 = 149 ,
K_F2 ,
K_F3 ,
K_F4 ,
K_F5 ,
K_F6 ,
K_F7 ,
K_F8 ,
K_F9 ,
K_F10 ,
K_F11 ,
K_F12 ,
K_INVERTED_EXCLAMATION = 161 , // upside down !
K_F13 ,
K_F14 ,
K_F15 ,
K_KP_HOME = 165 ,
K_KP_UPARROW ,
K_KP_PGUP ,
K_KP_LEFTARROW ,
K_KP_5 ,
K_KP_RIGHTARROW ,
K_KP_END ,
K_KP_DOWNARROW ,
K_KP_PGDN ,
K_KP_ENTER ,
K_KP_INS ,
K_KP_DEL ,
K_KP_SLASH ,
K_SUPERSCRIPT_TWO = 178 , // superscript 2
K_KP_MINUS ,
K_ACUTE_ACCENT = 180 , // accute accent
K_KP_PLUS ,
K_KP_NUMLOCK ,
K_KP_STAR ,
K_KP_EQUALS ,
2019-06-17 01:50:07 +00:00
// DG: please don't change any existing constants above this one (or recreate the tables in win_input.cpp)!
2011-12-06 18:20:15 +00:00
K_MASCULINE_ORDINATOR = 186 ,
2011-11-22 21:28:15 +00:00
// K_MOUSE enums must be contiguous (no char codes in the middle)
K_MOUSE1 = 187 ,
K_MOUSE2 ,
K_MOUSE3 ,
K_MOUSE4 ,
K_MOUSE5 ,
K_MOUSE6 ,
K_MOUSE7 ,
K_MOUSE8 ,
K_MWHEELDOWN = 195 ,
K_MWHEELUP ,
2024-01-07 00:26:45 +00:00
//------------------------
2024-01-08 04:26:27 +00:00
// K_JOY codes must be contiguous, too, and K_JOY_BTN_* should be kept in sync with J_BTN_* of sys_jEvents
2024-01-07 00:26:45 +00:00
//------------------------
2024-01-08 04:26:27 +00:00
K_FIRST_JOY = 197 ,
K_JOY_BTN_SOUTH = K_FIRST_JOY , // bottom face button, like Xbox A
K_JOY_BTN_EAST , // right face button, like Xbox B
K_JOY_BTN_WEST , // left face button, like Xbox X
K_JOY_BTN_NORTH , // top face button, like Xbox Y
2024-01-16 16:26:45 +00:00
2024-01-08 04:26:27 +00:00
K_JOY_BTN_BACK ,
K_JOY_BTN_GUIDE , // Note: this one should probably not be used?
2024-01-18 05:09:33 +00:00
K_JOY_BTN_START , // hardcoded to generate Esc to open/close menu
2024-01-08 04:26:27 +00:00
K_JOY_BTN_LSTICK , // press left stick
K_JOY_BTN_RSTICK , // press right stick
K_JOY_BTN_LSHOULDER ,
K_JOY_BTN_RSHOULDER ,
2024-01-16 16:26:45 +00:00
K_JOY_DPAD_UP ,
K_JOY_DPAD_DOWN ,
K_JOY_DPAD_LEFT ,
K_JOY_DPAD_RIGHT ,
2024-01-08 04:26:27 +00:00
K_JOY_BTN_MISC1 , // Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button)
K_JOY_BTN_RPADDLE1 , // Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1)
K_JOY_BTN_LPADDLE1 , // Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3)
K_JOY_BTN_RPADDLE2 , // Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2)
K_JOY_BTN_LPADDLE2 , // Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4)
2024-01-07 00:26:45 +00:00
K_JOY_STICK1_UP ,
K_JOY_STICK1_DOWN ,
K_JOY_STICK1_LEFT ,
K_JOY_STICK1_RIGHT ,
K_JOY_STICK2_UP ,
K_JOY_STICK2_DOWN ,
K_JOY_STICK2_LEFT ,
K_JOY_STICK2_RIGHT ,
K_JOY_TRIGGER1 ,
K_JOY_TRIGGER2 ,
2024-01-16 16:26:45 +00:00
K_LAST_JOY = K_JOY_TRIGGER2 ,
2024-01-07 00:26:45 +00:00
K_GRAVE_A = 229 , // lowercase a with grave accent FIXME: used to be 224; this probably isn't used anyway
2011-11-22 21:28:15 +00:00
K_AUX1 = 230 ,
K_CEDILLA_C = 231 , // lowercase c with Cedilla
K_GRAVE_E = 232 , // lowercase e with grave accent
K_AUX2 ,
K_AUX3 ,
K_AUX4 ,
K_GRAVE_I = 236 , // lowercase i with grave accent
K_AUX5 ,
K_AUX6 ,
K_AUX7 ,
K_AUX8 ,
K_TILDE_N = 241 , // lowercase n with tilde
K_GRAVE_O = 242 , // lowercase o with grave accent
K_AUX9 ,
K_AUX10 ,
K_AUX11 ,
K_AUX12 ,
K_AUX13 ,
K_AUX14 ,
K_GRAVE_U = 249 , // lowercase u with grave accent
K_AUX15 ,
K_AUX16 ,
K_PRINT_SCR = 252 , // SysRq / PrintScr
K_RIGHT_ALT = 253 , // used by some languages as "Alt-Gr"
2021-07-03 02:33:27 +00:00
2021-07-03 12:42:14 +00:00
// DG: added the following two
K_RIGHT_CTRL = 254 ,
K_RIGHT_SHIFT = 255 ,
2021-07-03 02:33:27 +00:00
// DG: map all relevant scancodes from SDL to K_SC_* (taken from Yamagi Quake II)
// (relevant are ones that are likely to be keyboardlayout-dependent,
// i.e. printable characters of sorts, *not* Ctrl, Alt, F1, Del, ...)
K_FIRST_SCANCODE = 256 ,
// !!! NOTE: if you add a scancode here, make sure to also add it to !!!
// !!! scancodemappings[] in sys/events.cpp (and preserve order) !!!
K_SC_A = K_FIRST_SCANCODE ,
K_SC_B ,
K_SC_C ,
K_SC_D ,
K_SC_E ,
K_SC_F ,
K_SC_G ,
K_SC_H ,
K_SC_I ,
K_SC_J ,
K_SC_K ,
K_SC_L ,
K_SC_M ,
K_SC_N ,
K_SC_O ,
K_SC_P ,
K_SC_Q ,
K_SC_R ,
K_SC_S ,
K_SC_T ,
K_SC_U ,
K_SC_V ,
K_SC_W ,
K_SC_X ,
K_SC_Y ,
K_SC_Z ,
// leaving out SDL_SCANCODE_1 ... _0, we handle them separately already
// also return, escape, backspace, tab, space, already handled as keycodes
K_SC_MINUS ,
K_SC_EQUALS ,
K_SC_LEFTBRACKET ,
K_SC_RIGHTBRACKET ,
K_SC_BACKSLASH ,
K_SC_NONUSHASH ,
K_SC_SEMICOLON ,
K_SC_APOSTROPHE ,
K_SC_GRAVE ,
K_SC_COMMA ,
K_SC_PERIOD ,
K_SC_SLASH ,
// leaving out lots of keys incl. from keypad, we already handle them as normal keys
K_SC_NONUSBACKSLASH ,
K_SC_INTERNATIONAL1 , /**< used on Asian keyboards, see footnotes in USB doc */
K_SC_INTERNATIONAL2 ,
K_SC_INTERNATIONAL3 , /**< Yen */
K_SC_INTERNATIONAL4 ,
K_SC_INTERNATIONAL5 ,
K_SC_INTERNATIONAL6 ,
K_SC_INTERNATIONAL7 ,
K_SC_INTERNATIONAL8 ,
K_SC_INTERNATIONAL9 ,
K_SC_THOUSANDSSEPARATOR ,
K_SC_DECIMALSEPARATOR ,
K_SC_CURRENCYUNIT ,
K_SC_CURRENCYSUBUNIT ,
K_LAST_SCANCODE = K_SC_CURRENCYSUBUNIT , // TODO: keep up to date!
Improve handling of "console key", add in_ignoreConsoleKey CVar
If in_ignoreConsoleKey is set, the console can only be opened with
Shift+Esc, not `/^/whatever, so you can easily type whatever character
is on your "console key" into the game, or even bind that key.
Otherwise, with SDL2, that key (KEY_SCANCODE_GRAVE) always generates the
newly added K_CONSOLE.
in_kbd has a new (SDL2-only) "auto" mode which tries to detect the
keyboard layout based on SDL_GetKeyFromScancode( SDL_SCANCODE_GRAVE ).
Wherever Sys_GetConsoleKey() is called, I now take the current state of
Shift into account, so we don't discard more chars than necessary, esp.
when they keyboard-layout (in_kbd) is *not* correctly set.
(TBH the only reason besides SDL1.2 to keep in_kbd around is to ignore
the char generated by the "console key" in the console..)
2021-07-12 04:15:22 +00:00
K_CONSOLE , // special keycode used for the "console key" and only to open/close the console (not bindable)
2021-07-03 02:33:27 +00:00
// FIXME: maybe move everything joystick related here
K_LAST_KEY // DG: this said "this better be < 256!"; I hope I fixed all places in code assuming this..
2011-11-22 21:28:15 +00:00
} keyNum_t ;
2021-07-03 02:33:27 +00:00
enum { K_NUM_SCANCODES = K_LAST_SCANCODE - K_FIRST_SCANCODE + 1 } ;
2011-11-22 21:28:15 +00:00
class idKeyInput {
public :
static void Init ( void ) ;
static void Shutdown ( void ) ;
static void ArgCompletion_KeyName ( const idCmdArgs & args , void ( * callback ) ( const char * s ) ) ;
static void PreliminaryKeyEvent ( int keyNum , bool down ) ;
static bool IsDown ( int keyNum ) ;
static int GetUsercmdAction ( int keyNum ) ;
static bool GetOverstrikeMode ( void ) ;
static void SetOverstrikeMode ( bool state ) ;
static void ClearStates ( void ) ;
static int StringToKeyNum ( const char * str ) ;
static const char * KeyNumToString ( int keyNum , bool localized ) ;
static void SetBinding ( int keyNum , const char * binding ) ;
static const char * GetBinding ( int keyNum ) ;
static bool UnbindBinding ( const char * bind ) ;
static int NumBinds ( const char * binding ) ;
static bool ExecKeyBinding ( int keyNum ) ;
static const char * KeysFromBinding ( const char * bind ) ;
static const char * BindingFromKey ( const char * key ) ;
static bool KeyIsBoundTo ( int keyNum , const char * binding ) ;
static void WriteBindings ( idFile * f ) ;
2024-03-25 01:15:20 +00:00
static void KeyReveal ( int keyNum ) ;
2011-11-22 21:28:15 +00:00
} ;
# endif /* !__KEYINPUT_H__ */