OpenTTD Source: src/hotkeys.cpp File Reference

OpenTTD Source 15.0-beta1

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_t | ParseCode (const char *start, const char *end)
| Try to parse a single part of a keycode.
static uint16_t | ParseKeycode (const char *start, const char *end)
| Parse a string representation of a keycode.
static void | ParseHotkeys (Hotkey &hotkey, const char *value)
| Parse a string to the keycodes it represents.
static std::string | KeycodeToString (uint16_t keycode)
| Convert a hotkey to it's string representation so it can be written to the config file.
std::string | SaveKeycodes (const Hotkey &hotkey)
| Convert all keycodes attached to a hotkey to a single string.
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 (char32_t key, uint16_t keycode)

## Variables
std::string | _hotkeys_file
static std::vector< HotkeyList * > * | _hotkey_lists = nullptr
| List of all HotkeyLists.
static const std::initializer_list< KeycodeNames > | _keycode_to_name
| Array of non-standard keycodes that can be used in the hotkeys config file.

## Detailed Description

Implementation of hotkey related functions.

Definition in file hotkeys.cpp.

## Function Documentation

## ◆ HandleGlobalHotkeys()

void HandleGlobalHotkeys | ( | char32_t | key,
|  | uint16_t | keycode
| ) |  |

Definition at line 351 of file hotkeys.cpp.

## ◆ KeycodeToString()

static std::string KeycodeToString | ( | uint16_t | 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

  keycode | The keycode to convert to a string.

Returns
  A string representation of this keycode.

Definition at line 171 of file hotkeys.cpp.

References _keycode_to_name, and WKC_GLOBAL_HOTKEY.

Referenced by SaveKeycodes().

## ◆ LoadHotkeysFromConfig()

void LoadHotkeysFromConfig | ( |  | ) |

Load the hotkeys from the config file.

Definition at line 340 of file hotkeys.cpp.

Referenced by AfterNewGRFScan::OnNewGRFsScanned().

## ◆ ParseCode()

static uint16_t ParseCode | ( | const char * | start,
|  | const char * | end
| ) |  |
| static

Try to parse a single part of a keycode.

Parameters

  start | Start of the string to parse.
  end | End of the string to parse.

Returns
  A keycode if a match is found or 0.

Definition at line 97 of file hotkeys.cpp.

References _keycode_to_name, and StrEqualsIgnoreCase().

Referenced by ParseKeycode().

## ◆ ParseHotkeys()

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

Parse a string to the keycodes it represents.

Parameters

  hotkey | The hotkey object to add the keycodes to
  value | The string to parse

Definition at line 152 of file hotkeys.cpp.

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

Referenced by HotkeyList::Load().

## ◆ ParseKeycode()

static uint16_t ParseKeycode | ( | const char * | start,
|  | const char * | end
| ) |  |
| static

Parse a string representation of a keycode.

Parameters

  start | Start of the input.
  end | End of the input.

Returns
  A valid keycode or 0.

Definition at line 122 of file hotkeys.cpp.

References ParseCode().

Referenced by ParseHotkeys().

## ◆ SaveHotkeysToConfig()

void SaveHotkeysToConfig | ( |  | ) |

Save the hotkeys to the config file.

Definition at line 346 of file hotkeys.cpp.

## ◆ SaveKeycodes()

std::string 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

  hotkey | The keycodes of this hotkey need to be converted to a string.

Returns
  A string representation of all keycodes.

Definition at line 213 of file hotkeys.cpp.

References KeycodeToString().

Referenced by HotkeyList::Save().

## ◆ SaveLoadHotkeys()

static void SaveLoadHotkeys | ( | bool | save | ) |
| static

Definition at line 322 of file hotkeys.cpp.

## Variable Documentation

## ◆ _hotkey_lists

std::vector<HotkeyList*>* _hotkey_lists = nullptr
| static

List of all HotkeyLists.

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

Definition at line 25 of file hotkeys.cpp.

## ◆ _hotkeys_file

std::string _hotkeys_file

Definition at line 19 of file hotkeys.cpp.

## ◆ _keycode_to_name

const std::initializer_list<KeycodeNames> _keycode_to_name
| static

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

Definition at line 34 of file hotkeys.cpp.

Referenced by KeycodeToString(), and ParseCode().