-
Notifications
You must be signed in to change notification settings - Fork 1
/
HotkeyEngine.h
47 lines (40 loc) · 1.71 KB
/
HotkeyEngine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef HOTKEYENGINE_H
#define HOTKEYENGINE_H
#include <memory>
#include <functional>
#include <windows.h>
#ifdef _WIN64
#define HKECALL
#else
#define HKECALL __cdecl
#endif
//As with TskbrNtfAreaIcon this is also singleton class
//Thoughts are the same - things are pretty incapsulated but only one instance is allowed to keep things simple giving customization options
class HotkeyEngine {
public:
typedef bool (HKECALL *KeyPressFn)(LPARAM event_param, WPARAM llkh_msg, KBDLLHOOKSTRUCT* llkh_struct);
private:
static std::unique_ptr<HotkeyEngine> instance;
static LPARAM event_param; //Custom value to be passed to the OnKeyPress event handler
static KeyPressFn OnKeyPress; //Keyboard event is passed to OnKeyPress - it should return true if event shouldn't be passed further (to other keyboard handlers) and false otherwise
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
static DWORD WINAPI ThreadProc(LPVOID lpParameter);
bool running;
HANDLE hook_thread_handle;
DWORD hook_thread_id;
size_t stack_commit;
HotkeyEngine();
public:
static HotkeyEngine* MakeInstance();
bool IsRunning();
bool Stop();
bool Start();
bool Set(LPARAM event_param, KeyPressFn OnKeyPress, size_t stack_commit=0);
bool StartNew(LPARAM event_param, KeyPressFn OnKeyPress, size_t stack_commit=0);
~HotkeyEngine();
HotkeyEngine(const HotkeyEngine&)=delete; //Get rid of default copy constructor
HotkeyEngine& operator=(const HotkeyEngine&)=delete; //Get rid of default copy assignment operator
HotkeyEngine(const HotkeyEngine&&)=delete; //Get rid of default move constructor
HotkeyEngine& operator=(const HotkeyEngine&&)=delete; //Get rid of default move assignment operator
};
#endif //HOTKEYENGINE_H