2020-05-01 17:37:18 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "./KeyboardHook.h"
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
namespace hooks {
|
|
|
|
extern KeyboardHook::KeyType key_type_from_vk(DWORD vk_code);
|
|
|
|
extern std::string key_string_from_vk(DWORD code, bool extended);
|
|
|
|
extern std::string key_string_from_sc(USHORT code);
|
|
|
|
|
|
|
|
class Win32RawHook : public KeyboardHook {
|
|
|
|
public:
|
|
|
|
Win32RawHook();
|
2020-08-23 21:52:57 +02:00
|
|
|
~Win32RawHook() override;
|
2020-05-01 17:37:18 +02:00
|
|
|
|
|
|
|
bool attach() override;
|
|
|
|
void detach() override;
|
|
|
|
|
2020-08-23 11:35:52 +02:00
|
|
|
[[nodiscard]] bool keytype_supported() const override { return true; }
|
2020-05-01 17:37:18 +02:00
|
|
|
private:
|
|
|
|
static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
|
|
|
|
|
2020-08-23 21:52:57 +02:00
|
|
|
void do_detach();
|
|
|
|
|
2020-08-23 11:35:52 +02:00
|
|
|
std::thread window_thread;
|
|
|
|
void window_loop();
|
2020-05-01 17:37:18 +02:00
|
|
|
|
|
|
|
enum struct WorkerStatus {
|
|
|
|
STOPPED,
|
|
|
|
DIED,
|
|
|
|
|
|
|
|
INITIALIZING,
|
|
|
|
RUNNING
|
|
|
|
};
|
|
|
|
|
|
|
|
bool wactive{false};
|
|
|
|
WorkerStatus wstatus{WorkerStatus::STOPPED};
|
|
|
|
std::mutex wstatus_mutex{};
|
|
|
|
std::condition_variable wstatus_changed_cv{};
|
|
|
|
std::string worker_died_reason{};
|
|
|
|
|
|
|
|
void set_wstatus(WorkerStatus);
|
|
|
|
void handle_raw_input(RAWINPUT&);
|
|
|
|
|
2020-08-23 11:35:52 +02:00
|
|
|
HWND hwnd{nullptr};
|
2020-05-01 17:37:18 +02:00
|
|
|
};
|
|
|
|
}
|