logitech_cve/
mouse.rs

1use std::{thread, time::Duration};
2
3use crate::device::Device;
4
5#[repr(u8)]
6pub enum MouseButton {
7    Left = 1,
8    Right = 2,
9    Middle = 4,
10    LeftRight = 3,
11    LeftMiddle = 5,
12    RightMiddle = 6,
13    All = 7,
14    Release = 0,
15}
16
17impl From<MouseButton> for u8 {
18    fn from(button: MouseButton) -> Self {
19        button as Self
20    }
21}
22
23pub struct Mouse<'a> {
24    device: &'a mut Device,
25}
26
27impl<'a> Mouse<'a> {
28    pub const fn new(device: &'a mut Device) -> Self {
29        Self { device }
30    }
31    
32    pub fn click(&mut self, button: MouseButton, millis: u64) {
33        self.device.send_mouse(button, 0, 0, 0);
34        thread::sleep(Duration::from_millis(millis));
35        self.device.send_mouse(MouseButton::Release, 0, 0, 0);
36    }
37
38    pub fn move_absolute(&mut self, button: MouseButton, x: i8, y: i8) {
39        self.device.send_mouse(button, x, y, 0);
40        todo!("Absolute move is not yet implemented");
41    }
42
43    pub fn move_relative(&mut self, button: MouseButton, x: i8, y: i8) {
44        self.device.send_mouse(button, x, y, 0);
45    }
46
47    pub fn press(&mut self, button: MouseButton) {
48        self.device.send_mouse(button, 0, 0, 0);
49    }
50
51    pub fn release(&mut self) {
52        self.device.send_mouse(MouseButton::Release, 0, 0, 0);
53    }
54
55    pub fn wheel(&mut self, button: MouseButton, wheel: i8) {
56        self.device.send_mouse(button, 0, 0, wheel);
57    }
58}