This commit is contained in:
rustdesk 2021-08-08 01:44:37 +08:00
parent 3200002e52
commit ab4843b76e
3 changed files with 37 additions and 47 deletions

View File

@ -176,13 +176,13 @@ impl KeyboardControllable for Enigo {
}
fn key_click(&mut self, key: Key) {
let scancode = self.key_to_scancode(key);
keybd_event(KEYEVENTF_SCANCODE, 0, scancode);
keybd_event(KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE, 0, scancode);
let vk = self.key_to_keycode(key);
keybd_event(0, vk, 0);
keybd_event(KEYEVENTF_KEYUP, vk, 0);
}
fn key_down(&mut self, key: Key) -> crate::ResultType {
let res = keybd_event(KEYEVENTF_SCANCODE, 0, self.key_to_scancode(key));
let res = keybd_event(0, self.key_to_keycode(key), 0);
if res == 0 {
let err = get_error();
if !err.is_empty() {
@ -193,11 +193,7 @@ impl KeyboardControllable for Enigo {
}
fn key_up(&mut self, key: Key) {
keybd_event(
KEYEVENTF_KEYUP | KEYEVENTF_SCANCODE,
0,
self.key_to_scancode(key),
);
keybd_event(KEYEVENTF_KEYUP, self.key_to_keycode(key), 0);
}
fn get_key_state(&mut self, key: Key) -> bool {
@ -345,15 +341,9 @@ impl Enigo {
Key::Raw(raw_keycode) => raw_keycode,
Key::Layout(c) => self.get_layoutdependent_keycode(c.to_string()),
Key::Super | Key::Command | Key::Windows | Key::Meta => EVK_LWIN,
_ => 0,
}
}
fn key_to_scancode(&self, key: Key) -> u16 {
let keycode = self.key_to_keycode(key);
unsafe { MapVirtualKeyW(keycode as u32, 0) as u16 }
}
fn get_layoutdependent_keycode(&self, string: String) -> u16 {
// get the first char from the string ignore the rest
// ensure its not a multybyte char

View File

@ -13,7 +13,7 @@ tokio-util = { version = "0.6", features = ["full"] }
futures = "0.3"
bytes = "1.0"
log = "0.4"
env_logger = "0.8"
env_logger = "0.9"
socket2 = { version = "0.3", features = ["reuseport"] }
zstd = "0.9"
quinn = {version = "0.6", optional = true }

View File

@ -305,14 +305,12 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
let mut en = ENIGO.lock().unwrap();
#[cfg(not(target_os = "macos"))]
let mut to_release = Vec::new();
#[cfg(target_os = "macos")]
en.reset_flag();
if evt_type == 1 || evt_type == 2 {
if evt_type == 1 {
#[cfg(target_os = "macos")]
en.reset_flag();
fix_modifiers(&evt.modifiers[..], &mut en, 0);
}
for ref ck in evt.modifiers.iter() {
if let Some(key) = KEY_MAP.get(&ck.value()) {
if evt_type == 1 || evt_type == 2 {
for ref ck in evt.modifiers.iter() {
if let Some(key) = KEY_MAP.get(&ck.value()) {
#[cfg(target_os = "macos")]
en.add_flag(key);
#[cfg(not(target_os = "macos"))]
@ -511,30 +509,32 @@ fn handle_key_(evt: &KeyEvent) {
let mut has_cap = false;
#[cfg(windows)]
let mut has_numlock = false;
let ck = if let Some(key_event::Union::control_key(ck)) = evt.union {
ck.value()
} else {
-1
};
fix_modifiers(&evt.modifiers[..], &mut en, ck);
for ref ck in evt.modifiers.iter() {
if let Some(key) = KEY_MAP.get(&ck.value()) {
#[cfg(target_os = "macos")]
en.add_flag(key);
#[cfg(not(target_os = "macos"))]
{
if key == &Key::CapsLock {
has_cap = true;
} else if key == &Key::NumLock {
#[cfg(windows)]
{
has_numlock = true;
}
} else {
if !get_modifier_state(key.clone(), &mut en) {
en.key_down(key.clone()).ok();
modifier_sleep();
to_release.push(key);
if evt.down {
let ck = if let Some(key_event::Union::control_key(ck)) = evt.union {
ck.value()
} else {
-1
};
fix_modifiers(&evt.modifiers[..], &mut en, ck);
for ref ck in evt.modifiers.iter() {
if let Some(key) = KEY_MAP.get(&ck.value()) {
#[cfg(target_os = "macos")]
en.add_flag(key);
#[cfg(not(target_os = "macos"))]
{
if key == &Key::CapsLock {
has_cap = true;
} else if key == &Key::NumLock {
#[cfg(windows)]
{
has_numlock = true;
}
} else {
if !get_modifier_state(key.clone(), &mut en) {
en.key_down(key.clone()).ok();
modifier_sleep();
to_release.push(key);
}
}
}
}