mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-21 06:33:17 +03:00
Add full mouse support on windows (#11)
This commit is contained in:
committed by
GitHub
parent
57b0d898c1
commit
929ac1c643
@@ -3,7 +3,16 @@ use std::sync::mpsc::Receiver;
|
|||||||
use crate::event::{KeyboardEvent, PointerEvent};
|
use crate::event::{KeyboardEvent, PointerEvent};
|
||||||
use winapi::{
|
use winapi::{
|
||||||
self,
|
self,
|
||||||
um::winuser::{INPUT, INPUT_MOUSE, LPINPUT, MOUSEEVENTF_MOVE, MOUSEINPUT},
|
um::winuser::{INPUT, INPUT_MOUSE, LPINPUT, MOUSEEVENTF_MOVE, MOUSEINPUT,
|
||||||
|
MOUSEEVENTF_LEFTDOWN,
|
||||||
|
MOUSEEVENTF_RIGHTDOWN,
|
||||||
|
MOUSEEVENTF_MIDDLEDOWN,
|
||||||
|
MOUSEEVENTF_LEFTUP,
|
||||||
|
MOUSEEVENTF_RIGHTUP,
|
||||||
|
MOUSEEVENTF_MIDDLEUP,
|
||||||
|
MOUSEEVENTF_WHEEL,
|
||||||
|
MOUSEEVENTF_HWHEEL,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -11,16 +20,7 @@ use crate::{
|
|||||||
event::Event,
|
event::Event,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn rel_mouse(dx: i32, dy: i32) {
|
fn send_mouse_input(mi: MOUSEINPUT) {
|
||||||
let mi = MOUSEINPUT {
|
|
||||||
dx,
|
|
||||||
dy,
|
|
||||||
mouseData: 0,
|
|
||||||
dwFlags: MOUSEEVENTF_MOVE,
|
|
||||||
time: 0,
|
|
||||||
dwExtraInfo: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut input = INPUT {
|
let mut input = INPUT {
|
||||||
type_: INPUT_MOUSE,
|
type_: INPUT_MOUSE,
|
||||||
@@ -35,6 +35,60 @@ fn rel_mouse(dx: i32, dy: i32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rel_mouse(dx: i32, dy: i32) {
|
||||||
|
let mi = MOUSEINPUT {
|
||||||
|
dx,
|
||||||
|
dy,
|
||||||
|
mouseData: 0,
|
||||||
|
dwFlags: MOUSEEVENTF_MOVE,
|
||||||
|
time: 0,
|
||||||
|
dwExtraInfo: 0,
|
||||||
|
};
|
||||||
|
send_mouse_input(mi);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mouse_button(button: u32, state: u32) {
|
||||||
|
let dw_flags = match state {
|
||||||
|
0 => match button {
|
||||||
|
0x110 => MOUSEEVENTF_LEFTUP,
|
||||||
|
0x111 => MOUSEEVENTF_RIGHTUP,
|
||||||
|
0x112 => MOUSEEVENTF_MIDDLEUP,
|
||||||
|
_ => return
|
||||||
|
}
|
||||||
|
1 => match button {
|
||||||
|
0x110 => MOUSEEVENTF_LEFTDOWN,
|
||||||
|
0x111 => MOUSEEVENTF_RIGHTDOWN,
|
||||||
|
0x112 => MOUSEEVENTF_MIDDLEDOWN,
|
||||||
|
_ => return
|
||||||
|
}
|
||||||
|
_ => return
|
||||||
|
};
|
||||||
|
let mi = MOUSEINPUT {
|
||||||
|
dx: 0, dy: 0, // no movement
|
||||||
|
mouseData: 0,
|
||||||
|
dwFlags: dw_flags,
|
||||||
|
time: 0,
|
||||||
|
dwExtraInfo: 0,
|
||||||
|
};
|
||||||
|
send_mouse_input(mi);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll(axis: u8, value: f64) {
|
||||||
|
let event_type = match axis {
|
||||||
|
0 => MOUSEEVENTF_WHEEL,
|
||||||
|
1 => MOUSEEVENTF_HWHEEL,
|
||||||
|
_ => return
|
||||||
|
};
|
||||||
|
let mi = MOUSEINPUT {
|
||||||
|
dx: 0, dy: 0,
|
||||||
|
mouseData: (-value * 15.0) as i32 as u32,
|
||||||
|
dwFlags: event_type,
|
||||||
|
time: 0,
|
||||||
|
dwExtraInfo: 0,
|
||||||
|
};
|
||||||
|
send_mouse_input(mi);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(event_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
|
pub fn run(event_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
|
||||||
loop {
|
loop {
|
||||||
match event_rx.recv().expect("event receiver unavailable").0 {
|
match event_rx.recv().expect("event receiver unavailable").0 {
|
||||||
@@ -46,8 +100,11 @@ pub fn run(event_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
|
|||||||
} => {
|
} => {
|
||||||
rel_mouse(relative_x as i32, relative_y as i32);
|
rel_mouse(relative_x as i32, relative_y as i32);
|
||||||
}
|
}
|
||||||
PointerEvent::Button { .. } => {}
|
PointerEvent::Button { time:_, button, state } => { mouse_button(button, state)}
|
||||||
PointerEvent::Axis { .. } => {}
|
PointerEvent::Axis { time:_, axis, value } => {
|
||||||
|
println!("axis: {axis}, value: {value}");
|
||||||
|
scroll(axis, value)
|
||||||
|
}
|
||||||
PointerEvent::Frame {} => {}
|
PointerEvent::Frame {} => {}
|
||||||
},
|
},
|
||||||
Event::Keyboard(keyboard_event) => match keyboard_event {
|
Event::Keyboard(keyboard_event) => match keyboard_event {
|
||||||
|
|||||||
Reference in New Issue
Block a user