TermOx
shortcuts.hpp
1 #ifndef TERMOX_SYSTEM_SHORTCUTS_HPP
2 #define TERMOX_SYSTEM_SHORTCUTS_HPP
3 #include <unordered_map>
4 
5 #include <signals_light/signal.hpp>
6 
7 #include <termox/system/key.hpp>
8 
9 namespace ox {
10 
12 class Shortcuts {
13  public:
15 
18  [[nodiscard]] static auto add_shortcut(Key k) -> sl::Signal<void()>&;
19 
21 
22  static void remove_shortcut(Key k);
23 
25  static void clear();
26 
28 
29  static auto send_key(Key k) -> bool;
30 
32  static void disable_all();
33 
35  static void enable_all();
36 
37  private:
38  using Map_t = std::unordered_map<Key, sl::Signal<void()>>;
39  inline static Map_t shortcuts_;
40  inline static bool enabled_ = true;
41 };
42 
43 } // namespace ox
44 #endif // TERMOX_SYSTEM_SHORTCUTS_HPP
Provides functions for defining global keyboard shortcuts.
Definition: shortcuts.hpp:12
static void remove_shortcut(Key k)
Stop key and its associated Signal from being called.
Definition: shortcuts.cpp:16
static void enable_all()
Allow all shortcuts to be processed, on by default.
Definition: shortcuts.cpp:31
static auto send_key(Key k) -> bool
Call on the associated Signal if key exists as a shortcut.
Definition: shortcuts.cpp:20
static void disable_all()
Stop all shortcuts from working.
Definition: shortcuts.cpp:29
static void clear()
Remove all shortcuts from the system.
Definition: shortcuts.cpp:18
static auto add_shortcut(Key k) -> sl::Signal< void()> &
Add an entry for the key, returning a Signal to connect an action to.
Definition: shortcuts.cpp:9