test-runner: Add example of using the Input protocol

This commit is contained in:
Nicholas Bishop
2025-09-03 14:20:12 -04:00
parent 4576f5a0dc
commit ee26d747cc
+36
View File
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
#![no_main]
#![no_std]
use uefi::proto::console::text::{Input, Key, ScanCode};
use uefi::{Result, ResultExt, Status, boot, entry, println, system};
fn read_keyboard_events(input: &mut Input) -> Result {
loop {
println!("waiting for key press...");
// Pause until a keyboard event occurs.
let mut events = [input.wait_for_key_event().unwrap()];
boot::wait_for_event(&mut events).discard_errdata()?;
match input.read_key()? {
Some(Key::Printable(key)) => {
println!("key '{key}' was pressed");
}
// Exit the loop when the escape key is pressed.
Some(Key::Special(ScanCode::ESCAPE)) => {
break;
}
_ => {}
}
}
Ok(())
}
#[entry]
fn main() -> Status {
system::with_stdin(|input| read_keyboard_events(input).status())
}