UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cl_keys.h File Reference

Header file for keyboard handler. More...

Go to the source code of this file.

Macros

#define MAXKEYLINES   32
 

Enumerations

enum  keyNum_t {
  K_FIRST_KEY, K_BACKSPACE = 8, K_TAB = 9, K_ENTER = 13,
  K_PAUSE = 19, K_ESCAPE = 27, K_SPACE = 32, K_DEL = 127,
  K_MOUSE1 = 200, K_MOUSE2 = 201, K_MOUSE3 = 202, K_MWHEELDOWN = 239,
  K_MWHEELUP = 240, K_MOUSE4 = 241, K_MOUSE5 = 242, K_KP_INS = 256,
  K_KP_END = 257, K_KP_DOWNARROW = 258, K_KP_PGDN = 259, K_KP_LEFTARROW = 260,
  K_KP_5 = 261, K_KP_RIGHTARROW = 262, K_KP_HOME = 263, K_KP_UPARROW = 264,
  K_KP_PGUP = 265, K_KP_DEL = 266, K_KP_SLASH = 267, K_KP_MULTIPLY = 268,
  K_KP_MINUS = 269, K_KP_PLUS = 270, K_KP_ENTER = 271, K_KP_NUMLOCK = 272,
  K_UPARROW = 273, K_DOWNARROW = 274, K_RIGHTARROW = 275, K_LEFTARROW = 276,
  K_HOME = 278, K_END = 279, K_PGUP = 280, K_PGDN = 281,
  K_F1 = 282, K_F2 = 283, K_F3 = 284, K_F4 = 285,
  K_F5 = 286, K_F6 = 287, K_F7 = 288, K_F8 = 289,
  K_F9 = 290, K_F10 = 291, K_F11 = 292, K_F12 = 293,
  K_F13 = 294, K_F14 = 295, K_F15 = 296, K_INS = 277,
  K_SHIFT = 304, K_CTRL = 306, K_ALT = 308, K_JOY1,
  K_JOY2, K_JOY3, K_JOY4, K_JOY5,
  K_JOY6, K_JOY7, K_JOY8, K_JOY9,
  K_JOY10, K_JOY11, K_JOY12, K_JOY13,
  K_JOY14, K_JOY15, K_JOY16, K_JOY17,
  K_JOY18, K_JOY19, K_JOY20, K_JOY21,
  K_JOY22, K_JOY23, K_JOY24, K_JOY25,
  K_JOY26, K_JOY27, K_JOY28, K_JOY29,
  K_JOY30, K_JOY31, K_JOY32, K_AUX1,
  K_AUX2, K_AUX3, K_AUX4, K_AUX5,
  K_AUX6, K_AUX7, K_AUX8, K_AUX9,
  K_AUX10, K_AUX11, K_AUX12, K_AUX13,
  K_AUX14, K_AUX15, K_AUX16, K_NUMLOCK,
  K_SUPER, K_COMPOSE, K_MODE, K_HELP,
  K_PRINT, K_SYSREQ, K_SCROLLOCK, K_BREAK,
  K_MENU, K_EURO, K_UNDO, K_COMMAND,
  K_CAPSLOCK, K_POWER, K_APPS, K_LAST_KEY = 511,
  K_KEY_SIZE = 512
}
 
enum  keyBindSpace_t { KEYSPACE_UI, KEYSPACE_GAME, KEYSPACE_BATTLE, KEYSPACE_MAX }
 
enum  keydest_t { key_game, key_console }
 

Functions

bool Key_IsDown (unsigned int key)
 Checks whether a given key is currently pressed. More...
 
bool Key_IsNumlock (void)
 
void Key_SetDest (keydest_t key_dest)
 Sets the keyDest in cls. More...
 
void Key_Event (unsigned int key, unsigned short unicode, bool down, unsigned time)
 Called by the system between frames for both key up and key down events. More...
 
void Key_Init (void)
 
void Key_WriteBindings (const char *filename)
 Writes lines containing "bind key value". More...
 
const char * Key_GetBinding (const char *binding, keyBindSpace_t space)
 Return the key binding for a given script command. More...
 
const char * Key_KeynumToString (int keynum)
 Convert a given keynum to string. More...
 
int Key_StringToKeynum (const char *str)
 Convert to given string to keynum. More...
 
void Key_SetBinding (int keynum, const char *binding, keyBindSpace_t space)
 Bind a keynum to script command. More...
 

Variables

int msgMode
 
char msgBuffer [MAXCMDLINE]
 
size_t msgBufferLen
 
char keyLines [MAXKEYLINES][MAXCMDLINE]
 
uint32_t keyLinePos
 
int historyLine
 
int editLine
 
char * keyBindings [K_KEY_SIZE]
 
char * menuKeyBindings [K_KEY_SIZE]
 
char * battleKeyBindings [K_KEY_SIZE]
 

Detailed Description

Header file for keyboard handler.

