forked from ecraven/g13
-
Notifications
You must be signed in to change notification settings - Fork 15
/
g13_action.cpp
123 lines (103 loc) · 3.51 KB
/
g13_action.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// Created by khampf on 07-05-2020.
//
#include "g13_action.hpp"
#include "g13.hpp"
#include "g13_device.hpp"
#include "g13_manager.hpp"
// *************************************************************************
namespace G13 {
G13_Action::~G13_Action() = default;
G13_Action_Keys::G13_Action_Keys(G13_Device &keypad,
const std::string &keys_string)
: G13_Action(keypad) {
auto keydownup = Helper::split<std::vector<std::string>>(keys_string, " ");
auto keys = Helper::split<std::vector<std::string>>(keydownup[0], "+");
for (auto &key : keys) {
auto kval = G13_Manager::Instance()->FindInputKeyValue(key);
if (kval == BAD_KEY_VALUE) {
throw G13_CommandException("create action unknown key : " + key);
}
_keys.push_back(kval);
}
if (keydownup.size()>1){
auto keysup = Helper::split<std::vector<std::string>>(keydownup[1], "+");
for (auto &key : keysup) {
auto kval = G13_Manager::Instance()->FindInputKeyValue(key);
if (kval == BAD_KEY_VALUE) {
throw G13_CommandException("create action unknown key : " + key);
}
_keysup.push_back(kval);
}
}
std::vector<int> _keys_local;
std::vector<int> _keysup_local;
}
G13_Action_Keys::~G13_Action_Keys() = default;
void G13_Action_Keys::act(G13_Device &g13, bool is_down) {
if (is_down) {
for (int &_key : _keys) {
g13.SendEvent(EV_KEY, _key, is_down);
G13_LOG(log4cpp::Priority::DEBUG << "sending KEY DOWN " << _key);
}
if (!_keysup.empty()) for (int i = _keys.size() - 1; i >= 0; i--) {
g13.SendEvent(EV_KEY, _keys[i], !is_down);
G13_LOG(log4cpp::Priority::DEBUG << "sending KEY UP " << _keys[i]);
}
} else {
if(_keysup.empty()) for (int i = _keys.size() - 1; i >= 0; i--) {
g13.SendEvent(EV_KEY, _keys[i], is_down);
G13_LOG(log4cpp::Priority::DEBUG << "sending KEY UP " << _keys[i]);
} else {
for (int &_key : _keysup) {
g13.SendEvent(EV_KEY, _key, !is_down);
G13_LOG(log4cpp::Priority::DEBUG << "sending KEY DOWN " << _key);
}
for (int i = _keysup.size() - 1; i >= 0; i--) {
g13.SendEvent(EV_KEY, _keysup[i], is_down);
G13_LOG(log4cpp::Priority::DEBUG << "sending KEY UP " << _keysup[i]);
}
}
}
}
void G13_Action_Keys::dump(std::ostream &out) const {
out << " SEND KEYS: ";
for (size_t i = 0; i < _keys.size(); i++) {
if (i)
out << " + ";
out << G13_Manager::Instance()->FindInputKeyName(_keys[i]);
}
}
G13_Action_PipeOut::G13_Action_PipeOut(G13_Device &keypad,
const std::string &out)
: G13_Action(keypad), _out(out + "\n") {}
G13_Action_PipeOut::~G13_Action_PipeOut() = default;
void G13_Action_PipeOut::act(G13_Device &kp, bool is_down) {
if (is_down) {
kp.OutputPipeWrite(_out);
}
}
void G13_Action_PipeOut::dump(std::ostream &o) const {
o << "WRITE PIPE : " << Helper::repr(_out);
}
G13_Action_Command::G13_Action_Command(G13_Device &keypad, std::string cmd)
: G13_Action(keypad), _cmd(std::move(cmd)) {}
G13_Action_Command::~G13_Action_Command() = default;
void G13_Action_Command::act(G13_Device &kp, bool is_down) {
if (is_down) {
keypad().Command(_cmd.c_str());
}
}
void G13_Action_Command::dump(std::ostream &o) const {
o << "COMMAND : " << Helper::repr(_cmd);
}
/*
// inlines
inline G13_Manager& G13_Action::manager() {
return m_keypad.manager();
}
*/
/*inline const G13_Manager& G13_Action::manager() const {
return m_keypad.manager();
}*/
} // namespace G13