mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 14:59:02 +08:00
feat: macos, mouse button, back&forward (#9185)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
c68ce7dd84
commit
40239a1c41
@ -37,6 +37,9 @@ const kUCKeyActionDisplay: u16 = 3;
|
||||
const kUCKeyTranslateDeadKeysBit: OptionBits = 1 << 31;
|
||||
const BUF_LEN: usize = 4;
|
||||
|
||||
const MOUSE_EVENT_BUTTON_NUMBER_BACK: i64 = 3;
|
||||
const MOUSE_EVENT_BUTTON_NUMBER_FORWARD: i64 = 4;
|
||||
|
||||
/// The event source user data value of cgevent.
|
||||
pub const ENIGO_INPUT_EXTRA_VALUE: i64 = 100;
|
||||
|
||||
@ -226,14 +229,24 @@ impl MouseControllable for Enigo {
|
||||
}
|
||||
self.last_click_time = Some(now);
|
||||
let (current_x, current_y) = Self::mouse_location();
|
||||
let (button, event_type) = match button {
|
||||
MouseButton::Left => (CGMouseButton::Left, CGEventType::LeftMouseDown),
|
||||
MouseButton::Middle => (CGMouseButton::Center, CGEventType::OtherMouseDown),
|
||||
MouseButton::Right => (CGMouseButton::Right, CGEventType::RightMouseDown),
|
||||
let (button, event_type, btn_value) = match button {
|
||||
MouseButton::Left => (CGMouseButton::Left, CGEventType::LeftMouseDown, None),
|
||||
MouseButton::Middle => (CGMouseButton::Center, CGEventType::OtherMouseDown, None),
|
||||
MouseButton::Right => (CGMouseButton::Right, CGEventType::RightMouseDown, None),
|
||||
MouseButton::Back => (
|
||||
CGMouseButton::Left,
|
||||
CGEventType::OtherMouseDown,
|
||||
Some(MOUSE_EVENT_BUTTON_NUMBER_BACK),
|
||||
),
|
||||
MouseButton::Forward => (
|
||||
CGMouseButton::Left,
|
||||
CGEventType::OtherMouseDown,
|
||||
Some(MOUSE_EVENT_BUTTON_NUMBER_FORWARD),
|
||||
),
|
||||
_ => {
|
||||
log::info!("Unsupported button {:?}", button);
|
||||
return Ok(());
|
||||
},
|
||||
}
|
||||
};
|
||||
let dest = CGPoint::new(current_x as f64, current_y as f64);
|
||||
if let Some(src) = self.event_source.as_ref() {
|
||||
@ -244,6 +257,9 @@ impl MouseControllable for Enigo {
|
||||
self.multiple_click,
|
||||
);
|
||||
}
|
||||
if let Some(v) = btn_value {
|
||||
event.set_integer_value_field(EventField::MOUSE_EVENT_BUTTON_NUMBER, v);
|
||||
}
|
||||
self.post(event);
|
||||
}
|
||||
}
|
||||
@ -252,14 +268,24 @@ impl MouseControllable for Enigo {
|
||||
|
||||
fn mouse_up(&mut self, button: MouseButton) {
|
||||
let (current_x, current_y) = Self::mouse_location();
|
||||
let (button, event_type) = match button {
|
||||
MouseButton::Left => (CGMouseButton::Left, CGEventType::LeftMouseUp),
|
||||
MouseButton::Middle => (CGMouseButton::Center, CGEventType::OtherMouseUp),
|
||||
MouseButton::Right => (CGMouseButton::Right, CGEventType::RightMouseUp),
|
||||
let (button, event_type, btn_value) = match button {
|
||||
MouseButton::Left => (CGMouseButton::Left, CGEventType::LeftMouseUp, None),
|
||||
MouseButton::Middle => (CGMouseButton::Center, CGEventType::OtherMouseUp, None),
|
||||
MouseButton::Right => (CGMouseButton::Right, CGEventType::RightMouseUp, None),
|
||||
MouseButton::Back => (
|
||||
CGMouseButton::Left,
|
||||
CGEventType::OtherMouseUp,
|
||||
Some(MOUSE_EVENT_BUTTON_NUMBER_BACK),
|
||||
),
|
||||
MouseButton::Forward => (
|
||||
CGMouseButton::Left,
|
||||
CGEventType::OtherMouseUp,
|
||||
Some(MOUSE_EVENT_BUTTON_NUMBER_FORWARD),
|
||||
),
|
||||
_ => {
|
||||
log::info!("Unsupported button {:?}", button);
|
||||
return;
|
||||
},
|
||||
}
|
||||
};
|
||||
let dest = CGPoint::new(current_x as f64, current_y as f64);
|
||||
if let Some(src) = self.event_source.as_ref() {
|
||||
@ -270,6 +296,9 @@ impl MouseControllable for Enigo {
|
||||
self.multiple_click,
|
||||
);
|
||||
}
|
||||
if let Some(v) = btn_value {
|
||||
event.set_integer_value_field(EventField::MOUSE_EVENT_BUTTON_NUMBER, v);
|
||||
}
|
||||
self.post(event);
|
||||
}
|
||||
}
|
||||
@ -385,9 +414,7 @@ impl KeyboardControllable for Enigo {
|
||||
return Err("".into());
|
||||
}
|
||||
if let Some(src) = self.event_source.as_ref() {
|
||||
if let Ok(event) =
|
||||
CGEvent::new_keyboard_event(src.clone(), code, true)
|
||||
{
|
||||
if let Ok(event) = CGEvent::new_keyboard_event(src.clone(), code, true) {
|
||||
self.post(event);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user