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

afrim-preprocessor

A preprocessor to process keyboard events for an input method

3 unstable releases

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

#1081 in Hardware support

Download history 31/week @ 2024-02-19 13/week @ 2024-02-26 162/week @ 2024-03-04 55/week @ 2024-03-11 9/week @ 2024-03-25 38/week @ 2024-04-01

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

MIT license

56KB
711 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

~250–445KB