Merge pull request #2731 from fufesou/feat/mouse_forward_back

Feat/mouse forward back
This commit is contained in:
RustDesk 2023-01-05 18:00:07 +08:00 committed by GitHub
commit 0f207bd38d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 18 deletions

View File

@ -466,15 +466,21 @@ class InputModel {
evt['y'] = '${y.round()}'; evt['y'] = '${y.round()}';
var buttons = ''; var buttons = '';
switch (evt['buttons']) { switch (evt['buttons']) {
case 1: case kPrimaryMouseButton:
buttons = 'left'; buttons = 'left';
break; break;
case 2: case kSecondaryMouseButton:
buttons = 'right'; buttons = 'right';
break; break;
case 4: case kMiddleMouseButton:
buttons = 'wheel'; buttons = 'wheel';
break; break;
case kBackMouseButton:
buttons = 'back';
break;
case kForwardMouseButton:
buttons = 'forward';
break;
} }
evt['buttons'] = buttons; evt['buttons'] = buttons;
bind.sessionSendMouse(id: id, msg: json.encode(evt)); bind.sessionSendMouse(id: id, msg: json.encode(evt));

View File

@ -104,6 +104,10 @@ pub enum MouseButton {
Middle, Middle,
/// Right mouse button /// Right mouse button
Right, Right,
/// Back mouse button
Back,
/// Forward mouse button
Forward,
/// Scroll up button /// Scroll up button
ScrollUp, ScrollUp,

View File

@ -57,6 +57,8 @@ fn mousebutton(button: MouseButton) -> c_int {
MouseButton::ScrollDown => 5, MouseButton::ScrollDown => 5,
MouseButton::ScrollLeft => 6, MouseButton::ScrollLeft => 6,
MouseButton::ScrollRight => 7, MouseButton::ScrollRight => 7,
MouseButton::Back => 8,
MouseButton::Forward => 9,
} }
} }

View File

@ -226,7 +226,10 @@ impl MouseControllable for Enigo {
MouseButton::Left => (CGMouseButton::Left, CGEventType::LeftMouseDown), MouseButton::Left => (CGMouseButton::Left, CGEventType::LeftMouseDown),
MouseButton::Middle => (CGMouseButton::Center, CGEventType::OtherMouseDown), MouseButton::Middle => (CGMouseButton::Center, CGEventType::OtherMouseDown),
MouseButton::Right => (CGMouseButton::Right, CGEventType::RightMouseDown), MouseButton::Right => (CGMouseButton::Right, CGEventType::RightMouseDown),
_ => unimplemented!(), _ => {
log::info!("Unsupported button {:?}", button);
return Ok(());
},
}; };
let dest = CGPoint::new(current_x as f64, current_y as f64); let dest = CGPoint::new(current_x as f64, current_y as f64);
if let Some(src) = self.event_source.as_ref() { if let Some(src) = self.event_source.as_ref() {
@ -249,7 +252,10 @@ impl MouseControllable for Enigo {
MouseButton::Left => (CGMouseButton::Left, CGEventType::LeftMouseUp), MouseButton::Left => (CGMouseButton::Left, CGEventType::LeftMouseUp),
MouseButton::Middle => (CGMouseButton::Center, CGEventType::OtherMouseUp), MouseButton::Middle => (CGMouseButton::Center, CGEventType::OtherMouseUp),
MouseButton::Right => (CGMouseButton::Right, CGEventType::RightMouseUp), MouseButton::Right => (CGMouseButton::Right, CGEventType::RightMouseUp),
_ => unimplemented!(), _ => {
log::info!("Unsupported button {:?}", button);
return;
},
}; };
let dest = CGPoint::new(current_x as f64, current_y as f64); let dest = CGPoint::new(current_x as f64, current_y as f64);
if let Some(src) = self.event_source.as_ref() { if let Some(src) = self.event_source.as_ref() {

View File

@ -134,9 +134,18 @@ impl MouseControllable for Enigo {
MouseButton::Left => MOUSEEVENTF_LEFTDOWN, MouseButton::Left => MOUSEEVENTF_LEFTDOWN,
MouseButton::Middle => MOUSEEVENTF_MIDDLEDOWN, MouseButton::Middle => MOUSEEVENTF_MIDDLEDOWN,
MouseButton::Right => MOUSEEVENTF_RIGHTDOWN, MouseButton::Right => MOUSEEVENTF_RIGHTDOWN,
_ => unimplemented!(), MouseButton::Back => MOUSEEVENTF_XDOWN,
MouseButton::Forward => MOUSEEVENTF_XDOWN,
_ => {
log::info!("Unsupported button {:?}", button);
return Ok(());
}
},
match button {
MouseButton::Back => XBUTTON1 as _,
MouseButton::Forward => XBUTTON2 as _,
_ => 0,
}, },
0,
0, 0,
0, 0,
); );
@ -155,9 +164,18 @@ impl MouseControllable for Enigo {
MouseButton::Left => MOUSEEVENTF_LEFTUP, MouseButton::Left => MOUSEEVENTF_LEFTUP,
MouseButton::Middle => MOUSEEVENTF_MIDDLEUP, MouseButton::Middle => MOUSEEVENTF_MIDDLEUP,
MouseButton::Right => MOUSEEVENTF_RIGHTUP, MouseButton::Right => MOUSEEVENTF_RIGHTUP,
_ => unimplemented!(), MouseButton::Back => MOUSEEVENTF_XUP,
MouseButton::Forward => MOUSEEVENTF_XUP,
_ => {
log::info!("Unsupported button {:?}", button);
return;
}
},
match button {
MouseButton::Back => XBUTTON1 as _,
MouseButton::Forward => XBUTTON2 as _,
_ => 0,
}, },
0,
0, 0,
0, 0,
); );

