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

65 lines
1.2 KiB
C
Raw Normal View History

2019-10-26 01:51:40 +02:00
#pragma once
2021-02-08 16:10:15 +00:00
#include <string>
2019-10-26 01:51:40 +02:00
#include <functional>
#include <thread>
#include <map>
enum struct KeyboardHookType {
X11,
2020-08-23 11:35:52 +02:00
RAW_INPUT
};
2019-10-26 01:51:40 +02:00
class KeyboardHook {
public:
typedef unsigned int KeyID;
enum struct KeyType {
KEY_UNKNOWN,
KEY_NORMAL,
KEY_SHIFT,
KEY_ALT,
KEY_WIN,
KEY_CTRL
2019-10-26 01:51:40 +02:00
};
struct KeyEvent {
enum type {
PRESS,
RELEASE,
TYPE
};
type type;
std::string key;
std::string code;
bool key_ctrl;
bool key_windows;
bool key_shift;
bool key_alt;
};
typedef std::function<void(const std::shared_ptr<KeyEvent>& /* event */)> callback_event_t;
2020-06-13 17:21:29 +02:00
explicit KeyboardHook(KeyboardHookType);
2019-10-26 01:51:40 +02:00
virtual ~KeyboardHook();
[[nodiscard]] inline KeyboardHookType type() const { return this->type_; }
[[nodiscard]] virtual bool keytype_supported() const = 0;
[[nodiscard]] virtual bool attach();
2020-08-23 21:52:57 +02:00
[[nodiscard]] inline bool attached() const { return this->attached_; }
virtual void detach();
2019-10-26 01:51:40 +02:00
2020-04-25 12:48:44 +02:00
void trigger_key_event(const enum KeyEvent::type&, const std::string& /* key */);
2019-10-26 01:51:40 +02:00
callback_event_t callback_event;
protected:
const KeyboardHookType type_;
2019-10-26 01:51:40 +02:00
std::map<KeyID, bool> map_key;
std::map<KeyType, KeyID> map_special;
2019-10-26 01:51:40 +02:00
2020-08-23 21:52:57 +02:00
bool attached_ = false;
2021-02-08 16:10:15 +00:00
};