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).
§Features
- 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.
§Usage
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_input2::with_stdin;
use uefi_input2::simple_text_input_ex::{LEFT_SHIFT_PRESSED, RIGHT_SHIFT_PRESSED};
#[entry]
fn main() -> Status {
uefi::helpers::init().unwrap();
with_stdin(|input| {
loop {
if let Some(data) = input.read_key_stroke_ex() {
// Check if any Shift key is held
let is_shift = data.key_state.key_shift_state & (LEFT_SHIFT_PRESSED | RIGHT_SHIFT_PRESSED) != 0;
if is_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§
Functions§
- with_
stdin - it has roughly the same function as
uefi::system::with_stdin.