diff --git a/libs/enigo/src/linux.rs b/libs/enigo/src/linux.rs index 7e3ba6d51..61b11ddec 100644 --- a/libs/enigo/src/linux.rs +++ b/libs/enigo/src/linux.rs @@ -383,6 +383,17 @@ impl KeyboardControllable for Enigo { if self.xdo.is_null() { return false; } + /* + // modifier keys mask + pub const ShiftMask: c_uint = 0x01; + pub const LockMask: c_uint = 0x02; + pub const ControlMask: c_uint = 0x04; + pub const Mod1Mask: c_uint = 0x08; + pub const Mod2Mask: c_uint = 0x10; + pub const Mod3Mask: c_uint = 0x20; + pub const Mod4Mask: c_uint = 0x40; + pub const Mod5Mask: c_uint = 0x80; + */ let mod_shift = 1 << 0; let mod_lock = 1 << 1; let mod_control = 1 << 2; diff --git a/pynput_service.py b/pynput_service.py index db79201f8..a3da93037 100644 --- a/pynput_service.py +++ b/pynput_service.py @@ -47,18 +47,19 @@ def loop(): keyboard = Controller() print("Keyboard reset") continue - print(msg) if len(msg) == 2: name = msg[1] else: name = KeyCode._from_symbol(msg[1:]) - print(name) if name == INVALID: continue - if msg[0] == "p": - keyboard.press(name) - else: - keyboard.release(name) + try: + if msg[0] == "p": + keyboard.press(name) + else: + keyboard.release(name) + except Exception as e: + print(e) loop() diff --git a/src/server/input_service.rs b/src/server/input_service.rs index 7dbe4105d..93d2ee85b 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -21,6 +21,8 @@ impl super::service::Reset for StateCursor { *self = Default::default(); crate::platform::reset_input_cache(); fix_key_down_timeout(true); + #[cfg(target_os = "linux")] + ENIGO.lock().unwrap().reset(); } } @@ -346,8 +348,8 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) { let mut en = ENIGO.lock().unwrap(); #[cfg(not(target_os = "macos"))] let mut to_release = Vec::new(); - fix_modifiers(&evt.modifiers[..], &mut en, 0); if evt_type == 1 { + fix_modifiers(&evt.modifiers[..], &mut en, 0); #[cfg(target_os = "macos")] en.reset_flag(); for ref ck in evt.modifiers.iter() { @@ -562,6 +564,18 @@ fn handle_key_(evt: &KeyEvent) { 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 = "linux")] + if key == &Key::Alt && !get_modifier_state(key.clone(), &mut en) { + // for AltGr on Linux + if KEYS_DOWN + .lock() + .unwrap() + .get(&(ControlKey::RAlt.value() as _)) + .is_some() + { + continue; + } + } #[cfg(target_os = "macos")] en.add_flag(key); #[cfg(not(target_os = "macos"))]