34 std::function<
void()> functor)
36 if (_registeredShortcuts.find(key) != _registeredShortcuts.end())
38 std::stringstream message;
39 message << key <<
" is already registered";
45 _registeredShortcuts[key] = shortcutInformation;
52 auto it = _registeredShortcuts.find(key);
53 if (it != _registeredShortcuts.end())
54 _registeredShortcuts.erase(it);
60 auto it = _registeredShortcuts.find(key);
61 if (it != _registeredShortcuts.end())
63 CORE_DEBUG(
"Processing " << (*it).second.description);
64 (*it).second.functor();
69 std::function<
void()> functor)
71 if (_registeredSpecialKeys.find(key) != _registeredSpecialKeys.end())
73 std::stringstream message;
74 message << int(key) <<
" is already registered";
80 _registeredSpecialKeys[key] = shortcutInformation;
87 auto it = _registeredSpecialKeys.find(key);
88 if (it != _registeredSpecialKeys.end())
89 _registeredSpecialKeys.erase(it);
95 auto it = _registeredSpecialKeys.find(key);
96 if (it != _registeredSpecialKeys.end())
98 CORE_INFO(
"Processing " << (*it).second.description);
99 (*it).second.functor();
103 void KeyboardHandler::_buildHelp()
105 _helpStrings.clear();
107 const auto specialKeyToString = [](
const SpecialKey key)
124 for (
const auto& registeredShortcut : _registeredShortcuts)
126 std::stringstream ss;
127 ss <<
"'" << registeredShortcut.first <<
"' " << registeredShortcut.second.description;
128 _helpStrings.push_back(ss.str());
130 for (
const auto& registeredShortcut : _registeredSpecialKeys)
132 std::stringstream ss;
133 ss <<
"'" << specialKeyToString(registeredShortcut.first) <<
"' " << registeredShortcut.second.description;
134 _helpStrings.push_back(ss.str());
146 auto it = _registeredShortcuts.find(key);
147 if (it != _registeredShortcuts.end())
148 return (*it).second.description;
void handle(const SpecialKey key)
Handles a special key.
void registerSpecialKey(const SpecialKey key, const std::string &description, std::function< void()> functor)
Registers a special key.
void handleKeyboardShortcut(const unsigned char key)
Handles a keyboard shortcut.
const std::string getKeyboardShortcutDescription(const unsigned char key)
Returns the description of a specific keyboard shortcut.
void registerKeyboardShortcut(const unsigned char key, const std::string &description, std::function< void()> functor)
Registers a keyboard shortcut.
void unregisterKeyboardShortcut(const unsigned char key)
Unregisters a keyboard shortcut.
const std::vector< std::string > & help() const
Returns a vector of help string descriptions for all registered keyboard shortcuts and special keys.
void unregisterSpecialKey(const SpecialKey key)
Unregisters a special key.