Skip to content

Commit

Permalink
fix(clafrica): update special key
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed Oct 19, 2023
1 parent bcd189e commit 1ecba40
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,26 @@ pub fn run(config: Config, mut frontend: impl Frontend) -> Result<(), Box<dyn er
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let mut idle = false;
let mut pause_counter = 0;
let mut is_ctrl_released = false;

rdev::listen(move |event| {
idle = match event.event_type {
EventType::KeyPress(E_Key::Pause) => true,
EventType::KeyRelease(E_Key::Pause) => false,
EventType::KeyPress(E_Key::ControlLeft) => idle,
EventType::KeyRelease(E_Key::ControlLeft) => {
pause_counter += 1;

if pause_counter != 0 && pause_counter % 2 == 0 {
pause_counter = 0;
!idle
} else {
idle
}
EventType::KeyPress(E_Key::ControlLeft | E_Key::ControlRight) => {
is_ctrl_released = false;
idle
}
EventType::KeyRelease(E_Key::ControlLeft | E_Key::ControlRight)
if is_ctrl_released =>
{
!idle
}
_ => {
pause_counter = 0;
EventType::KeyRelease(E_Key::ControlLeft | E_Key::ControlRight) => {
is_ctrl_released = true;
idle
}
_ => idle,
};
if !idle {
tx.send(event)
Expand All @@ -91,7 +90,7 @@ pub fn run(config: Config, mut frontend: impl Frontend) -> Result<(), Box<dyn er
EventType::KeyRelease(E_Key::ShiftLeft) if is_special_pressed => {
frontend.previous_predicate()
}
EventType::KeyRelease(E_Key::ControlRight) if is_special_pressed => {
EventType::KeyRelease(E_Key::Space) if is_special_pressed => {
rdev::simulate(&EventType::KeyRelease(E_Key::ControlLeft))
.expect("We couldn't cancel the special function key");
is_special_pressed = false;
Expand Down Expand Up @@ -261,9 +260,16 @@ mod tests {
output!(textfield, LIMIT);

// We verify that the pause/resume works as expected
input!(ControlLeft ControlLeft, typing_speed_ms);
rdev::simulate(&KeyPress(ControlLeft)).unwrap();
rdev::simulate(&KeyPress(ControlRight)).unwrap();
rdev::simulate(&KeyRelease(ControlRight)).unwrap();
rdev::simulate(&KeyRelease(ControlLeft)).unwrap();
input!(KeyU KeyU, typing_speed_ms);
input!(ControlLeft ControlLeft, typing_speed_ms);

rdev::simulate(&KeyPress(ControlLeft)).unwrap();
rdev::simulate(&KeyPress(ControlRight)).unwrap();
rdev::simulate(&KeyRelease(ControlRight)).unwrap();
rdev::simulate(&KeyRelease(ControlLeft)).unwrap();
input!(KeyA KeyF, typing_speed_ms);
output!(textfield, format!("{LIMIT}uuɑ"));
input!(Escape, typing_speed_ms);
Expand Down Expand Up @@ -291,7 +297,7 @@ mod tests {

input!(KeyL KeyL, typing_speed_ms);
rdev::simulate(&KeyPress(ControlLeft)).unwrap();
input!(ControlRight, typing_speed_ms);
input!(Space, typing_speed_ms);
rdev::simulate(&KeyRelease(ControlLeft)).unwrap();
output!(textfield, format!("{LIMIT}uuɑαⱭⱭɑɑhihellohi"));
input!(Escape, typing_speed_ms);
Expand Down

0 comments on commit 1ecba40

Please sign in to comment.