OpenTTD
Data Structures | Functions | Variables
hotkeys.cpp File Reference

Implementation of hotkey related functions. More...

#include "stdafx.h"
#include "openttd.h"
#include "hotkeys.h"
#include "ini_type.h"
#include "string_func.h"
#include "window_gui.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  KeycodeNames
 String representation of a keycode. More...
 

Functions

static uint16 ParseCode (const char *start, const char *end)
 Try to parse a single part of a keycode. More...
 
static uint16 ParseKeycode (const char *start, const char *end)
 Parse a string representation of a keycode. More...
 
static void ParseHotkeys (Hotkey *hotkey, const char *value)
 Parse a string to the keycodes it represents. More...
 
static const char * KeycodeToString (uint16 keycode)
 Convert a hotkey to it's string representation so it can be written to the config file. More...
 
const char * SaveKeycodes (const Hotkey *hotkey)
 Convert all keycodes attached to a hotkey to a single string. More...
 
static void SaveLoadHotkeys (bool save)
 
void LoadHotkeysFromConfig ()
 Load the hotkeys from the config file.
 
void SaveHotkeysToConfig ()
 Save the hotkeys to the config file.
 
void HandleGlobalHotkeys (WChar key, uint16 keycode)
 

Variables

char * _hotkeys_file
 
static SmallVector< HotkeyList *, 16 > * _hotkey_lists = NULL
 List of all HotkeyLists. More...
 
static const KeycodeNames _keycode_to_name []
 Array of non-standard keycodes that can be used in the hotkeys config file. More...
 

Detailed Description

Implementation of hotkey related functions.

Definition in file hotkeys.cpp.

Function Documentation

◆ KeycodeToString()

static const char* KeycodeToString ( uint16  keycode)
static

Convert a hotkey to it's string representation so it can be written to the config file.

Separate parts of the keycode (like "CTRL" and "F1" are split by a '+'.

Parameters
keycodeThe keycode to convert to a string.
Returns
A string representation of this keycode.
Note
The return value is a static buffer, stredup the result before calling this function again.

Definition at line 147 of file hotkeys.cpp.

References lastof, strecat(), and WKC_GLOBAL_HOTKEY.

Referenced by SaveKeycodes().

◆ ParseCode()

static uint16 ParseCode ( const char *  start,
const char *  end 
)
static

Try to parse a single part of a keycode.

Parameters
startStart of the string to parse.
endEnd of the string to parse.
Returns
A keycode if a match is found or 0.

Definition at line 72 of file hotkeys.cpp.

◆ ParseHotkeys()

static void ParseHotkeys ( Hotkey hotkey,
const char *  value 
)
static

Parse a string to the keycodes it represents.

Parameters
hotkeyThe hotkey object to add the keycodes to
valueThe string to parse

Definition at line 126 of file hotkeys.cpp.

References Hotkey::AddKeycode(), KeycodeNames::keycode, and ParseKeycode().

Referenced by HotkeyList::Load().

◆ ParseKeycode()

static uint16 ParseKeycode ( const char *  start,
const char *  end 
)
static

Parse a string representation of a keycode.

Parameters
startStart of the input.
endEnd of the input.
Returns
A valid keycode or 0.

Definition at line 96 of file hotkeys.cpp.

Referenced by ParseHotkeys().

◆ SaveKeycodes()

const char* SaveKeycodes ( const Hotkey hotkey)

Convert all keycodes attached to a hotkey to a single string.

If multiple keycodes are attached to the hotkey they are split by a comma.

Parameters
hotkeyThe keycodes of this hotkey need to be converted to a string.
Returns
A string representation of all keycodes.
Note
The return value is a static buffer, stredup the result before calling this function again.

Definition at line 201 of file hotkeys.cpp.

References KeycodeToString(), lastof, SmallVector< T, S >::Length(), and strecat().

Referenced by HotkeyList::Save().

Variable Documentation

◆ _hotkey_lists

SmallVector<HotkeyList*, 16>* _hotkey_lists = NULL
static

List of all HotkeyLists.

This is a pointer to ensure initialisation order with the various static HotkeyList instances.

Definition at line 27 of file hotkeys.cpp.

◆ _keycode_to_name

const KeycodeNames _keycode_to_name[]
static
Initial value:
= {
{"SHIFT", WKC_SHIFT},
{"CTRL", WKC_CTRL},
{"ALT", WKC_ALT},
{"META", WKC_META},
{"GLOBAL", WKC_GLOBAL_HOTKEY},
{"ESC", WKC_ESC},
{"DEL", WKC_DELETE},
{"RETURN", WKC_RETURN},
{"BACKQUOTE", WKC_BACKQUOTE},
{"F1", WKC_F1},
{"F2", WKC_F2},
{"F3", WKC_F3},
{"F4", WKC_F4},
{"F5", WKC_F5},
{"F6", WKC_F6},
{"F7", WKC_F7},
{"F8", WKC_F8},
{"F9", WKC_F9},
{"F10", WKC_F10},
{"F11", WKC_F11},
{"F12", WKC_F12},
{"PAUSE", WKC_PAUSE},
{"COMMA", WKC_COMMA},
{"NUM_PLUS", WKC_NUM_PLUS},
{"NUM_MINUS", WKC_NUM_MINUS},
{"=", WKC_EQUALS},
{"-", WKC_MINUS},
}
, Comma
Definition: gfx_type.h:104
= Equals
Definition: gfx_type.h:99
Fake keycode bit to indicate global hotkeys.
Definition: gfx_type.h:35

Array of non-standard keycodes that can be used in the hotkeys config file.

Definition at line 36 of file hotkeys.cpp.