Skip to content
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

Open
HuakunShen opened this issue Jun 24, 2024 · 8 comments
Open

No mouse move event emitted while mouse is down #136

HuakunShen opened this issue Jun 24, 2024 · 8 comments

Comments

@HuakunShen
Copy link

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.

@qzd1989
Copy link

qzd1989 commented Jun 30, 2024

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));
        }
        _ => {}
    }
}

@qzd1989
Copy link

qzd1989 commented Jul 1, 2024

I have pull something new for this issue, the EventType will return position when mouse button pressed or released.
see here: #138

@chaozwn
Copy link

chaozwn commented Nov 10, 2024

I have pull something new for this issue, the EventType will return position when mouse button pressed or released. see here: #138
Why did you close your pr?

@qzd1989
Copy link

qzd1989 commented Nov 11, 2024

I have pull something new for this issue, the EventType will return position when mouse button pressed or released. see here: #138
Why did you close your pr?

It's not necessary to implement this feature.

@chaozwn
Copy link

chaozwn commented Nov 12, 2024

I have pull something new for this issue, the EventType will return position when mouse button pressed or released. see here: #138
Why did you close your pr?

It's not necessary to implement this feature.

So is there a way to get x and y when you press the mouse down.

@qzd1989
Copy link

qzd1989 commented Nov 15, 2024

I have pull something new for this issue, the EventType will return position when mouse button pressed or released. see here: #138
Why did you close your pr?

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.

@HuakunShen
Copy link
Author

I have pull something new for this issue, the EventType will return position when mouse button pressed or released. see here: #138
Why did you close your pr?

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.

@qzd1989
Copy link

qzd1989 commented Nov 19, 2024

I have pull something new for this issue, the EventType will return position when mouse button pressed or released. see here: #138
Why did you close your pr?

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.
"get_current_mouse_location" this fn, you can read the source code and search it. also there are some third library crates can get the current location of mouse. so it's to necessary to implement it. and you can use engino instead of rdev too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants