mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-24 12:43:20 +03:00
Compare commits
1 Commits
fix-key-re
...
log-keypre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0f73ea7ba |
@@ -160,6 +160,7 @@ impl InputCapture {
|
|||||||
_ => self.pressed_keys.remove(&scancode),
|
_ => self.pressed_keys.remove(&scancode),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
log::info!("pressed keys: {:?}", self.pressed_keys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,13 +217,15 @@ impl InputEmulation {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if state == 0 {
|
let ret = if state == 0 {
|
||||||
// currently pressed => can release
|
// currently pressed => can release
|
||||||
pressed_keys.remove(&key)
|
pressed_keys.remove(&key)
|
||||||
} else {
|
} else {
|
||||||
// currently not pressed => can press
|
// currently not pressed => can press
|
||||||
pressed_keys.insert(key)
|
pressed_keys.insert(key)
|
||||||
}
|
};
|
||||||
|
log::info!("client {handle}: pressed keys: {:?}", pressed_keys);
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ use core_graphics::event_source::{CGEventSource, CGEventSourceStateID};
|
|||||||
use input_event::{Event, KeyboardEvent, PointerEvent};
|
use input_event::{Event, KeyboardEvent, PointerEvent};
|
||||||
use keycode::{KeyMap, KeyMapping};
|
use keycode::{KeyMap, KeyMapping};
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
use std::sync::Arc;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::{sync::Notify, task::JoinHandle};
|
use tokio::task::AbortHandle;
|
||||||
|
|
||||||
use super::error::MacOSEmulationCreationError;
|
use super::error::MacOSEmulationCreationError;
|
||||||
|
|
||||||
@@ -22,9 +21,8 @@ const DEFAULT_REPEAT_INTERVAL: Duration = Duration::from_millis(32);
|
|||||||
|
|
||||||
pub(crate) struct MacOSEmulation {
|
pub(crate) struct MacOSEmulation {
|
||||||
event_source: CGEventSource,
|
event_source: CGEventSource,
|
||||||
repeat_task: Option<JoinHandle<()>>,
|
repeat_task: Option<AbortHandle>,
|
||||||
button_state: ButtonState,
|
button_state: ButtonState,
|
||||||
notify_repeat_task: Arc<Notify>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ButtonState {
|
struct ButtonState {
|
||||||
@@ -70,7 +68,6 @@ impl MacOSEmulation {
|
|||||||
event_source,
|
event_source,
|
||||||
button_state,
|
button_state,
|
||||||
repeat_task: None,
|
repeat_task: None,
|
||||||
notify_repeat_task: Arc::new(Notify::new()),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,33 +79,20 @@ impl MacOSEmulation {
|
|||||||
async fn spawn_repeat_task(&mut self, key: u16) {
|
async fn spawn_repeat_task(&mut self, key: u16) {
|
||||||
// there can only be one repeating key and it's
|
// there can only be one repeating key and it's
|
||||||
// always the last to be pressed
|
// always the last to be pressed
|
||||||
self.cancel_repeat_task().await;
|
self.kill_repeat_task();
|
||||||
let event_source = self.event_source.clone();
|
let event_source = self.event_source.clone();
|
||||||
let notify = self.notify_repeat_task.clone();
|
|
||||||
let repeat_task = tokio::task::spawn_local(async move {
|
let repeat_task = tokio::task::spawn_local(async move {
|
||||||
let stop = tokio::select! {
|
tokio::time::sleep(DEFAULT_REPEAT_DELAY).await;
|
||||||
_ = tokio::time::sleep(DEFAULT_REPEAT_DELAY) => false,
|
|
||||||
_ = notify.notified() => true,
|
|
||||||
};
|
|
||||||
if !stop {
|
|
||||||
loop {
|
loop {
|
||||||
key_event(event_source.clone(), key, 1);
|
key_event(event_source.clone(), key, 1);
|
||||||
tokio::select! {
|
tokio::time::sleep(DEFAULT_REPEAT_INTERVAL).await;
|
||||||
_ = tokio::time::sleep(DEFAULT_REPEAT_INTERVAL) => {},
|
|
||||||
_ = notify.notified() => break,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
// release key when cancelled
|
|
||||||
key_event(event_source.clone(), key, 0);
|
|
||||||
});
|
});
|
||||||
self.repeat_task = Some(repeat_task);
|
self.repeat_task = Some(repeat_task.abort_handle());
|
||||||
}
|
}
|
||||||
|
fn kill_repeat_task(&mut self) {
|
||||||
async fn cancel_repeat_task(&mut self) {
|
|
||||||
if let Some(task) = self.repeat_task.take() {
|
if let Some(task) = self.repeat_task.take() {
|
||||||
self.notify_repeat_task.notify_waiters();
|
task.abort();
|
||||||
let _ = task.await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,7 +346,7 @@ impl Emulation for MacOSEmulation {
|
|||||||
match state {
|
match state {
|
||||||
// pressed
|
// pressed
|
||||||
1 => self.spawn_repeat_task(code).await,
|
1 => self.spawn_repeat_task(code).await,
|
||||||
_ => self.cancel_repeat_task().await,
|
_ => self.kill_repeat_task(),
|
||||||
}
|
}
|
||||||
key_event(self.event_source.clone(), code, state)
|
key_event(self.event_source.clone(), code, state)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user