forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget_state.h
44 lines (41 loc) · 891 Bytes
/
target_state.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <deque>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <chrono>
#include "shortcut_guide.h"
struct KeyEvent
{
bool key_down;
unsigned vk_code;
};
class TargetState
{
public:
TargetState(int ms_delay);
bool signal_event(unsigned vk_code, bool key_down);
void was_hiden();
void exit();
void set_delay(int ms_delay);
private:
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;
};