Definition in file cl_keys.h.

Macro Definition Documentation

#define MAXKEYLINES   32

Definition at line 186 of file cl_keys.h.

Referenced by Con_LoadConsoleHistory(), Key_Console(), and Key_Init().

Enumeration Type Documentation

Enumerator
KEYSPACE_UI 
KEYSPACE_GAME 
KEYSPACE_BATTLE 
KEYSPACE_MAX 

Definition at line 173 of file cl_keys.h.

enum keydest_t
Enumerator
key_game 

input focus is on the menu (or the keyBindings)

key_console 

console is opened

Definition at line 181 of file cl_keys.h.

enum keyNum_t
Enumerator
K_FIRST_KEY 
K_BACKSPACE 
K_TAB 
K_ENTER 
K_PAUSE 
K_ESCAPE 
K_SPACE 
K_DEL 
K_MOUSE1 
K_MOUSE2 
K_MOUSE3 
K_MWHEELDOWN 
K_MWHEELUP 
K_MOUSE4 
K_MOUSE5 
K_KP_INS 
K_KP_END 
K_KP_DOWNARROW 
K_KP_PGDN 
K_KP_LEFTARROW 
K_KP_5 
K_KP_RIGHTARROW 
K_KP_HOME 
K_KP_UPARROW 
K_KP_PGUP 
K_KP_DEL 
K_KP_SLASH 
K_KP_MULTIPLY 
K_KP_MINUS 
K_KP_PLUS 
K_KP_ENTER 
K_KP_NUMLOCK 
K_UPARROW 
K_DOWNARROW 
K_RIGHTARROW 
K_LEFTARROW 
K_HOME 
K_END 
K_PGUP 
K_PGDN 
K_F1 
K_F2 
K_F3 
K_F4 
K_F5 
K_F6 
K_F7 
K_F8 
K_F9 
K_F10 
K_F11 
K_F12 
K_F13 
K_F14 
K_F15 
K_INS 
K_SHIFT 
K_CTRL 
K_ALT 
K_JOY1 
K_JOY2 
K_JOY3 
K_JOY4 
K_JOY5 
K_JOY6 
K_JOY7 
K_JOY8 
K_JOY9 
K_JOY10 
K_JOY11 
K_JOY12 
K_JOY13 
K_JOY14 
K_JOY15 
K_JOY16 
K_JOY17 
K_JOY18 
K_JOY19 
K_JOY20 
K_JOY21 
K_JOY22 
K_JOY23 
K_JOY24 
K_JOY25 
K_JOY26 
K_JOY27 
K_JOY28 
K_JOY29 
K_JOY30 
K_JOY31 
K_JOY32 
K_AUX1 
K_AUX2 
K_AUX3 
K_AUX4 
K_AUX5 
K_AUX6 
K_AUX7 
K_AUX8 
K_AUX9 
K_AUX10 
K_AUX11 
K_AUX12 
K_AUX13 
K_AUX14 
K_AUX15 
K_AUX16 
K_NUMLOCK 
K_SUPER 
K_COMPOSE 
K_MODE 
K_HELP 
K_PRINT 
K_SYSREQ 
K_SCROLLOCK 
K_BREAK 
K_MENU 
K_EURO 
K_UNDO 
K_COMMAND 
K_CAPSLOCK 
K_POWER 
K_APPS 
K_LAST_KEY 
K_KEY_SIZE 

Definition at line 35 of file cl_keys.h.

Function Documentation

void Key_Event ( unsigned int  key,
unsigned short  unicode,
bool  down,
unsigned  time 
)

Called by the system between frames for both key up and key down events.

Note
Should NOT be called during an interrupt!
See also
Key_Message

Definition at line 845 of file cl_keys.cpp.

References battleKeyBindings, Cbuf_AddText(), CL_OnBattlescape(), cls, Com_Error(), Con_ToggleConsole_f(), down, ERR_FATAL, i, IN_GetMouseSpace, K_ESCAPE, K_KEY_SIZE, K_MOUSE1, K_MWHEELUP, key, key_console, Key_Console(), key_game, Key_IsMouseButton(), keyBindings, client_static_s::keyDest, keyDown, menuKeyBindings, MS_UI, UI_KeyPressed(), UI_KeyRelease(), and unicode.

Referenced by IN_SendKeyEvents().

const char* Key_GetBinding ( const char *  binding,
keyBindSpace_t  space 
)

Return the key binding for a given script command.

Parameters
[in]bindingThe script command to bind keynum to
spaceNamespace of the key binding
See also
Key_SetBinding
Returns
the binded key or empty string if not found

Definition at line 511 of file cl_keys.cpp.

References battleKeyBindings, i, K_FIRST_KEY, K_LAST_KEY, Key_KeynumToString(), keyBindings, KEYSPACE_BATTLE, KEYSPACE_GAME, KEYSPACE_UI, menuKeyBindings, Q_streq, and Sys_Error().

