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

37 lines
926 B
C++

#include "./KeyboardHook.h"
#include <cassert>
using namespace std;
KeyboardHook::KeyboardHook(KeyboardHookType type) : type_{type} {};
KeyboardHook::~KeyboardHook() {
if(this->_attached)
this->detach();
}
bool KeyboardHook::attach() {
assert(!this->_attached);
this->_attached = true;
return true;
}
void KeyboardHook::detach() {
assert(this->_attached);
this->_attached = false;
}
void KeyboardHook::trigger_key_event(const enum KeyEvent::type& type, const std::string &key) {
if(!this->callback_event) return;
auto event = make_shared<KeyboardHook::KeyEvent>();
event->type = type;
event->code = key;
event->key_alt = this->map_special[KeyType::KEY_ALT] > 0;
event->key_ctrl = this->map_special[KeyType::KEY_CTRL] > 0;
event->key_windows = this->map_special[KeyType::KEY_WIN] > 0;
event->key_shift = this->map_special[KeyType::KEY_SHIFT] > 0;
this->callback_event(event);
}