fix: Enter key not sent via uinput, add send_enter helper

- \n char had no keycode mapping — now sends KEY_ENTER via uinput
- Fixed in both ASCII path and trailing-ASCII-after-unicode path
- Enter now works on single press (was being silently consumed)
This commit is contained in:
Khoa Vo 2026-06-26 16:23:04 +07:00
parent ebfff3db11
commit b40c615583

View file

@ -124,6 +124,15 @@ impl KeyInjector for UinputInjector {
InjectResult::Success InjectResult::Success
} }
fn send_enter(&self) {
self.send_uinput_event(EV_KEY, 28, 1); // KEY_ENTER press
self.send_uinput_event(0, 0, 0);
std::thread::sleep(std::time::Duration::from_millis(2));
self.send_uinput_event(EV_KEY, 28, 0);
self.send_uinput_event(0, 0, 0);
std::thread::sleep(std::time::Duration::from_millis(2));
}
fn send_key_event(&self, keycode: u16, value: i32) -> InjectResult { fn send_key_event(&self, keycode: u16, value: i32) -> InjectResult {
self.send_uinput_event(EV_KEY, keycode, value); self.send_uinput_event(EV_KEY, keycode, value);
self.send_uinput_event(0, 0, 0); self.send_uinput_event(0, 0, 0);
@ -348,7 +357,11 @@ impl UinputInjector {
} }
} }
for ch in text.chars() { for ch in text.chars() {
let _ = self.send_char(ch); if ch == '\n' {
self.send_enter();
} else {
let _ = self.send_char(ch);
}
} }
return InjectResult::Success; return InjectResult::Success;
} }
@ -385,7 +398,9 @@ impl UinputInjector {
if !ascii_tail.is_empty() { if !ascii_tail.is_empty() {
std::thread::sleep(std::time::Duration::from_millis(15)); std::thread::sleep(std::time::Duration::from_millis(15));
for ch in ascii_tail.chars() { for ch in ascii_tail.chars() {
if let Some(kc) = char_to_linux_keycode(ch) { if ch == '\n' {
self.send_enter();
} else if let Some(kc) = char_to_linux_keycode(ch) {
self.send_key_stroke(kc, false); self.send_key_stroke(kc, false);
} }
} }