/ src / runner / centralized_hotkeys.h
centralized_hotkeys.h
 1  #pragma once
 2  #include <Windows.h>
 3  #include <functional>
 4  
 5  namespace CentralizedHotkeys
 6  {
 7      struct Action
 8      {
 9          std::wstring moduleName;
10          std::function<void(WORD, WORD)> action;
11  
12          Action(std::wstring moduleName = L"", std::function<void(WORD, WORD)> action = ([](WORD /*modifiersMask*/, WORD /*vkCode*/) {}))
13          {
14              this->moduleName = moduleName;
15              this->action = action;
16          }
17      };
18  
19      struct Shortcut
20      {
21          WORD modifiersMask;
22          WORD vkCode;
23          int hotkeyID;
24  
25          Shortcut(WORD modifiersMask = 0, WORD vkCode = 0, const int hotkeyID = 0)
26          {
27              this->modifiersMask = modifiersMask;
28              this->vkCode = vkCode;
29              this->hotkeyID = hotkeyID;
30          }
31  
32          bool operator<(const Shortcut& key) const
33          {
34              return std::pair<WORD, WORD>{ this->modifiersMask, this->vkCode } < std::pair<WORD, WORD>{ key.modifiersMask, key.vkCode };
35          }
36      };
37  
38      std::wstring ToWstring(const Shortcut& shortcut);
39  
40      bool AddHotkeyAction(Shortcut shortcut, Action action);
41  
42      void UnregisterHotkeysForModule(std::wstring moduleName);
43  
44      void PopulateHotkey(Shortcut shortcut);
45  
46      void RegisterWindow(HWND hwnd);
47  }