1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use crate::proto::Protocol;
use crate::{unsafe_guid, Char16, Event, Result, Status};
use core::mem::MaybeUninit;
#[repr(C)]
#[unsafe_guid("387477c1-69c7-11d2-8e39-00a0c969723b")]
#[derive(Protocol)]
pub struct Input {
reset: extern "efiapi" fn(this: &mut Input, extended: bool) -> Status,
read_key_stroke: extern "efiapi" fn(this: &mut Input, key: *mut RawKey) -> Status,
wait_for_key: Event,
}
impl Input {
pub fn reset(&mut self, extended_verification: bool) -> Result {
(self.reset)(self, extended_verification).into()
}
pub fn read_key(&mut self) -> Result<Option<Key>> {
let mut key = MaybeUninit::<RawKey>::uninit();
match (self.read_key_stroke)(self, key.as_mut_ptr()) {
Status::NOT_READY => Ok(None),
other => other.into_with_val(|| Some(unsafe { key.assume_init() }.into())),
}
}
pub fn wait_for_key_event(&self) -> &Event {
&self.wait_for_key
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Key {
Printable(Char16),
Special(ScanCode),
}
impl From<RawKey> for Key {
fn from(k: RawKey) -> Key {
if k.scan_code == ScanCode::NULL {
Key::Printable(k.unicode_char)
} else {
Key::Special(k.scan_code)
}
}
}
#[repr(C)]
pub struct RawKey {
pub scan_code: ScanCode,
pub unicode_char: Char16,
}
newtype_enum! {
pub enum ScanCode: u16 => #[allow(missing_docs)] {
NULL = 0x00,
UP = 0x01,
DOWN = 0x02,
RIGHT = 0x03,
LEFT = 0x04,
HOME = 0x05,
END = 0x06,
INSERT = 0x07,
DELETE = 0x08,
PAGE_UP = 0x09,
PAGE_DOWN = 0x0A,
FUNCTION_1 = 0x0B,
FUNCTION_2 = 0x0C,
FUNCTION_3 = 0x0D,
FUNCTION_4 = 0x0E,
FUNCTION_5 = 0x0F,
FUNCTION_6 = 0x10,
FUNCTION_7 = 0x11,
FUNCTION_8 = 0x12,
FUNCTION_9 = 0x13,
FUNCTION_10 = 0x14,
FUNCTION_11 = 0x15,
FUNCTION_12 = 0x16,
ESCAPE = 0x17,
FUNCTION_13 = 0x68,
FUNCTION_14 = 0x69,
FUNCTION_15 = 0x6A,
FUNCTION_16 = 0x6B,
FUNCTION_17 = 0x6C,
FUNCTION_18 = 0x6D,
FUNCTION_19 = 0x6E,
FUNCTION_20 = 0x6F,
FUNCTION_21 = 0x70,
FUNCTION_22 = 0x71,
FUNCTION_23 = 0x72,
FUNCTION_24 = 0x73,
MUTE = 0x7F,
VOLUME_UP = 0x80,
VOLUME_DOWN = 0x81,
BRIGHTNESS_UP = 0x100,
BRIGHTNESS_DOWN = 0x101,
SUSPEND = 0x102,
HIBERNATE = 0x103,
TOGGLE_DISPLAY = 0x104,
RECOVERY = 0x105,
EJECT = 0x106,
}}