Crate uefi_input2

Crate uefi_input2 

Source
Expand description

§UEFI Simple Text Input Ex Protocol Wrapper

This library provides a safe, idiomatic Rust wrapper for the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL. Unlike the standard SimpleTextInput, this protocol allows for advanced key tracking, including shift state (Ctrl, Alt, Shift) and toggle state (Caps Lock, Num Lock).

§Purpose

  • Seamless Migration: Designed as a drop-in, painless replacement for the standard uefi::system::with_stdin.
  • Safe Resource Management: Uses the with_stdin pattern to ensure the protocol is opened exclusively and closed automatically.
  • Extended Key Data: Access to KeyShiftState and KeyToggleState.
  • No-Std Compatible: Designed specifically for UEFI environments.

§Feature List

  • alloc: Enables Vec support. For example, with_stdins requires the alloc feature to more than 8 multiple input handles via find_handles.

§Minimal Example

Simply replace your import and use the same closure-based pattern:

#![no_main]
#![no_std]
use uefi::prelude::*;
use uefi::{print, println};
use uefi::proto::console::text::Key::{Printable, Special};
use uefi::proto::console::text::ScanCode;
use uefi::boot::check_event;

#[entry]
fn main() -> Status {
    uefi::helpers::init().unwrap();

    uefi_input2::with_stdin(|input| {
        loop {
            // Performance Note: Using wait_for_key_event + check_event conforms to UEFI
            // best practices by reducing CPU overhead and bus traffic. However,
            // for maximum loop throughput (e.g., high-frequency GOP rendering),
            // consider calling read_key_stroke_ex directly to save the extra protocol call.
            let Some(event) = input.wait_for_key_event() else { continue };
            if !check_event(event)? { continue }

            if let Some(data) = input.read_key_stroke_ex() {
                if data.shift() { println!("Shift is being held!") }
                match data.key {
                   Printable(c) if u16::from(c) == 0x0D => print!("\r\n"),
                   Printable(c) => print!("{}", c),
                   Special(code) if code == ScanCode::ESCAPE => {
                       println!("Exiting...");
                       return Ok(())
                   },
                   _ => {},
               }
            }
        }
        Ok(())
    }).unwrap();

    Status::SUCCESS
}

Modules§

config
hotplugalloc
keyboard hotplug support (Not Recommend, Unplugging is UEFI Spec Undefined Behavior)
input
simple_text_input_ex wrapper
key_data
height-level data wrapper
simple_text_input_ex
C FFI Bindingw
state_machinealloc
Core input state machine for handling complex keyboard events. A high-level input state machine that transforms raw hardware signals into semantic events.

Functions§

init_keyboards_protocolextend
with_stdin
it has roughly the same function as uefi::system::with_stdin. only support single keyboard.
with_stdinsalloc
support multiple keyboard.