|
| 1 | +// SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | + |
| 3 | +#![no_main] |
| 4 | +#![no_std] |
| 5 | + |
| 6 | +use uefi::proto::console::text::{Input, Key, ScanCode}; |
| 7 | +use uefi::{Result, ResultExt, Status, boot, entry, println, system}; |
| 8 | + |
| 9 | +fn read_keyboard_events(input: &mut Input) -> Result { |
| 10 | + loop { |
| 11 | + println!("waiting for key press..."); |
| 12 | + |
| 13 | + // Pause until a keyboard event occurs. |
| 14 | + let mut events = [input.wait_for_key_event().unwrap()]; |
| 15 | + boot::wait_for_event(&mut events).discard_errdata()?; |
| 16 | + |
| 17 | + match input.read_key()? { |
| 18 | + Some(Key::Printable(key)) => { |
| 19 | + println!("key '{key}' was pressed"); |
| 20 | + } |
| 21 | + |
| 22 | + // Exit the loop when the escape key is pressed. |
| 23 | + Some(Key::Special(ScanCode::ESCAPE)) => { |
| 24 | + break; |
| 25 | + } |
| 26 | + _ => {} |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + Ok(()) |
| 31 | +} |
| 32 | + |
| 33 | +#[entry] |
| 34 | +fn main() -> Status { |
| 35 | + system::with_stdin(|input| read_keyboard_events(input).status()) |
| 36 | +} |
0 commit comments