mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-19 00:13:01 +08:00
swap_modifier_key()
This commit is contained in:
parent
edff4acbcb
commit
f438dd9fd0
110
src/keyboard.rs
110
src/keyboard.rs
@ -202,66 +202,70 @@ pub fn update_grab_get_key_name() {
|
||||
#[cfg(target_os = "windows")]
|
||||
static mut IS_0X021D_DOWN: bool = false;
|
||||
|
||||
fn swap_modifier_key(mut event: Event) -> Event {
|
||||
|
||||
let mut allow_swap_key = false;
|
||||
#[cfg(not(any(feature = "flutter", feature = "cli")))]
|
||||
if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
|
||||
allow_swap_key = session.get_toggle_option("allow_swap_key".to_string());
|
||||
}
|
||||
#[cfg(feature = "flutter")]
|
||||
if let Some(session) = SESSIONS
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&*CUR_SESSION_ID.read().unwrap())
|
||||
{
|
||||
allow_swap_key = session.get_toggle_option("allow_swap_key".to_string());
|
||||
}
|
||||
if allow_swap_key {
|
||||
match event.event_type {
|
||||
EventType::KeyPress( key) => {
|
||||
let key = match key {
|
||||
rdev::Key::ControlLeft => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaLeft => rdev::Key::ControlLeft,
|
||||
rdev::Key::ControlRight => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaRight => rdev::Key::ControlLeft,
|
||||
_ => key,
|
||||
};
|
||||
event.event_type = EventType::KeyPress(key);
|
||||
#[cfg(target_os = "windows")]
|
||||
let scan_code = rdev::win_scancode_from_key(key).unwrap_or_default();
|
||||
#[cfg(target_os = "macos")]
|
||||
let scan_code = rdev::macos_keycode_from_key(key).unwrap_or_default();
|
||||
event.scan_code = scan_code;
|
||||
event.code = event.scan_code as _;
|
||||
}
|
||||
EventType::KeyRelease(key) => {
|
||||
let key = match key {
|
||||
rdev::Key::ControlLeft => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaLeft => rdev::Key::ControlLeft,
|
||||
rdev::Key::ControlRight => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaRight => rdev::Key::ControlLeft,
|
||||
_ => key,
|
||||
};
|
||||
event.event_type = EventType::KeyRelease(key);
|
||||
#[cfg(target_os = "windows")]
|
||||
let scan_code = rdev::win_scancode_from_key(key).unwrap_or_default();
|
||||
#[cfg(target_os = "macos")]
|
||||
let scan_code = rdev::macos_keycode_from_key(key).unwrap_or_default();
|
||||
event.scan_code = scan_code;
|
||||
event.code = event.scan_code as _;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
event
|
||||
}
|
||||
|
||||
pub fn start_grab_loop() {
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
std::thread::spawn(move || {
|
||||
let try_handle_keyboard = move |mut event: Event, key: Key, is_press: bool| -> Option<Event> {
|
||||
let try_handle_keyboard = move |event: Event, key: Key, is_press: bool| -> Option<Event> {
|
||||
// fix #2211:CAPS LOCK don't work
|
||||
if key == Key::CapsLock || key == Key::NumLock {
|
||||
return Some(event);
|
||||
}
|
||||
{
|
||||
let mut allow_swap_key = false;
|
||||
#[cfg(not(any(feature = "flutter", feature = "cli")))]
|
||||
if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
|
||||
allow_swap_key = session.get_toggle_option("allow_swap_key".to_string());
|
||||
}
|
||||
#[cfg(feature = "flutter")]
|
||||
if let Some(session) = SESSIONS
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&*CUR_SESSION_ID.read().unwrap())
|
||||
{
|
||||
allow_swap_key = session.get_toggle_option("allow_swap_key".to_string());
|
||||
}
|
||||
if allow_swap_key {
|
||||
match event.event_type {
|
||||
EventType::KeyPress( key) => {
|
||||
let key = match key {
|
||||
rdev::Key::ControlLeft => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaLeft => rdev::Key::ControlLeft,
|
||||
rdev::Key::ControlRight => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaRight => rdev::Key::ControlLeft,
|
||||
_ => key,
|
||||
};
|
||||
event.event_type = EventType::KeyPress(key);
|
||||
#[cfg(target_os = "windows")]
|
||||
let scan_code = rdev::win_scancode_from_key(key).unwrap_or_default();
|
||||
#[cfg(target_os = "macos")]
|
||||
let scan_code = rdev::macos_keycode_from_key(key).unwrap_or_default();
|
||||
event.scan_code = scan_code;
|
||||
event.code = event.scan_code as _;
|
||||
}
|
||||
EventType::KeyRelease(key) => {
|
||||
let key = match key {
|
||||
rdev::Key::ControlLeft => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaLeft => rdev::Key::ControlLeft,
|
||||
rdev::Key::ControlRight => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaRight => rdev::Key::ControlLeft,
|
||||
_ => key,
|
||||
};
|
||||
event.event_type = EventType::KeyRelease(key);
|
||||
#[cfg(target_os = "windows")]
|
||||
let scan_code = rdev::win_scancode_from_key(key).unwrap_or_default();
|
||||
#[cfg(target_os = "macos")]
|
||||
let scan_code = rdev::macos_keycode_from_key(key).unwrap_or_default();
|
||||
event.scan_code = scan_code;
|
||||
event.code = event.scan_code as _;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
};
|
||||
};
|
||||
let event = swap_modifier_key(event);
|
||||
|
||||
let mut _keyboard_mode = KeyboardMode::Map;
|
||||
let _scan_code = event.scan_code;
|
||||
|
Loading…
Reference in New Issue
Block a user