#keyboard-events #keyboard #keyboard-input #ime #input-event #processor

afrim-preprocessor

A preprocessor to process keyboard events for an input method

4 releases

0.6.1 Apr 28, 2024
0.6.0 Mar 5, 2024
0.5.1 Nov 9, 2023
0.5.0 Oct 24, 2023

#1229 in Hardware support

Download history 22/week @ 2024-03-27 23/week @ 2024-04-03 325/week @ 2024-04-10 1/week @ 2024-04-17 147/week @ 2024-04-24 17/week @ 2024-05-01 2/week @ 2024-05-15 8/week @ 2024-05-22 6/week @ 2024-05-29 7/week @ 2024-06-05 5/week @ 2024-06-12

459 downloads per month
Used in 2 crates (via afrim)

MPL-2.0 license

57KB
721 lines

Afrim Preprocessor

It generate a sequence of command to be perform to execute a particular task.

Features

  • inhibit: Enable the inhibit mode.
  • serde: Enable serialization/deserialization.

lib.rs:

Preprocess keyboard events for an input method.

Enables the generation of keyboard event responses from a keyboard input event in an input method engine. The afrim-preprocessor crate is built on the top of the afrim-memory crate.

Example

use afrim_preprocessor::{utils, Command, Preprocessor};
use keyboard_types::{
    webdriver::{self, Event},
    Key::*,
};
use std::{collections::VecDeque, rc::Rc};

// Prepares the memory.
let data = utils::load_data("cc ç");
let text_buffer = utils::build_map(data);
let memory = Rc::new(text_buffer);

// Builds the preprocessor.
let mut preprocessor = Preprocessor::new(memory, 8);

// Process an input.
let input = "cc";
webdriver::send_keys(input)
    .into_iter()
    .for_each(|event| {
        match event {
            // Triggers the generated keyboard input event.
            Event::Keyboard(event) => preprocessor.process(event),
            _ => unimplemented!(),
        };
    });

// Now let's look at the generated commands.
// The expected results without `inhibit` feature.
#[cfg(not(feature = "inhibit"))]
let mut expecteds = VecDeque::from(vec![
    Command::Pause,
    Command::Delete,
    Command::Delete,
    Command::CommitText("ç".to_owned()),
    Command::Resume,
]);

// The expected results with `inhibit` feature.
#[cfg(feature = "inhibit")]
let mut expecteds = VecDeque::from(vec![
    Command::Pause,
    Command::Delete,
    Command::Resume,
    Command::Pause,
    Command::Delete,
    Command::CommitText("ç".to_owned()),
    Command::Resume,
]);

// Verification.
while let Some(command) = preprocessor.pop_queue() {
    assert_eq!(command, expecteds.pop_front().unwrap());
}

Note: When dealing with non latin languages. The inhibit feature allows for the removal of unwanted characters typically latin characters, as much as posssible.

Dependencies

~230–420KB