winit/platform/
modifier_supplement.rs

1use crate::event::KeyEvent;
2use crate::keyboard::Key;
3
4/// Additional methods for the `KeyEvent` which cannot be implemented on all
5/// platforms.
6pub trait KeyEventExtModifierSupplement {
7    /// Identical to `KeyEvent::text` but this is affected by <kbd>Ctrl</kbd>.
8    ///
9    /// For example, pressing <kbd>Ctrl</kbd>+<kbd>a</kbd> produces `Some("\x01")`.
10    fn text_with_all_modifiers(&self) -> Option<&str>;
11
12    /// This value ignores all modifiers including,
13    /// but not limited to <kbd>Shift</kbd>, <kbd>Caps Lock</kbd>,
14    /// and <kbd>Ctrl</kbd>. In most cases this means that the
15    /// unicode character in the resulting string is lowercase.
16    ///
17    /// This is useful for key-bindings / shortcut key combinations.
18    ///
19    /// In case `logical_key` reports `Dead`, this will still report the
20    /// key as `Character` according to the current keyboard layout. This value
21    /// cannot be `Dead`.
22    fn key_without_modifiers(&self) -> Key;
23}
24
25impl KeyEventExtModifierSupplement for KeyEvent {
26    #[inline]
27    fn text_with_all_modifiers(&self) -> Option<&str> {
28        self.platform_specific.text_with_all_modifiers.as_ref().map(|s| s.as_str())
29    }
30
31    #[inline]
32    fn key_without_modifiers(&self) -> Key {
33        self.platform_specific.key_without_modifiers.clone()
34    }
35}