2019-09-05 00:26:26 +08:00
|
|
|
#pragma once
|
|
|
|
#include <deque>
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <chrono>
|
|
|
|
#include "shortcut_guide.h"
|
|
|
|
|
2019-12-06 19:07:54 +08:00
|
|
|
struct KeyEvent
|
|
|
|
{
|
|
|
|
bool key_down;
|
|
|
|
unsigned vk_code;
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|
|
|
|
|
2019-12-06 19:07:54 +08:00
|
|
|
class TargetState
|
|
|
|
{
|
2019-09-05 00:26:26 +08:00
|
|
|
public:
|
2019-12-06 19:07:54 +08:00
|
|
|
TargetState(int ms_delay);
|
|
|
|
bool signal_event(unsigned vk_code, bool key_down);
|
|
|
|
void was_hiden();
|
|
|
|
void exit();
|
|
|
|
void set_delay(int ms_delay);
|
|
|
|
|
2019-09-05 00:26:26 +08:00
|
|
|
private:
|
2019-12-06 19:07:54 +08:00
|
|
|
KeyEvent next();
|
|
|
|
void handle_hidden();
|
|
|
|
void handle_timeout();
|
|
|
|
void handle_shown();
|
|
|
|
void thread_proc();
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable cv;
|
|
|
|
std::chrono::system_clock::time_point winkey_timestamp, singnal_timestamp;
|
|
|
|
std::chrono::milliseconds delay;
|
|
|
|
std::deque<KeyEvent> events;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
Hidden,
|
|
|
|
Timeout,
|
|
|
|
Shown,
|
|
|
|
Exiting
|
|
|
|
} state = Hidden;
|
|
|
|
bool key_was_pressed = false;
|
|
|
|
std::thread thread;
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|