Skip to content

Can't seem to emit a few dozens of key events at once on the virtual keyboard #166

Description

@fr33-sh

If I have a vector of around 30 InputEvents and try to emit them on a virtual keyboard, only a few of them and sometimes none of them will actually be emitted. Here's a minimal PoC for this issue, where I expect the 50 'A' to be typed, but in reality only a few are typed. And if I change 50 to 30, it seems like it only type out 'A's every 2 iterations. Is it an issue with this crate, or linux?

use evdev::KeyEvent;use evdev::{Device, uinput::VirtualDevice,AttributeSet,EventType,InputEvent,KeyCode};use std::collections::HashSet;use std::thread::sleep;use std::time;use std::time::Duration;use std::fs::File;use std::io::{Read};fnmain() -> std::io::Result<()>{// Have to insert all allowed keys manually (?)// Is it because the evdev crate is minimal?letmut all_keys = vec![KeyCode::KEY_ESC,KeyCode::KEY_1,KeyCode::KEY_2,KeyCode::KEY_3,KeyCode::KEY_4,KeyCode::KEY_5,KeyCode::KEY_6,KeyCode::KEY_7,KeyCode::KEY_8,KeyCode::KEY_9,KeyCode::KEY_0,KeyCode::KEY_MINUS,KeyCode::KEY_EQUAL,KeyCode::KEY_BACKSPACE,KeyCode::KEY_TAB,KeyCode::KEY_Q,KeyCode::KEY_W,KeyCode::KEY_E,KeyCode::KEY_R,KeyCode::KEY_T,KeyCode::KEY_Y,KeyCode::KEY_U,KeyCode::KEY_I,KeyCode::KEY_O,KeyCode::KEY_P,KeyCode::KEY_LEFTBRACE,KeyCode::KEY_RIGHTBRACE,KeyCode::KEY_ENTER,KeyCode::KEY_LEFTCTRL,KeyCode::KEY_LEFTMETA,KeyCode::KEY_A,KeyCode::KEY_S,KeyCode::KEY_D,KeyCode::KEY_F,KeyCode::KEY_G,KeyCode::KEY_H,KeyCode::KEY_J,KeyCode::KEY_K,KeyCode::KEY_L,KeyCode::KEY_SEMICOLON,KeyCode::KEY_APOSTROPHE,KeyCode::KEY_GRAVE,KeyCode::KEY_LEFTSHIFT,KeyCode::KEY_BACKSLASH,KeyCode::KEY_Z,KeyCode::KEY_X,KeyCode::KEY_C,KeyCode::KEY_V,KeyCode::KEY_B,KeyCode::KEY_N,KeyCode::KEY_M,KeyCode::KEY_COMMA,KeyCode::KEY_DOT,KeyCode::KEY_SLASH,KeyCode::KEY_RIGHTSHIFT,KeyCode::KEY_LEFTALT,KeyCode::KEY_SPACE,KeyCode::KEY_CAPSLOCK,KeyCode::KEY_RIGHTCTRL,KeyCode::KEY_RIGHTALT,];letmut v_keys = AttributeSet::<KeyCode>::new();for key in all_keys {
v_keys.insert(key);}// Create a virtual keyboard.letmut v_keyboard = VirtualDevice::builder()?
.name("Virtual Keyboard").with_keys(&v_keys)?
.build().unwrap();for path in v_keyboard.enumerate_dev_nodes_blocking()? {let path = path?;println!("Available as {}", path.display());}let new_input_event_down = InputEvent::new(EventType::KEY.0,KeyCode::KEY_A.code(),1);let new_input_event_up = InputEvent::new(EventType::KEY.0,KeyCode::KEY_A.code(),0);letmut new_input_events:Vec<InputEvent> = Vec::new();for i in(1..50){
new_input_events.push(new_input_event_down);
new_input_events.push(new_input_event_up);}loop{
v_keyboard.emit(&new_input_events).unwrap();sleep(Duration::from_secs(2));}Ok(())}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions