2021-04-26 22:01:38 +03:00
|
|
|
#pragma once
|
2021-05-07 11:16:31 +03:00
|
|
|
#include <common/hooks/LowlevelKeyboardEvent.h>
|
2021-04-26 22:01:38 +03:00
|
|
|
#include <common/utils/EventWaiter.h>
|
|
|
|
|
#include <keyboardmanager/common/Input.h>
|
2021-05-07 11:16:31 +03:00
|
|
|
#include "State.h"
|
2021-04-26 22:01:38 +03:00
|
|
|
|
|
|
|
|
class KeyboardManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// Constructor
|
|
|
|
|
KeyboardManager();
|
2021-05-10 01:39:54 -07:00
|
|
|
|
|
|
|
|
~KeyboardManager()
|
|
|
|
|
{
|
|
|
|
|
if (editorIsRunningEvent)
|
|
|
|
|
{
|
|
|
|
|
CloseHandle(editorIsRunningEvent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 22:01:38 +03:00
|
|
|
void StartLowlevelKeyboardHook();
|
|
|
|
|
void StopLowlevelKeyboardHook();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Contains the non localized module name
|
|
|
|
|
std::wstring moduleName = KeyboardManagerConstants::ModuleName;
|
|
|
|
|
|
|
|
|
|
// Low level hook handles
|
|
|
|
|
static HHOOK hookHandle;
|
|
|
|
|
|
|
|
|
|
// Required for Unhook in old versions of Windows
|
|
|
|
|
static HHOOK hookHandleCopy;
|
|
|
|
|
|
|
|
|
|
// Static pointer to the current KeyboardManager object required for accessing the HandleKeyboardHookEvent function in the hook procedure
|
|
|
|
|
// Only global or static variables can be accessed in a hook procedure CALLBACK
|
|
|
|
|
static KeyboardManager* keyboardManagerObjectPtr;
|
|
|
|
|
|
|
|
|
|
// Variable which stores all the state information to be shared between the UI and back-end
|
2021-05-07 11:16:31 +03:00
|
|
|
State state;
|
2021-04-26 22:01:38 +03:00
|
|
|
|
|
|
|
|
// Object of class which implements InputInterface. Required for calling library functions while enabling testing
|
|
|
|
|
KeyboardManagerInput::Input inputHandler;
|
|
|
|
|
|
|
|
|
|
// Auto reset event for waiting for settings changes. The event is signaled when settings are changed
|
|
|
|
|
EventWaiter settingsEventWaiter;
|
|
|
|
|
|
|
|
|
|
std::atomic_bool loadingSettings = false;
|
|
|
|
|
|
2021-05-10 01:39:54 -07:00
|
|
|
HANDLE editorIsRunningEvent = nullptr;
|
|
|
|
|
|
2021-04-26 22:01:38 +03:00
|
|
|
// Hook procedure definition
|
|
|
|
|
static LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
|
|
|
|
|
// Load settings from the file.
|
|
|
|
|
void LoadSettings();
|
|
|
|
|
|
|
|
|
|
// Function called by the hook procedure to handle the events. This is the starting point function for remapping
|
|
|
|
|
intptr_t HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept;
|
|
|
|
|
};
|