Atrinik Client  4.0
Functions | Variables
keybind.c File Reference
#include <global.h>
#include <toolkit/packet.h>
#include <toolkit/string.h>
#include <toolkit/path.h>

Go to the source code of this file.

Functions

void keybind_load (void)
 
void keybind_save (void)
 
void keybind_free (keybind_struct *keybind)
 
void keybind_deinit (void)
 
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_process (keybind_struct *keybind, uint8_t type)
 
int keybind_process_command_up (const char *cmd)
 
void keybind_state_ensure (void)
 
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 237 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 196 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 391 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 414 of file keybind.c.

void keybind_deinit ( void  )

Deinitialize all keybindings.

Definition at line 168 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 266 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 371 of file keybind.c.

void keybind_free ( keybind_struct keybind)

Free a single keybinding entry.

Parameters
keybindKeybinding to free.

Definition at line 159 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 336 of file keybind.c.

void keybind_load ( void  )

Load keybindings.

Definition at line 60 of file keybind.c.

void keybind_process ( keybind_struct keybind,
uint8_t  type 
)

Process a keybinding.

Parameters
keybindThe keybinding to process.
typeEither SDL_KEYDOWN or SDL_KEYUP.

Definition at line 467 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 553 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 503 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 436 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_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 ( void  )

Save the keybindings.

Definition at line 122 of file keybind.c.

void keybind_state_ensure ( void  )

Ensure that keybindings which should trigger on 'key up' event have done so, even if the 'key up' event was handled by something else.

Definition at line 535 of file keybind.c.

Variable Documentation

keybind_struct** keybindings = NULL

The keybindings.

Definition at line 53 of file keybind.c.

size_t keybindings_num = 0

Number of keybindings.

Definition at line 55 of file keybind.c.