KeyboardManager.h
1 #pragma once 2 #include <common/hooks/LowlevelKeyboardEvent.h> 3 #include <common/utils/EventWaiter.h> 4 #include <keyboardmanager/common/Input.h> 5 #include "State.h" 6 7 class KeyboardManager 8 { 9 public: 10 static const inline DWORD StartHookMessageID = WM_APP + 1; 11 12 // Constructor 13 KeyboardManager(); 14 15 ~KeyboardManager() 16 { 17 if (editorIsRunningEvent) 18 { 19 CloseHandle(editorIsRunningEvent); 20 } 21 } 22 23 void StartLowlevelKeyboardHook(); 24 void StopLowlevelKeyboardHook(); 25 26 bool HasRegisteredRemappings() const; 27 28 private: 29 // Returns whether there are any remappings available without waiting for settings to load 30 bool HasRegisteredRemappingsUnchecked() const; 31 32 // Contains the non localized module name 33 std::wstring moduleName = KeyboardManagerConstants::ModuleName; 34 35 // Low level hook handles 36 static HHOOK hookHandle; 37 38 // Required for Unhook in old versions of Windows 39 static HHOOK hookHandleCopy; 40 41 // Static pointer to the current KeyboardManager object required for accessing the HandleKeyboardHookEvent function in the hook procedure 42 // Only global or static variables can be accessed in a hook procedure CALLBACK 43 static KeyboardManager* keyboardManagerObjectPtr; 44 45 // Variable which stores all the state information to be shared between the UI and back-end 46 State state; 47 48 // Object of class which implements InputInterface. Required for calling library functions while enabling testing 49 KeyboardManagerInput::Input inputHandler; 50 51 // Auto reset event for waiting for settings changes. The event is signaled when settings are changed 52 EventWaiter settingsEventWaiter; 53 54 std::atomic_bool loadingSettings = false; 55 56 HANDLE editorIsRunningEvent = nullptr; 57 58 // Hook procedure definition 59 static LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam); 60 61 // Load settings from the file. 62 void LoadSettings(); 63 64 // Function called by the hook procedure to handle the events. This is the starting point function for remapping 65 intptr_t HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept; 66 };