@@ -26,12 +26,52 @@ impl Input {
26
26
27
27
/// Reads the next keystroke from the input device, if any.
28
28
///
29
- /// Use `wait_for_key_event()` with the `BootServices::wait_for_event()`
29
+ /// Use [ `wait_for_key_event`] with the [ `BootServices::wait_for_event`]
30
30
/// interface in order to wait for a key to be pressed.
31
31
///
32
+ /// [`BootServices::wait_for_event`]: uefi::table::boot::BootServices::wait_for_event
33
+ /// [`wait_for_key_event`]: Self::wait_for_key_event
34
+ ///
32
35
/// # Errors
33
36
///
34
- /// - `DeviceError` if there was an issue with the input device
37
+ /// - [`Status::DEVICE_ERROR`] if there was an issue with the input device
38
+ ///
39
+ /// # Examples
40
+ ///
41
+ /// ```
42
+ /// use log::info;
43
+ /// use uefi::proto::console::text::{Input, Key, ScanCode};
44
+ /// use uefi::table::boot::BootServices;
45
+ /// use uefi::{Char16, Result, ResultExt};
46
+ ///
47
+ /// fn read_keyboard_events(boot_services: &BootServices, input: &mut Input) -> Result {
48
+ /// loop {
49
+ /// // Pause until a keyboard event occurs.
50
+ /// let mut events = unsafe { [input.wait_for_key_event().unsafe_clone()] };
51
+ /// boot_services
52
+ /// .wait_for_event(&mut events)
53
+ /// .discard_errdata()?;
54
+ ///
55
+ /// let u_key = Char16::try_from('u').unwrap();
56
+ /// match input.read_key()? {
57
+ /// // Example of handling a printable key: print a message when
58
+ /// // the 'u' key is pressed.
59
+ /// Some(Key::Printable(key)) if key == u_key => {
60
+ /// info!("the 'u' key was pressed");
61
+ /// }
62
+ ///
63
+ /// // Example of handling a special key: exit the loop when the
64
+ /// // escape key is pressed.
65
+ /// Some(Key::Special(ScanCode::ESCAPE)) => {
66
+ /// break;
67
+ /// }
68
+ /// _ => {}
69
+ /// }
70
+ /// }
71
+ ///
72
+ /// Ok(())
73
+ /// }
74
+ /// ```
35
75
pub fn read_key ( & mut self ) -> Result < Option < Key > > {
36
76
let mut key = MaybeUninit :: < RawKey > :: uninit ( ) ;
37
77
0 commit comments