uefi_input2/
simple_text_input_ex.rs

1use core::ffi::c_void;
2pub use uefi_raw::Boolean;
3use uefi_raw::{guid, Event, Guid, Status};
4pub use uefi_raw::protocol::console::InputKey;
5
6pub type KeyToggleState = u8;
7/// Keyboard states:
8/// including Shift/Alt/Ctrl states and Caps Lock flags.
9#[repr(C)]
10#[derive(Clone, Copy, Debug, Default)]
11pub struct KeyState {
12    /// The bitmask here is determined using the SHIFT_STATE constant below.
13    pub key_shift_state: u32,
14    /// TOGGLE_STATE
15    pub key_toggle_state: KeyToggleState,
16}
17
18/// C FFI key data structure
19#[repr(C)]
20#[derive(Clone, Copy, Debug, Default)]
21pub struct RawKeyData {
22    pub key: InputKey,
23    pub key_state: KeyState,
24}
25
26// Protocol constant definition
27// Key combination status mask
28pub const SHIFT_STATE_VALID: u32     = 0x8000_0000;
29pub const RIGHT_SHIFT_PRESSED: u32   = 0x0000_0001;
30pub const LEFT_SHIFT_PRESSED: u32    = 0x0000_0002;
31pub const RIGHT_CONTROL_PRESSED: u32 = 0x0000_0004;
32pub const LEFT_CONTROL_PRESSED: u32  = 0x0000_0008;
33pub const RIGHT_ALT_PRESSED: u32     = 0x0000_0010;
34pub const LEFT_ALT_PRESSED: u32      = 0x0000_0020;
35pub const RIGHT_LOGO_PRESSED: u32    = 0x0000_0040;
36pub const LEFT_LOGO_PRESSED: u32     = 0x0000_0080;
37pub const MENU_KEY_PRESSED: u32      = 0x0000_0100;
38pub const SYS_REQ_PRESSED: u32       = 0x0000_0200;
39
40// Toggle state mask
41pub const TOGGLE_STATE_VALID: u8     = 0x80;
42pub const KEY_STATE_EXPOSED: u8      = 0x40;
43pub const SCROLL_LOCK_ACTIVE: u8     = 0x01;
44pub const NUM_LOCK_ACTIVE: u8        = 0x02;
45pub const CAPS_LOCK_ACTIVE: u8       = 0x04;
46
47// Protocol interface definition
48/// Key notification callback function type
49pub type KeyNotifyFunction = unsafe extern "efiapi" fn(key_data: *mut RawKeyData) -> Status;
50
51/// EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL:
52/// allows obtaining modifier key (Shift/Alt/Ctrl) states.
53#[derive(Debug)]
54#[repr(C)]
55pub struct SimpleTextInputExProtocol {
56    /// Resets the input device hardware.
57    pub reset: unsafe extern "efiapi" fn(this: *mut Self, extended_verification: Boolean) -> Status,
58
59    /// Reads key data (including KeyState).
60    pub read_key_stroke_ex: unsafe extern "efiapi" fn(this: *mut Self, key_data: *mut RawKeyData) -> Status,
61
62    /// Event for waiting for a key press.
63    pub wait_for_key_ex: Event,
64
65    /// Sets the keyboard indicator light state (e.g., CapsLock).
66    pub set_state: unsafe extern "efiapi" fn(this: *mut Self, key_toggle_state: *mut KeyToggleState) -> Status,
67
68    /// Registers a key notification function, triggered when a specific key is pressed.
69    pub register_key_notify: unsafe extern "efiapi" fn(
70        this: *mut Self,
71        key_data: *mut RawKeyData,
72        key_notification_function: KeyNotifyFunction,
73        notify_handle: *mut *mut c_void,
74    ) -> Status,
75
76    /// Unregisters a key notification.
77    pub unregister_key_notify: unsafe extern "efiapi" fn(this: *mut Self, notification_handle: *mut c_void) -> Status,
78}
79
80impl SimpleTextInputExProtocol {
81    pub const GUID: Guid = guid!("dd9e7534-7762-4698-8c14-f58517a625aa");
82}