fixing AltGr

This commit is contained in:
rustdesk 2022-03-07 16:19:10 +08:00
parent ab1805281f
commit b8f7e347c3
4 changed files with 24 additions and 18 deletions

10
Cargo.lock generated
View File

@ -2548,18 +2548,18 @@ dependencies = [
[[package]]
name = "num_enum"
version = "0.5.6"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "720d3ea1055e4e4574c0c0b0f8c3fd4f24c4cdaf465948206dea090b57b526ad"
checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9"
dependencies = [
"num_enum_derive",
]
[[package]]
name = "num_enum_derive"
version = "0.5.6"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d992b768490d7fe0d8586d9b5745f6c49f557da6d81dc982b1d167ad4edbb21"
checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce"
dependencies = [
"proc-macro-crate 1.1.3",
"proc-macro2",
@ -3226,7 +3226,7 @@ dependencies = [
[[package]]
name = "rdev"
version = "0.5.0"
source = "git+https://github.com/open-trade/rdev#6d431464a29fa51008356734eb568f09e26d723f"
source = "git+https://github.com/open-trade/rdev#f2265895d92b4e9fcdc6f41e6e168d5da6d94493"
dependencies = [
"cocoa 0.22.0",
"core-foundation 0.7.0",

View File

@ -20,6 +20,7 @@ impl super::service::Reset for StateCursor {
fn reset(&mut self) {
*self = Default::default();
crate::platform::reset_input_cache();
fix_key_down_timeout(true);
}
}
@ -31,7 +32,6 @@ struct StatePos {
impl super::service::Reset for StatePos {
fn reset(&mut self) {
self.cursor_pos = (0, 0);
fix_key_down_timeout(true);
}
}
@ -227,7 +227,7 @@ pub fn handle_mouse(evt: &MouseEvent, conn: i32) {
pub fn fix_key_down_timeout_loop() {
std::thread::spawn(move || loop {
std::thread::sleep(std::time::Duration::from_millis(300));
std::thread::sleep(std::time::Duration::from_millis(1_000));
fix_key_down_timeout(false);
});
if let Err(err) = ctrlc::set_handler(move || {
@ -257,7 +257,6 @@ fn fix_key_down_timeout(force: bool) {
return;
}
let cloned = (*KEYS_DOWN.lock().unwrap()).clone();
log::debug!("{} keys in key down timeout map", cloned.len());
for (key, value) in cloned.into_iter() {
if force || value.elapsed().as_millis() >= 360_000 {
KEYS_DOWN.lock().unwrap().remove(&key);
@ -273,10 +272,8 @@ fn fix_key_down_timeout(force: bool) {
if let Some(key) = key {
let func = move || {
let mut en = ENIGO.lock().unwrap();
if get_modifier_state(key, &mut en) {
en.key_up(key);
log::debug!("Fixed {:?} timeout", key);
}
en.key_up(key);
log::debug!("Fixed {:?} timeout", key);
};
#[cfg(target_os = "macos")]
QUEUE.exec_async(func);
@ -357,8 +354,6 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
en.key_down(key.clone()).ok();
modifier_sleep();
to_release.push(key);
} else {
KEYS_DOWN.lock().unwrap().insert(ck.value() as _, Instant::now());
}
}
}
@ -577,8 +572,6 @@ fn handle_key_(evt: &KeyEvent) {
en.key_down(key.clone()).ok();
modifier_sleep();
to_release.push(key);
} else {
KEYS_DOWN.lock().unwrap().insert(ck.value() as _, Instant::now());
}
}
}

View File

@ -184,6 +184,7 @@ impl<T: Subscriber + From<ConnInner>> ServiceTmpl<T> {
let sp = self.clone();
let thread = thread::spawn(move || {
let mut state = S::default();
let mut may_reset = false;
while sp.active() {
let now = time::Instant::now();
if sp.has_subscribes() {
@ -193,8 +194,12 @@ impl<T: Subscriber + From<ConnInner>> ServiceTmpl<T> {
#[cfg(windows)]
crate::platform::windows::try_change_desktop();
}
} else {
if !may_reset {
may_reset = true;
}
} else if may_reset {
state.reset();
may_reset = false;
}
let elapsed = now.elapsed();
if elapsed < interval {

View File

@ -261,7 +261,15 @@ impl Handler {
Key::Alt => Some(ControlKey::Alt),
Key::AltGr => Some(ControlKey::RAlt),
Key::Backspace => Some(ControlKey::Backspace),
Key::ControlLeft => Some(ControlKey::Control),
Key::ControlLeft => {
// when pressing AltGr, an extra VK_LCONTROL with a special
// scancode with bit 9 set is sent, let's ignore this.
#[cfg(windows)]
if evt.scan_code & 0x200 != 0 {
return;
}
Some(ControlKey::Control)
}
Key::ControlRight => Some(ControlKey::RControl),
Key::DownArrow => Some(ControlKey::DownArrow),
Key::Escape => Some(ControlKey::Escape),