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

Keyboard handling routines. More...

#include "../client.h"
#include "../cl_console.h"
#include "../ui/ui_input.h"
#include "../ui/ui_nodes.h"
#include "../../shared/utf8.h"

Go to the source code of this file.

Data Structures

struct  keyName_t
 

Macros

#define M(x)   {#x, K_##x}
 

Functions

bool Key_IsDown (unsigned int key)
 Checks whether a given key is currently pressed. More...
 
bool Key_IsNumlock (void)
 
static void Key_Console (int key, int unicode)
 Interactive line editing and console scrollback. More...
 
int Key_StringToKeynum (const char *str)
 Convert to given string to keynum. More...
 
const char * Key_KeynumToString (int keynum)
 Convert a given keynum to string. More...
 
const char * Key_GetBinding (const char *binding, keyBindSpace_t space)
 Return the key binding for a given script command. More...
 
void Key_SetBinding (int keynum, const char *binding, keyBindSpace_t space)
 Bind a keynum to script command. More...
 
static void Key_Unbind_f (void)
 Unbind a given key binding. More...
 
static void Key_Unbindall_f (void)
 Unbind all key bindings. More...
 
static void Key_Bind_f (void)
 Binds a key to a given script command. More...
 
void Key_WriteBindings (const char *filename)
 Writes lines containing "bind key value". More...
 
static void Key_WriteBindings_f (void)
 
static void Key_Bindlist_f (void)
 List all binded keys with its function. More...
 
static int Key_CompleteKeyName (const char *partial, const char **match)
 
void Key_Init (void)
 
void Key_SetDest (keydest_t keyDest)
 Sets the keyDest in cls. More...
 
static bool Key_IsMouseButton (unsigned int key)
 Returns true if the Key is a mouse event. 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...
 

Variables

char keyLines [MAXKEYLINES][MAXCMDLINE]
 
uint32_t keyLinePos
 
static int keyInsert = 1
 
int editLine = 0
 
int historyLine = 0
 
int msgMode
 
char msgBuffer [MAXCMDLINE]
 
size_t msgBufferLen = 0
 
char * keyBindings [K_KEY_SIZE]
 
char * menuKeyBindings [K_KEY_SIZE]
 
char * battleKeyBindings [K_KEY_SIZE]
 
static bool keyDown [K_KEY_SIZE]
 
static const keyName_t keyNames []
 

Detailed Description

Keyboard handling routines.

Note: Key up events are sent even if in console mode

Definition in file cl_keys.cpp.

Macro Definition Documentation

#define M (   x)    {#x, K_##x}

Definition at line 74 of file cl_keys.cpp.

Referenced by mdfour_tail(), and mdfour_update().

Function Documentation

static void Key_Bind_f ( void  )
static

Binds a key to a given script command.

See also
Key_SetBinding

Definition at line 626 of file cl_keys.cpp.

References Cmd_Argc(), Cmd_Argv(), Com_Printf(), Key_SetBinding(), Key_StringToKeynum(), keyBindings, KEYSPACE_BATTLE, KEYSPACE_GAME, KEYSPACE_UI, Q_streq, and UI_SetKeyBinding().

Referenced by Key_Init().

static void Key_Bindlist_f ( void  )
static

List all binded keys with its function.

Definition at line 747 of file cl_keys.cpp.

References battleKeyBindings, Com_Printf(), i, K_FIRST_KEY, K_LAST_KEY, Key_KeynumToString(), keyBindings, and menuKeyBindings.

Referenced by Key_Init().

static int Key_CompleteKeyName ( const char *  partial,
const char **  match 
)
static

Definition at line 764 of file cl_keys.cpp.

References Cmd_GenericCompleteFunction(), Com_Printf(), and keyName_t::name.

Referenced by Key_Init().

static void Key_Console ( int  key,
int  unicode 
)
static

Interactive line editing and console scrollback.

Parameters
[in]keykey code, either K_ value or lowercase ascii
[in]unicodetranslated meaning of keypress in unicode
Todo:
use isprint here?

Definition at line 236 of file cl_keys.cpp.

References Cbuf_AddText(), Com_ConsoleCompleteCommand(), Com_Printf(), Con_Scroll(), CONSOLE_PROMPT_CHAR, editLine, historyLine, i, K_BACKSPACE, K_CTRL, K_DEL, K_DOWNARROW, K_END, K_ENTER, K_HOME, K_INS, K_KP_5, K_KP_DEL, K_KP_DOWNARROW, K_KP_END, K_KP_ENTER, K_KP_HOME, K_KP_INS, K_KP_LEFTARROW, K_KP_MINUS, K_KP_MULTIPLY, K_KP_PGDN, K_KP_PGUP, K_KP_PLUS, K_KP_RIGHTARROW, K_KP_SLASH, K_KP_UPARROW, K_LEFTARROW, K_MWHEELDOWN, K_MWHEELUP, K_PGDN, K_PGUP, K_RIGHTARROW, K_TAB, K_UPARROW, key, keyDown, keyInsert, keyLinePos, keyLines, MAXCMDLINE, MAXKEYLINES, Q_strncpyz(), and unicode.

Referenced by Key_Event().

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().

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().

static bool Key_IsMouseButton ( unsigned int  key)
static

Returns true if the Key is a mouse event.

Parameters
[in]keyKey code

Definition at line 835 of file cl_keys.cpp.

References K_MOUSE1, and K_MOUSE5.

Referenced by Key_Event().

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().

static void Key_Unbind_f ( void  )
static

Unbind a given key binding.

See also
Key_SetBinding

Definition at line 586 of file cl_keys.cpp.

References Cmd_Argc(), Cmd_Argv(), Com_Printf(), Key_SetBinding(), Key_StringToKeynum(), KEYSPACE_BATTLE, KEYSPACE_GAME, KEYSPACE_UI, and Q_streq.

Referenced by Key_Init().

static void Key_Unbindall_f ( void  )
static

Unbind all key bindings.

See also
Key_SetBinding

Definition at line 611 of file cl_keys.cpp.

References Cmd_Argv(), i, K_FIRST_KEY, K_LAST_KEY, Key_SetBinding(), keyBindings, KEYSPACE_GAME, KEYSPACE_UI, and Q_streq.

Referenced by Key_Init().

static void Key_WriteBindings_f ( void  )
static

Variable Documentation

char* battleKeyBindings[K_KEY_SIZE]
int editLine = 0

Definition at line 42 of file cl_keys.cpp.

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

int historyLine = 0

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().

bool keyDown[K_KEY_SIZE]
static

Definition at line 67 of file cl_keys.cpp.

Referenced by IN_EventEnqueue(), Key_Console(), Key_Event(), Key_Init(), and Key_IsDown().

int keyInsert = 1
static

Definition at line 40 of file cl_keys.cpp.

Referenced by Key_Console().

uint32_t keyLinePos

Definition at line 38 of file cl_keys.cpp.

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

const keyName_t keyNames[]
static

Definition at line 75 of file cl_keys.cpp.

char msgBuffer[MAXCMDLINE]

Definition at line 46 of file cl_keys.cpp.

size_t msgBufferLen = 0

Definition at line 47 of file cl_keys.cpp.

int msgMode

Definition at line 45 of file cl_keys.cpp.