![]() |
Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Hotkey system. More...


Go to the source code of this file.
Classes | |
| struct | SKey |
| struct | SHotkeyMapping |
Typedefs | |
| using | SDL_Scancode_ = int |
| typedef std::vector< SHotkeyMapping > | KeyMapping |
Functions | |
| void | LoadHotkeys (CConfigDB &configDB) |
| void | UnloadHotkeys () |
| InReaction | HotkeyStateChange (const SDL_Event_ *ev) |
| Updates g_HotkeyMap. More... | |
| InReaction | HotkeyInputPrepHandler (const SDL_Event_ *ev) |
| Detects hotkeys that should fire. More... | |
| InReaction | HotkeyInputActualHandler (const SDL_Event_ *ev) |
| Actually fires hotkeys. More... | |
| bool | EventWillFireHotkey (const SDL_Event_ *ev, const CStr &keyname) |
| void | ResetActiveHotkeys () |
| Resets all currently active hotkeys (and clears in-flight hotkeys). More... | |
| bool | HotkeyIsPressed (const CStr &keyname) |
Variables | |
| const uint | SDL_USEREVENT_ = 0x8000 |
| const uint | SDL_HOTKEYPRESS = SDL_USEREVENT_ |
| const uint | SDL_HOTKEYDOWN = SDL_USEREVENT_ + 1 |
| const uint | SDL_HOTKEYUP = SDL_USEREVENT_ + 2 |
| const uint | SDL_HOTKEYPRESS_SILENT = SDL_USEREVENT_ + 3 |
| const uint | SDL_HOTKEYUP_SILENT = SDL_USEREVENT_ + 4 |
| constexpr SDL_Scancode_ | UNUSED_HOTKEY_CODE = 0 |
| std::unordered_map< SDL_Scancode_, KeyMapping > | g_HotkeyMap |
Hotkey system.
Hotkeys consist of a name (an arbitrary string), and a key mapping. The names and mappings are loaded from the config system (any config setting with the name prefix "hotkey."). When a hotkey is pressed one SDL_HOTKEYPRESS is triggered. While the key is kept down repeated SDL_HOTKEYDOWN events are triggered at an interval determined by the OS. When a hotkey is released an SDL_HOTKEYUP event is triggered. All with the hotkey name stored in ev.user.data1 as a const char*.
| typedef std::vector<SHotkeyMapping> KeyMapping |
| using SDL_Scancode_ = int |
| bool EventWillFireHotkey | ( | const SDL_Event_ * | ev, |
| const CStr & | keyname | ||
| ) |
| ev | will fire the hotkey |
| keyname. |
| InReaction HotkeyInputActualHandler | ( | const SDL_Event_ * | ev | ) |
Actually fires hotkeys.
| InReaction HotkeyInputPrepHandler | ( | const SDL_Event_ * | ev | ) |
Detects hotkeys that should fire.
This allows using EventWillFireHotkey, (and then possibly preventing those hotkeys from firing by handling the event).
Hotkey behaviour spec (see also tests):
| bool HotkeyIsPressed | ( | const CStr & | keyname | ) |
| InReaction HotkeyStateChange | ( | const SDL_Event_ * | ev | ) |
Updates g_HotkeyMap.
| void LoadHotkeys | ( | CConfigDB & | configDB | ) |
| void ResetActiveHotkeys | ( | ) |
Resets all currently active hotkeys (and clears in-flight hotkeys).
You should call this when something grabs key input, e.g. an input box, as those prevent keydown/keyup messages from reaching the hotkey system, and can lead to hotkeys being stuck active. NB: active hotkeys are released immediately and "HotkeyUp" message sent.
| void UnloadHotkeys | ( | ) |
|
extern |
| const uint SDL_HOTKEYDOWN = SDL_USEREVENT_ + 1 |
| const uint SDL_HOTKEYPRESS = SDL_USEREVENT_ |
| const uint SDL_HOTKEYPRESS_SILENT = SDL_USEREVENT_ + 3 |
| const uint SDL_HOTKEYUP = SDL_USEREVENT_ + 2 |
| const uint SDL_HOTKEYUP_SILENT = SDL_USEREVENT_ + 4 |
| const uint SDL_USEREVENT_ = 0x8000 |
|
constexpr |