cl_keys.c File Reference

Keyboard handling routines. More...

#include "../client.h"
#include "../cl_screen.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.c:

Go to the source code of this file.

Data Structures

struct  keyName_t

Defines

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

Functions

static void Key_Console (int key, int unicode)
 Interactive line editing and console scrollback.
static void Key_Message (int key)
 Handles input when cls.keyDest == key_message.
static 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 (int keyDest)
 Sets the keyDest in cls.
void Key_Event (unsigned int key, unsigned short unicode, qboolean down, unsigned time)
 Called by the system between frames for both key up and key down events.

Variables

char keyLines [MAXKEYLINES][MAXCMDLINE]
int 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 qboolean 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.c.


Define Documentation

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

Definition at line 75 of file cl_keys.c.

Referenced by DisplayContentFlags(), 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 695 of file cl_keys.c.

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

Referenced by Key_Init().

static void Key_Bindlist_f ( void   )  [static]

List all binded keys with its function.

Definition at line 825 of file cl_keys.c.

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 844 of file cl_keys.c.

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

Referenced by Key_Init().

static void Key_Console ( int  key,
int  unicode 
) [static]
void Key_Event ( unsigned int  key,
unsigned short  unicode,
qboolean  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 921 of file cl_keys.c.

References battleKeyBindings, Cbuf_AddText(), CL_OnBattlescape(), cls, Com_Error(), Com_sprintf(), Con_ToggleConsole_f(), ERR_FATAL, i, K_ESCAPE, K_KEY_SIZE, K_MOUSE1, K_MWHEELUP, Key_Console(), key_console, key_game, Key_Message(), key_message, keyBindings, client_static_s::keyDest, keyDown, MAX_STRING_CHARS, menuKeyBindings, mouseSpace, MS_UI, and UI_KeyPressed().

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] binding The script command to bind keynum to
See also:
Key_SetBinding
Returns:
the binded key or empty string if not found

Definition at line 573 of file cl_keys.c.

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

Referenced by UI_GetReferenceString(), and UI_KeyBindingNodeKeyPressed().

void Key_Init ( void   ) 

Definition at line 872 of file cl_keys.c.

Referenced by Qcommon_Init().

const char* Key_KeynumToString ( int  keynum  ) 

Convert a given keynum to string.

Parameters:
[in] keynum The 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 546 of file cl_keys.c.

References keyName_t::keynum, and keyName_t::name.

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

static void Key_Message ( int  key  )  [static]

Handles input when cls.keyDest == key_message.

Note:
Used for chatting and cvar editing via menu
See also:
Key_Event
UI_LeftClick

Todo:
figure out which unicode codes to accept

Definition at line 445 of file cl_keys.c.

References ca_active, ca_disconnected, Cbuf_AddText(), cls, Com_DPrintf(), Com_Error(), Com_Printf(), DEBUG_CLIENT, ERR_DROP, K_BACKSPACE, K_ENTER, K_ESCAPE, K_KP_ENTER, key_game, Key_SetDest(), MSG_SAY, MSG_SAY_TEAM, msgBuffer, msgBufferLen, msgMode, qfalse, qtrue, client_static_s::state, UTF8_delete_char(), UTF8_encoded_len(), and UTF8_insert_char().

Referenced by Key_Event().

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

Bind a keynum to script command.

Parameters:
[in] keynum Converted from string to keynum
[in] binding The script command to bind keynum to
[in] space The 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 610 of file cl_keys.c.

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

void Key_SetDest ( int  keyDest  ) 

Sets the keyDest in cls.

Parameters:
[in] keyDest see keydest_t

Definition at line 907 of file cl_keys.c.

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

Referenced by Con_Close(), Con_MessageModeSay_f(), Con_MessageModeSayTeam_f(), Con_ToggleChat_f(), Con_ToggleConsole_f(), Key_Message(), UI_PopWindow(), and UI_PushWindowDelete().

static int Key_StringToKeynum ( const char *  str  )  [static]

Convert to given string to keynum.

Parameters:
[in] str The 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 521 of file cl_keys.c.

References keyName_t::keynum, keyName_t::name, and Q_strcasecmp.

Referenced by 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 651 of file cl_keys.c.

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

Referenced by Key_Init().

static void Key_Unbindall_f ( void   )  [static]

Unbind all key bindings.

See also:
Key_SetBinding

Definition at line 678 of file cl_keys.c.

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

Referenced by Key_Init().

void Key_WriteBindings ( const char *  filename  ) 
static void Key_WriteBindings_f ( void   )  [static]

Variable Documentation

char* battleKeyBindings[K_KEY_SIZE]
int editLine = 0

Definition at line 43 of file cl_keys.c.

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

int historyLine = 0

Definition at line 44 of file cl_keys.c.

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 64 of file cl_keys.c.

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

qboolean keyDown[K_KEY_SIZE] [static]

Definition at line 68 of file cl_keys.c.

Referenced by Key_Console(), and Key_Event().

int keyInsert = 1 [static]

Definition at line 41 of file cl_keys.c.

Referenced by Key_Console().

Definition at line 39 of file cl_keys.c.

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

char keyLines[MAXKEYLINES][MAXCMDLINE]
const keyName_t keyNames[] [static]

Definition at line 76 of file cl_keys.c.

char* menuKeyBindings[K_KEY_SIZE]
char msgBuffer[MAXCMDLINE]

Definition at line 47 of file cl_keys.c.

Referenced by Con_DrawNotify(), and Key_Message().

size_t msgBufferLen = 0

Definition at line 48 of file cl_keys.c.

Referenced by Con_DrawNotify(), and Key_Message().

int msgMode

Generated by  doxygen 1.6.2