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
use crate::{
free_launch::free_launch::{Actions, FreeLaunch},
util::egui_to_keybinds_key,
};
use keybinds::{KeyInput, Mods};
use tracing::debug;
impl FreeLaunch {
#[must_use]
pub(crate) fn key_events_to_actions(&mut self, ctx: &egui::Context) -> Vec<Actions> {
let mut actions: Vec<Actions> = Default::default();
ctx.input(|input| {
for event in input.events.iter() {
if let Some(action) = match event {
egui::Event::Key {
key, // we'll use the key after it's been translated via the keymap
physical_key: _, // this is the unmapped key from the keyboard
pressed, // we can use this to respond to keys on press or release
repeat, // this will allow us to ignore key repeat events
modifiers,
} => {
if *pressed || *repeat {
continue;
}
debug!("processing key event: {:#?}", event);
// collect modifier keys
let mut mods = Mods::NONE;
if modifiers.ctrl {
mods.insert(Mods::CTRL);
}
// this only works on macOS machines
if modifiers.mac_cmd {
mods.insert(Mods::CMD);
}
if modifiers.alt {
mods.insert(Mods::ALT);
}
if modifiers.shift {
mods.insert(Mods::SHIFT);
}
// there doesn't seem to be a way to detect super in egui: https://github.com/emilk/egui/issues/5604
// convert egui key to a keybinds key since that is not natively supported yet
let key_input: KeyInput = KeyInput::new(egui_to_keybinds_key(key), mods);
debug!("dispatching key: {:#?}", key_input);
// feed the key into keybinds dispatch to see if anything matches
self.keybinds.dispatch(key_input)
}
// TODO do we want to act on text events? Probably not.
// egui::Event::Text(_) => todo!(),
// ignore other event types
_ => None,
} {
actions.push(*action);
} else {
debug!("skipping action...")
};
}
});
actions
}
}