TeaSpeak-Client/native/ppt/src/Win32KeyboardHook.h

68 lines
1.9 KiB
C
Raw Normal View History

#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 Win32SystemHook : public KeyboardHook {
public:
Win32SystemHook();
bool attach() override;
void detach() override;
bool keytype_supported() const override { return true; }
private:
static LRESULT CALLBACK _keyboard_hook_callback(int, WPARAM, LPARAM);
static LRESULT CALLBACK _mouse_hook_callback(int, WPARAM, LPARAM);
HHOOK keyboad_hook_id{nullptr};
bool keyboard_hook_callback(int, WPARAM, LPARAM);
HHOOK mouse_hook_id{nullptr};
bool mouse_hook_callback(int, WPARAM, LPARAM);
bool active{false};
std::thread poll_thread;
void poll_events();
};
class Win32RawHook : public KeyboardHook {
public:
Win32RawHook();
bool attach() override;
void detach() override;
bool keytype_supported() const override { return true; }
private:
static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
std::thread wthread;
void wloop();
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&);
HWND hwnd{0};
};
}