View File

@ -885,9 +885,11 @@ pub fn session_send_mouse(id: String, msg: String) {
} }
if let Some(buttons) = m.get("buttons") { if let Some(buttons) = m.get("buttons") {
mask |= match buttons.as_str() { mask |= match buttons.as_str() {
"left" => 1, "left" => 0x01,
"right" => 2, "right" => 0x02,
"wheel" => 4, "wheel" => 0x04,
"back" => 0x08,
"forward" => 0x10,
_ => 0, _ => 0,
} << 3; } << 3;
} }

View File

@ -556,27 +556,39 @@ pub fn handle_mouse_(evt: &MouseEvent) {
en.mouse_move_to(evt.x, evt.y); en.mouse_move_to(evt.x, evt.y);
} }
1 => match buttons { 1 => match buttons {
1 => { 0x01 => {
allow_err!(en.mouse_down(MouseButton::Left)); allow_err!(en.mouse_down(MouseButton::Left));
} }
2 => { 0x02 => {
allow_err!(en.mouse_down(MouseButton::Right)); allow_err!(en.mouse_down(MouseButton::Right));
} }
4 => { 0x04 => {
allow_err!(en.mouse_down(MouseButton::Middle)); allow_err!(en.mouse_down(MouseButton::Middle));
} }
0x08 => {
allow_err!(en.mouse_down(MouseButton::Back));
}
0x10 => {
allow_err!(en.mouse_down(MouseButton::Forward));
}
_ => {} _ => {}
}, },
2 => match buttons { 2 => match buttons {
1 => { 0x01 => {
en.mouse_up(MouseButton::Left); en.mouse_up(MouseButton::Left);
} }
2 => { 0x02 => {
en.mouse_up(MouseButton::Right); en.mouse_up(MouseButton::Right);
} }
4 => { 0x04 => {
en.mouse_up(MouseButton::Middle); en.mouse_up(MouseButton::Middle);
} }
0x08 => {
en.mouse_up(MouseButton::Back);
}
0x10 => {
en.mouse_up(MouseButton::Forward);
}
_ => {} _ => {}
}, },
3 | 4 => { 3 | 4 => {