Skip to content

Commit

Permalink
merge commit
Browse files Browse the repository at this point in the history
  • Loading branch information
medzernik committed Feb 3, 2023
1 parent a0cbb54 commit 43cfc0d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions wooting-macro-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ fn keypress_executor_sender(mut rchan_execute: Receiver<rdev::EventType>) {
}
}

async fn lift_keys(pressed_events: Vec<u32>, channel_sender: Sender<rdev::EventType>) {
for x in pressed_events {
channel_sender
.send(rdev::EventType::KeyRelease(SCANCODE_TO_RDEV[&x]))
.await
.unwrap();
}
}

/// A more efficient way using hashtable to check whether the trigger keys match the macro.
///
/// `pressed_events` - the keys pressed in HID format (use the conversion HID hashtable to get the number).
Expand Down Expand Up @@ -327,6 +336,12 @@ fn check_macro_execution_efficiently(

let channel_clone = channel_sender.clone();
let macro_clone = macros.clone();
let channel_clone2 = channel_sender.clone();
let pressed_events2 = pressed_events.clone();
task::spawn(async move {

lift_keys(pressed_events2, channel_clone2).await;
});

task::spawn(async move {
execute_macro(macro_clone, channel_clone).await;
Expand All @@ -347,8 +362,15 @@ fn check_macro_execution_efficiently(

let channel_clone = channel_sender.clone();
let macro_clone = macros.clone();
let channel_clone2 = channel_sender.clone();
let pressed_events2 = pressed_events.clone();
task::spawn(async move {

lift_keys(pressed_events2, channel_clone2).await;
});

task::spawn(async move {
tokio::time::sleep(time::Duration::from_millis(3)).await;
execute_macro(macro_clone, channel_clone).await;
});
output = true;
Expand Down

0 comments on commit 43cfc0d

Please sign in to comment.