Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b02a37d

Browse files
Merge pull request #1755 from rust-osdev/bishop-add-input-example
test-runner: Add example of using the Input protocol
2 parents 4576f5a + ee26d74 commit b02a37d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

‎uefi-test-runner/examples/input.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /