kanata_state_machine/oskbd/
mod.rs1#[cfg(any(target_os = "linux", target_os = "android"))]
4mod linux;
5#[cfg(any(target_os = "linux", target_os = "android"))]
6pub use linux::*;
7
8#[cfg(target_os = "windows")]
9mod windows;
10#[cfg(target_os = "windows")]
11pub use windows::*;
12
13#[cfg(target_os = "macos")]
14mod macos;
15#[cfg(target_os = "macos")]
16pub use macos::*;
17
18#[cfg(any(
19 all(
20 not(feature = "simulated_input"),
21 feature = "simulated_output",
22 not(feature = "passthru_ahk")
23 ),
24 all(
25 feature = "simulated_input",
26 not(feature = "simulated_output"),
27 not(feature = "passthru_ahk")
28 )
29))]
30mod simulated; #[cfg(any(
32 all(
33 not(feature = "simulated_input"),
34 feature = "simulated_output",
35 not(feature = "passthru_ahk")
36 ),
37 all(
38 feature = "simulated_input",
39 not(feature = "simulated_output"),
40 not(feature = "passthru_ahk")
41 )
42))]
43pub use simulated::*;
44#[cfg(any(
45 all(feature = "simulated_input", feature = "simulated_output"),
46 all(
47 feature = "simulated_input",
48 feature = "simulated_output",
49 feature = "passthru_ahk"
50 ),
51))]
52mod sim_passthru; #[cfg(any(
54 all(feature = "simulated_input", feature = "simulated_output"),
55 all(
56 feature = "simulated_input",
57 feature = "simulated_output",
58 feature = "passthru_ahk"
59 ),
60))]
61pub use sim_passthru::*;
62
63pub const HI_RES_SCROLL_UNITS_IN_LO_RES: u16 = 120;
64
65#[derive(Copy, Clone, Debug, PartialEq, Eq)]
68pub enum KeyValue {
69 Release = 0,
70 Press = 1,
71 Repeat = 2,
72 Tap,
73 WakeUp,
74}
75
76impl From<i32> for KeyValue {
77 fn from(item: i32) -> Self {
78 match item {
79 0 => Self::Release,
80 1 => Self::Press,
81 2 => Self::Repeat,
82 _ => unreachable!(),
83 }
84 }
85}
86
87impl From<bool> for KeyValue {
88 fn from(up: bool) -> Self {
89 match up {
90 true => Self::Release,
91 false => Self::Press,
92 }
93 }
94}
95
96impl From<KeyValue> for bool {
97 fn from(val: KeyValue) -> Self {
98 matches!(val, KeyValue::Release)
99 }
100}
101
102use kanata_parser::keys::OsCode;
103
104#[derive(Clone, Copy)]
105pub struct KeyEvent {
106 pub code: OsCode,
107 pub value: KeyValue,
108}
109
110#[allow(dead_code, unused)]
111impl KeyEvent {
112 pub fn new(code: OsCode, value: KeyValue) -> Self {
113 Self { code, value }
114 }
115}
116
117use core::fmt;
118impl fmt::Display for KeyEvent {
119 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120 use kanata_keyberon::key_code::KeyCode;
121 let direction = match self.value {
122 KeyValue::Press => "↓",
123 KeyValue::Release => "↑",
124 KeyValue::Repeat => "⟳",
125 KeyValue::Tap => "↕",
126 KeyValue::WakeUp => "!",
127 };
128 let key_name = KeyCode::from(self.code);
129 write!(f, "{direction}{key_name:?}")
130 }
131}
132
133impl fmt::Debug for KeyEvent {
134 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
135 f.debug_struct("KeyEvent")
136 .field(
137 "code",
138 &format_args!("{:?} ({})", self.code, self.code.as_u16()),
139 )
140 .field("value", &self.value)
141 .finish()
142 }
143}