UFO: Alien Invasion
Loading...
Searching...
No Matches
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"
Include dependency graph for cl_keys.cpp:

Go to the source code of this file.

Data Structures

struct  keyName_t

Macros

#define M(x)

Functions

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

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

◆ M

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

Definition at line 74 of file cl_keys.cpp.

Referenced by copy64(), mdfour64(), mdfour_tail(), and mdfour_update().

Function Documentation

◆ Key_Bind_f()

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

◆ Key_Bindlist_f()

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

◆ Key_CompleteKeyName()

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 keyNames.

Referenced by Key_Init().

◆ Key_Console()

void Key_Console ( int key,
int unicode )
static

◆ 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 841 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, keyDown, menuKeyBindings, MS_UI, UI_KeyPressed(), UI_KeyRelease(), and unicode.

Referenced by IN_SendKeyEvents().

◆ Key_GetBinding()

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, binding, i, K_FIRST_KEY, K_LAST_KEY, Key_KeynumToString(), keyBindings, KEYSPACE_BATTLE, KEYSPACE_GAME, KEYSPACE_UI, menuKeyBindings, Q_streq, and Sys_Error().

◆ Key_Init()

◆ Key_IsDown()

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

◆ Key_IsMouseButton()

bool Key_IsMouseButton ( unsigned int key)
static

Returns true if the Key is a mouse event.

Parameters
[in]keyKey code

Definition at line 831 of file cl_keys.cpp.

References K_MOUSE1, K_MOUSE5, and key.

Referenced by Key_Event().

◆ Key_IsNumlock()

bool Key_IsNumlock ( void )

Definition at line 221 of file cl_keys.cpp.

Referenced by IN_TranslateKey().

◆ Key_KeynumToString()

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 keyNames.

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

◆ Key_SetBinding()

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

◆ Key_SetDest()

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, and UI_ReleaseInput().

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

◆ Key_StringToKeynum()

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 keyNames, Q_strcasecmp, and Q_strnull().

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

◆ Key_Unbind_f()

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

◆ Key_Unbindall_f()

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

◆ Key_WriteBindings()

void Key_WriteBindings ( const char * filename)

◆ Key_WriteBindings_f()

void Key_WriteBindings_f ( void )
static

Variable Documentation

◆ battleKeyBindings

char* battleKeyBindings[K_KEY_SIZE]

◆ editLine

int editLine = 0

Definition at line 42 of file cl_keys.cpp.

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

◆ historyLine

int historyLine = 0

Definition at line 43 of file cl_keys.cpp.

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

◆ keyBindings

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

◆ keyDown

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

◆ keyInsert

int keyInsert = 1
static

Definition at line 40 of file cl_keys.cpp.

Referenced by Key_Console().

◆ keyLinePos

uint32_t keyLinePos

Definition at line 38 of file cl_keys.cpp.

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

◆ keyLines

◆ keyNames

const keyName_t keyNames[]
static

Definition at line 75 of file cl_keys.cpp.

Referenced by Key_CompleteKeyName(), Key_KeynumToString(), and Key_StringToKeynum().

◆ menuKeyBindings

◆ msgBuffer

char msgBuffer[MAXCMDLINE]

Definition at line 46 of file cl_keys.cpp.

◆ msgBufferLen

size_t msgBufferLen = 0

Definition at line 47 of file cl_keys.cpp.

◆ msgMode

int msgMode

Definition at line 45 of file cl_keys.cpp.