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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
use timing;
use defs::{Slide, Vector};
pub type Key = Button;
pub type KeyCode = u16;
pub type KeyValue = i32;
pub mod modifier {
pub type ModifierType = u16;
pub const NONE: ModifierType = 0b00000000;
pub const LCTL: ModifierType = 0b00000001;
pub const RCTL: ModifierType = 0b00000010;
pub const LSHF: ModifierType = 0b00000100;
pub const RSHF: ModifierType = 0b00001000;
pub const LALT: ModifierType = 0b00010000;
pub const RALT: ModifierType = 0b00100000;
pub const LMTA: ModifierType = 0b01000000;
pub const RMTA: ModifierType = 0b10000000;
pub const CTRL: ModifierType = LCTL | RCTL;
pub const SHIFT: ModifierType = LSHF | RSHF;
pub const ALT: ModifierType = LALT | RALT;
pub const META: ModifierType = LMTA | RMTA;
}
#[derive(PartialEq)]
pub enum KeyCatchResult {
Caught,
Passed,
}
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub struct Binding {
code: KeyCode,
modifiers: modifier::ModifierType,
}
impl Binding {
pub fn new(code: i32, modifiers: modifier::ModifierType) -> Self {
Binding {
code: code as KeyCode,
modifiers: modifiers,
}
}
pub fn create(code: KeyCode, modifiers: modifier::ModifierType) -> Self {
Binding {
code: code,
modifiers: modifiers,
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct Button {
pub code: u16,
pub value: i32,
pub time: timing::Milliseconds,
}
impl Button {
pub fn new(code: u16, value: i32, milliseconds: timing::Milliseconds) -> Self {
Button {
code: code,
value: value,
time: milliseconds,
}
}
pub fn new_now(code: u16, value: i32) -> Self {
Button {
code: code,
value: value,
time: timing::Milliseconds::now(),
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct Axis {
pub discrete: Vector,
pub continuous: Slide,
pub time: timing::Milliseconds,
}
impl Axis {
pub fn new(discrete: Vector, continuous: Slide, time: timing::Milliseconds) -> Self {
Axis {
discrete: discrete,
continuous: continuous,
time: time,
}
}
pub fn new_now(discrete: Vector, continuous: Slide) -> Self {
Axis {
discrete: discrete,
continuous: continuous,
time: timing::Milliseconds::now(),
}
}
}
pub trait InputHandling: Send {
fn catch_key(&mut self,
code: KeyCode,
value: KeyValue,
modifiers: modifier::ModifierType)
-> KeyCatchResult;
fn duplicate(&self) -> Box<InputHandling>;
}
pub trait InputForwarding: Send {
fn emit_key(&mut self, code: u16, value: i32);
fn emit_motion(&mut self, x: isize, y: isize);
fn emit_position(&mut self, x: Option<isize>, y: Option<isize>);
fn emit_button(&mut self, code: u16, value: i32);
fn emit_axis(&mut self, horizontal: isize, vertical: isize);
fn emit_position_reset(&mut self);
fn emit_system_activity_event(&mut self);
fn duplicate(&self) -> Box<InputForwarding>;
}