-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No mouse move event emitted while mouse is down #136
Comments
you are right, I only can get the position when button pressed, but I can't get the position if mouse doesn't move after button released. use rdev::{listen, Button, Event, EventType};
use std::sync::{Arc, Mutex};
use std::thread::{self, spawn};
use std::time::Duration;
fn main() {
let mouse_state = Arc::new(Mutex::new(MouseState::new()));
let mouse_state_clone = Arc::clone(&mouse_state);
spawn(|| {
if let Err(error) = listen(move |event| callback(event, &mouse_state_clone)) {
println!("Error: {:?}", error)
}
});
thread::sleep(Duration::from_secs(3600));
}
#[derive(Debug)]
pub struct MouseState {
pub last_position: Option<(f64, f64)>,
}
impl MouseState {
fn new() -> Self {
MouseState {
last_position: None,
}
}
}
fn callback(event: Event, mouse_state: &Arc<Mutex<MouseState>>) {
match event.event_type {
EventType::ButtonPress(button) => {
let mouse_state = mouse_state.lock().unwrap();
if let Some(last_position) = mouse_state.last_position {
if button == Button::Left {
println!("position is :{}, {}", last_position.0, last_position.1);
}
}
}
EventType::ButtonRelease(button) => {
if button == Button::Left {
//I can't get the position if mouse doesn't move after button released.
}
}
EventType::MouseMove { x, y } => {
let mut mouse_state = mouse_state.lock().unwrap();
mouse_state.last_position = Some((x, y));
}
_ => {}
}
} |
I have pull something new for this issue, the EventType will return position when mouse button pressed or released. |
|
It's not necessary to implement this feature. |
So is there a way to get x and y when you press the mouse down. |
just get the current mouse position. |
@qzd1989 what do you mean? I didn't get it. There is no event to report mouse position when mouse is down. |
|
I made a PR #150 fixing the issue for MacOS. When mouse is pressed and moved, mouse move event is still emitted. |
When left mouse button is down, mouse move events are no longer detected.
How can this be solved?
I am trying to detect mouse movements while holding and moving a file.
The text was updated successfully, but these errors were encountered: