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_stdinpattern to ensure the protocol is opened exclusively and closed automatically. - Extended Key Data: Access to
KeyShiftStateandKeyToggleState. - No-Std Compatible: Designed specifically for UEFI environments.
§Feature List
- alloc: Enables
Vecsupport. For example,with_stdinsrequires theallocfeature to more than 8 multiple input handles viafind_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
- hotplug
alloc - 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_
machine alloc - 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_ protocol extend - with_
stdin - it has roughly the same function as
uefi::system::with_stdin. only support single keyboard. - with_
stdins alloc - support multiple keyboard.