Atrinik Client 2.5
Functions | Variables
client/keybind.c File Reference
#include <global.h>

Go to the source code of this file.

Functions

void keybind_load ()
void keybind_save ()
void keybind_free (keybind_struct *keybind)
void keybind_deinit ()
static SDLMod keybind_adjust_kmod (SDLMod mod)
keybind_structkeybind_add (SDLKey key, SDLMod mod, const char *command)
void keybind_edit (size_t i, SDLKey key, SDLMod mod, const char *command)
void keybind_remove (size_t i)
void keybind_repeat_toggle (size_t i)
char * keybind_get_key_shortcut (SDLKey key, SDLMod mod, char *buf, size_t len)
keybind_structkeybind_find_by_command (const char *cmd)
int keybind_command_matches_event (const char *cmd, SDL_KeyboardEvent *event)
int keybind_command_matches_state (const char *cmd)
int keybind_process_event (SDL_KeyboardEvent *event)
void keybind_repeat ()
void keybind_process (keybind_struct *keybind, uint8 type)
int keybind_process_command_up (const char *cmd)
int keybind_process_command (const char *cmd)

Variables

keybind_struct ** keybindings = NULL
size_t keybindings_num = 0

Detailed Description

Handles keybindings.

Whenever a keyboard event occurs and the user is logged into the game, keybindings are checked for a match. First keybindings with modifier keys are checked to see if they match the event key and modifier state, then keybindings without modifier keys are checked and will work regardless of the current key modifier state.

This is done to ensure user commands will work correctly, even if they have modifier keys. For example, CTRL+c would not work if it was near the bottom of the keybinding list, because the 'c' keybinding near the top would work first.

Also if the keybindings with no modifier keys were not triggered regardless of the current keyboard modifier state, it would not be possible to do actions such as alt+numpad, or ctrl+numpad.

Author:
Alex Tokar

Definition in file keybind.c.


Function Documentation

keybind_struct* keybind_add ( SDLKey  key,
SDLMod  mod,
const char *  command 
)

Add a keybinding to the keybindings array.

Parameters:
keyKey the keybinding uses.
modModifier for the keybinding shortcut. Will be adjusted by keybind_adjust_kmod().
commandCommand to execute when the keybinding is activated.
Returns:
The added keybinding.

Definition at line 243 of file keybind.c.

static SDLMod keybind_adjust_kmod ( SDLMod  mod) [static]

Adjust SDLMod state value. This is done because the state may have other flags we do not care about, and we do not want to save those to file. It also simplifies keyboard modifier state checks.

Parameters:
modState to adjust.
Returns:
Adjusted state.

Definition at line 203 of file keybind.c.

int keybind_command_matches_event ( const char *  cmd,
SDL_KeyboardEvent *  event 
)

Check if the specified keybinding command matches a keyboard event.

Parameters:
cmdThe keybinding command.
Returns:
1 if it matches, 0 otherwise.

Definition at line 384 of file keybind.c.

int keybind_command_matches_state ( const char *  cmd)

Check if the specified keybinding command matches the current keyboard state.

Parameters:
cmdThe keybinding command.
Returns:
1 if it matches, 0 otherwise.

Definition at line 406 of file keybind.c.

void keybind_deinit ( )

Deinitialize all keybindings.

Definition at line 176 of file keybind.c.

void keybind_edit ( size_t  i,
SDLKey  key,
SDLMod  mod,
const char *  command 
)

Edit the specified keybinding.

Parameters:
iIndex inside the keybindings array to edit.
keyKey to change.
modModifier to change.
commandCommand to change.

Definition at line 267 of file keybind.c.

keybind_struct* keybind_find_by_command ( const char *  cmd)

Finds keybinding structure by command name.

Parameters:
cmdThe command to find.
Returns:
Keybinding if found, NULL otherwise.

Definition at line 365 of file keybind.c.

void keybind_free ( keybind_struct keybind)

Free a single keybinding entry.

Parameters:
keybindKeybinding to free.

Definition at line 168 of file keybind.c.

char* keybind_get_key_shortcut ( SDLKey  key,
SDLMod  mod,
char *  buf,
size_t  len 
)

Construct a text representation of a keybinding shortcut.

Parameters:
keyKey of the shortcut.
modKeyboard modifier.
bufWhere to store the result.
lenSize of 'buf'.
Returns:
'buf'.

Definition at line 331 of file keybind.c.

void keybind_load ( )

Load keybindings.

Definition at line 56 of file keybind.c.

void keybind_process ( keybind_struct keybind,
uint8  type 
)

Process a keybinding.

Parameters:
keybindThe keybinding to process.
typeEither SDL_KEYDOWN or SDL_KEYUP.

Definition at line 501 of file keybind.c.

int keybind_process_command ( const char *  cmd)

Handle keybinding 'key down' event.

Parameters:
cmdKeybinding command to handle.
Returns:
1 if the command was handled, 0 otherwise.

Definition at line 564 of file keybind.c.

int keybind_process_command_up ( const char *  cmd)

Handle keybinding 'key up' event.

Parameters:
cmdKeybinding command to handle.
Returns:
1 if the command was handled, 0 otherwise.

Definition at line 534 of file keybind.c.

int keybind_process_event ( SDL_KeyboardEvent *  event)

Attempt to process a keyboard event.

Parameters:
eventThe event to process.
Returns:
1 if the event was handled, 0 otherwise.

Definition at line 427 of file keybind.c.

void keybind_remove ( size_t  i)

Remove a keybinding from keybindings.

Parameters:
iIndex in the keybindings array to remove.

Definition at line 285 of file keybind.c.

void keybind_repeat ( )

Handle key repeating.

Definition at line 457 of file keybind.c.

void keybind_repeat_toggle ( size_t  i)

Toggle the repeat state of a keybinding.

Parameters:
iIndex in the keybindings array to toggle the repeat state of.

Definition at line 313 of file keybind.c.

void keybind_save ( )

Save the keybindings.

Definition at line 132 of file keybind.c.


Variable Documentation

The keybindings.

Definition at line 50 of file keybind.c.

size_t keybindings_num = 0

Number of keybindings.

Definition at line 52 of file keybind.c.