void Key_Init ( void  )

Definition at line 776 of file cl_keys.cpp.

bool Key_IsDown ( unsigned int  key)

Checks whether a given key is currently pressed.

Parameters
[in]keyThe key to check,
See also
keyNum_t
Returns
true if the key is pressed, false otherwise

Definition at line 214 of file cl_keys.cpp.

References K_KEY_SIZE, key, and keyDown.

Referenced by uiAbstractValueNode::getFactorFloat(), uiContainerNode::onDndFinished(), and UI_ContainerNodeDrawDropPreview().

bool Key_IsNumlock ( void  )

Definition at line 221 of file cl_keys.cpp.

Referenced by IN_TranslateKey().

const char* Key_KeynumToString ( int  keynum)

Convert a given keynum to string.

Parameters
[in]keynumThe keynum to convert to string
Returns
a string (either a single ascii char, or a K_* name) for the given keynum.
Todo:
handle quote special (general escape sequence?)
See also
Key_StringToKeynum
Todo:
use isprint here?

Definition at line 485 of file cl_keys.cpp.

References keyName_t::name.

Referenced by CLMN_AddBindings(), CLMN_AddUIBindings(), IN_EventEnqueue(), Key_Bindlist_f(), Key_GetBinding(), Key_WriteBindings(), UI_SetKeyBindingEx(), and UI_Tooltip().

void Key_SetBinding ( int  keynum,
const char *  binding,
keyBindSpace_t  space 
)

Bind a keynum to script command.

Parameters
[in]keynumConverted from string to keynum
[in]bindingThe script command to bind keynum to
[in]spaceThe key space to bind the key for (menu, game or battle)
See also
Key_Bind_f
Key_StringToKeynum
Note
If command is empty, this function will only remove the actual key binding instead of setting empty string.

Definition at line 547 of file cl_keys.cpp.

References battleKeyBindings, Com_DPrintf(), com_genericPool, DEBUG_CLIENT, K_KEY_SIZE, keyBindings, KEYSPACE_BATTLE, KEYSPACE_GAME, KEYSPACE_UI, Mem_Free, Mem_PoolStrDup, and menuKeyBindings.

Referenced by Key_Bind_f(), Key_Unbind_f(), and Key_Unbindall_f().

void Key_SetDest ( keydest_t  keyDest)

Sets the keyDest in cls.

Parameters
[in]keyDestsee keydest_t

Definition at line 815 of file cl_keys.cpp.

References cls, key_console, client_static_s::keyDest, and UI_ReleaseInput().

Referenced by Con_Close(), Con_ToggleChat_f(), Con_ToggleConsole_f(), UI_PopWindow(), and UI_PushWindow().

int Key_StringToKeynum ( const char *  str)

Convert to given string to keynum.

Parameters
[in]strThe keystring to convert to keynum
Returns
a key number to be used to index keyBindings[] by looking at the given string. Single ascii characters return themselves, while the K_* names are matched up.
See also
Key_KeynumToString

Definition at line 462 of file cl_keys.cpp.

References keyName_t::name, Q_strcasecmp, and Q_strnull().

Referenced by CL_PressKey_f(), Key_Bind_f(), and Key_Unbind_f().

Variable Documentation

char* battleKeyBindings[K_KEY_SIZE]
int editLine

Definition at line 42 of file cl_keys.cpp.

Referenced by Con_DrawInput(), Con_LoadConsoleHistory(), Key_ClearTyping(), and Key_Console().

int historyLine

Definition at line 43 of file cl_keys.cpp.

Referenced by Con_LoadConsoleHistory(), Con_SaveConsoleHistory(), and Key_Console().

char* keyBindings[K_KEY_SIZE]
Todo:
To support international keyboards nicely, we will need full support for binding to either
  • a unicode value, however achieved
  • a key
  • modifier + key with a priority system to decide which to try first. This will mean that cleverly-hidden punctuation keys will still have their expected effect, even if they have to be pressed as Shift-AltGr-7 or something. At the same time, it allows key combinations to be bound regardless of what their translated meaning is, so that for example Shift-4 can do something with the 4th agent regardless of which punctuation symbol is above the 4.

Definition at line 63 of file cl_keys.cpp.

Referenced by CLMN_InitKeyList_f(), Key_Bind_f(), Key_Bindlist_f(), Key_Event(), Key_GetBinding(), Key_Init(), Key_SetBinding(), Key_Unbindall_f(), and Key_WriteBindings().

uint32_t keyLinePos

Definition at line 38 of file cl_keys.cpp.

Referenced by Con_DrawInput(), Key_ClearTyping(), Key_Console(), and Key_Init().

char msgBuffer[MAXCMDLINE]

Definition at line 46 of file cl_keys.cpp.

size_t msgBufferLen

Definition at line 47 of file cl_keys.cpp.

int msgMode

Definition at line 45 of file cl_keys.cpp.