Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions uefi-test-runner/examples/input.rs
Original file line number Diff line number Diff line change
@@ -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())
}
Loading