Open takistakis opened 4 years ago
Thanks for opening this issue. Unfortunately i don't really understand the Problem. What do you mean by
with a keybinding Meta+a
is there a global keybinding and you're pressing Meta
right before the code executes manually? I just don't understand what is really causing the issue here.
Yes it's a global keybinding that's configured from the window manager (i3 in my case).
I have set up Meta+p
to call an application that uses enigo and types something.
This happens as soon as p
is pressed, and because Meta
is still pressed at this point, each character is typed with Meta
enabled.
So instead of actually typing the character, it triggers other keybindings that are set up by the window manager.
The macOS implementation would look like this:
impl Enigo {
pub fn clear_modifiers(&mut self) {
let event = CGEvent::new(self.event_source.clone()).unwrap();
event.set_type(CGEventType::FlagsChanged);
event.set_flags(CGEventFlags::CGEventFlagNull);
event.post(CGEventTapLocation::HID);
}
}
I guess another alternative would be to put event.set_flags(CGEventFlags::CGEventFlagNull)
inside of key_sequence
.
xdotool has a flag to clear modifiers and press them after the command was executed. From it's man page:
CLEARMODIFIERS
Any command taking the --clearmodifiers flag will attempt to clear any active
input modifiers during the command and restore them afterwards.
For example, if you were to run this command:
xdotool key a
The result would be 'a' or 'A' depending on whether or not you were holding the
shift key on your keyboard. Often it is undesirable to have any modifiers active,
so you can tell xdotool to clear any active modifiers.
The order of operations if you hold shift while running 'xdotool key
--clearmodifiers a' is this:
1. Query for all active modifiers (finds shift, in this case)
2. Try to clear shift by sending 'key up' for the shift key
3. Runs normal 'xdotool key a'
4. Restore shift key by sending 'key down' for shift
Would the suggested macOS implementation restore the modifiers afterwards?
enigo (at least the linux implementation) does not ignore modifiers such as Meta. So when executing a program that calls
enigo.key_sequence("asdf")
with a keybindingMeta+a
, ifMeta
is not unpressed quickly, the equivalent of "{+META}asdf" is typed instead.The following diff, creates a
clear_modifiers
function for the linux implementation, which callsxdo_clear_active_modifiers
.How does enigo work in this regard in windows and mac implementations? If they don't have the same behavior, enigo could clear modifiers implicitly before typing on linux.