feat(inject): add evdev_modifier_delay option
This commit is contained in:
parent
d86c6f7c46
commit
d20eaf1aba
|
@ -249,6 +249,12 @@ impl EVDEVInjector {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn wait_delay(&self, delay_ms: u32) {
|
||||||
|
if delay_ms > 0 {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(delay_ms as u64));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Injector for EVDEVInjector {
|
impl Injector for EVDEVInjector {
|
||||||
|
@ -267,6 +273,7 @@ impl Injector for EVDEVInjector {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let delay_us = options.delay as u32 * 1000; // Convert to micro seconds
|
let delay_us = options.delay as u32 * 1000; // Convert to micro seconds
|
||||||
|
let modifier_delay_ms = options.evdev_modifier_delay;
|
||||||
|
|
||||||
// We need to keep track of the modifiers currently pressed to
|
// We need to keep track of the modifiers currently pressed to
|
||||||
// press or release them accordingly
|
// press or release them accordingly
|
||||||
|
@ -277,13 +284,21 @@ impl Injector for EVDEVInjector {
|
||||||
|
|
||||||
// Release all the modifiers that are not needed anymore
|
// Release all the modifiers that are not needed anymore
|
||||||
for expired_modifier in current_modifiers.difference(&record_modifiers) {
|
for expired_modifier in current_modifiers.difference(&record_modifiers) {
|
||||||
|
self.wait_delay(modifier_delay_ms);
|
||||||
|
|
||||||
self.send_key(*expired_modifier, false, delay_us);
|
self.send_key(*expired_modifier, false, delay_us);
|
||||||
|
|
||||||
|
self.wait_delay(modifier_delay_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Press all the new modifiers that are now needed
|
// Press all the new modifiers that are now needed
|
||||||
for new_modifier in record_modifiers.difference(¤t_modifiers) {
|
for new_modifier in record_modifiers.difference(¤t_modifiers) {
|
||||||
|
self.wait_delay(modifier_delay_ms);
|
||||||
|
|
||||||
self.wait_until_key_is_released(record.code)?;
|
self.wait_until_key_is_released(record.code)?;
|
||||||
self.send_key(*new_modifier, true, delay_us);
|
self.send_key(*new_modifier, true, delay_us);
|
||||||
|
|
||||||
|
self.wait_delay(modifier_delay_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the char
|
// Send the char
|
||||||
|
|
|
@ -57,6 +57,10 @@ pub struct InjectionOptions {
|
||||||
// using XSendEvent rather than XTestFakeKeyEvent
|
// using XSendEvent rather than XTestFakeKeyEvent
|
||||||
// NOTE: Only relevant on X11 linux systems.
|
// NOTE: Only relevant on X11 linux systems.
|
||||||
pub disable_fast_inject: bool,
|
pub disable_fast_inject: bool,
|
||||||
|
|
||||||
|
// Used to set a modifier-specific delay.
|
||||||
|
// NOTE: Only relevant on Wayland systems.
|
||||||
|
pub evdev_modifier_delay: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InjectionOptions {
|
impl Default for InjectionOptions {
|
||||||
|
@ -78,6 +82,7 @@ impl Default for InjectionOptions {
|
||||||
Self {
|
Self {
|
||||||
delay: default_delay,
|
delay: default_delay,
|
||||||
disable_fast_inject: false,
|
disable_fast_inject: false,
|
||||||
|
evdev_modifier_delay: 10,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user