Refactor KeyCode into Key and Location

This commit is contained in:
Héctor Ramón Jiménez 2024-01-16 13:28:00 +01:00
parent 534c7dd7b0
commit 64d1ce5532
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
24 changed files with 1277 additions and 461 deletions

View file

@ -144,6 +144,7 @@ raw-window-handle = "0.5"
resvg = "0.36"
rustc-hash = "1.0"
smol = "1.0"
smol_str = "0.2"
softbuffer = "0.2"
syntect = "5.1"
sysinfo = "0.28"

View file

@ -13,10 +13,11 @@ keywords.workspace = true
[dependencies]
bitflags.workspace = true
log.workspace = true
thiserror.workspace = true
xxhash-rust.workspace = true
num-traits.workspace = true
smol_str.workspace = true
thiserror.workspace = true
web-time.workspace = true
xxhash-rust.workspace = true
palette.workspace = true
palette.optional = true

View file

@ -1,8 +1,11 @@
//! Listen to keyboard events.
pub mod key;
mod event;
mod key_code;
mod location;
mod modifiers;
pub use event::Event;
pub use key_code::KeyCode;
pub use key::Key;
pub use location::Location;
pub use modifiers::Modifiers;

View file

@ -1,4 +1,4 @@
use super::{KeyCode, Modifiers};
use crate::keyboard::{Key, Location, Modifiers};
/// A keyboard event.
///
@ -10,10 +10,13 @@ use super::{KeyCode, Modifiers};
pub enum Event {
/// A keyboard key was pressed.
KeyPressed {
/// The key identifier
key_code: KeyCode,
/// The key pressed.
key: Key,
/// The state of the modifier keys
/// The location of the key.
location: Location,
/// The state of the modifier keys.
modifiers: Modifiers,
/// The text produced by the key press, if any.
@ -22,10 +25,13 @@ pub enum Event {
/// A keyboard key was released.
KeyReleased {
/// The key identifier
key_code: KeyCode,
/// The key released.
key: Key,
/// The state of the modifier keys
/// The location of the key.
location: Location,
/// The state of the modifier keys.
modifiers: Modifiers,
},

744
core/src/keyboard/key.rs Normal file
View file

@ -0,0 +1,744 @@
//! Identify keyboard keys.
use smol_str::SmolStr;
/// A key on the keyboard.
///
/// This is mostly the `Key` type found in [`winit`].
///
/// [`winit`]: https://docs.rs/winit/0.29.10/winit/keyboard/enum.Key.html
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Key<C = SmolStr> {
/// A key with an established name.
Named(Named),
/// A key string that corresponds to the character typed by the user, taking into account the
/// users current locale setting, and any system-level keyboard mapping overrides that are in
/// effect.
Character(C),
/// An unidentified key.
Unidentified,
}
impl Key {
/// Convert `Key::Character(SmolStr)` to `Key::Character(&str)` so you can more easily match on
/// `Key`. All other variants remain unchanged.
pub fn as_ref(&self) -> Key<&str> {
match self {
Self::Named(named) => Key::Named(*named),
Self::Character(c) => Key::Character(c.as_ref()),
Self::Unidentified => Key::Unidentified,
}
}
}
/// A named key.
///
/// This is mostly the `NamedKey` type found in [`winit`].
///
/// [`winit`]: https://docs.rs/winit/0.29.10/winit/keyboard/enum.Key.html
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[allow(missing_docs)]
pub enum Named {
/// The `Alt` (Alternative) key.
///
/// This key enables the alternate modifier function for interpreting concurrent or subsequent
/// keyboard input. This key value is also used for the Apple <kbd>Option</kbd> key.
Alt,
/// The Alternate Graphics (<kbd>AltGr</kbd> or <kbd>AltGraph</kbd>) key.
///
/// This key is used enable the ISO Level 3 shift modifier (the standard `Shift` key is the
/// level 2 modifier).
AltGraph,
/// The `Caps Lock` (Capital) key.
///
/// Toggle capital character lock function for interpreting subsequent keyboard input event.
CapsLock,
/// The `Control` or `Ctrl` key.
///
/// Used to enable control modifier function for interpreting concurrent or subsequent keyboard
/// input.
Control,
/// The Function switch `Fn` key. Activating this key simultaneously with another key changes
/// that keys value to an alternate character or function. This key is often handled directly
/// in the keyboard hardware and does not usually generate key events.
Fn,
/// The Function-Lock (`FnLock` or `F-Lock`) key. Activating this key switches the mode of the
/// keyboard to changes some keys' values to an alternate character or function. This key is
/// often handled directly in the keyboard hardware and does not usually generate key events.
FnLock,
/// The `NumLock` or Number Lock key. Used to toggle numpad mode function for interpreting
/// subsequent keyboard input.
NumLock,
/// Toggle between scrolling and cursor movement modes.
ScrollLock,
/// Used to enable shift modifier function for interpreting concurrent or subsequent keyboard
/// input.
Shift,
/// The Symbol modifier key (used on some virtual keyboards).
Symbol,
SymbolLock,
// Legacy modifier key. Also called "Super" in certain places.
Meta,
// Legacy modifier key.
Hyper,
/// Used to enable "super" modifier function for interpreting concurrent or subsequent keyboard
/// input. This key value is used for the "Windows Logo" key and the Apple `Command` or `⌘` key.
///
/// Note: In some contexts (e.g. the Web) this is referred to as the "Meta" key.
Super,
/// The `Enter` or `↵` key. Used to activate current selection or accept current input. This key
/// value is also used for the `Return` (Macintosh numpad) key. This key value is also used for
/// the Android `KEYCODE_DPAD_CENTER`.
Enter,
/// The Horizontal Tabulation `Tab` key.
Tab,
/// Used in text to insert a space between words. Usually located below the character keys.
Space,
/// Navigate or traverse downward. (`KEYCODE_DPAD_DOWN`)
ArrowDown,
/// Navigate or traverse leftward. (`KEYCODE_DPAD_LEFT`)
ArrowLeft,
/// Navigate or traverse rightward. (`KEYCODE_DPAD_RIGHT`)
ArrowRight,
/// Navigate or traverse upward. (`KEYCODE_DPAD_UP`)
ArrowUp,
/// The End key, used with keyboard entry to go to the end of content (`KEYCODE_MOVE_END`).
End,
/// The Home key, used with keyboard entry, to go to start of content (`KEYCODE_MOVE_HOME`).
/// For the mobile phone `Home` key (which goes to the phones main screen), use [`GoHome`].
///
/// [`GoHome`]: Self::GoHome
Home,
/// Scroll down or display next page of content.
PageDown,
/// Scroll up or display previous page of content.
PageUp,
/// Used to remove the character to the left of the cursor. This key value is also used for
/// the key labeled `Delete` on MacOS keyboards.
Backspace,
/// Remove the currently selected input.
Clear,
/// Copy the current selection. (`APPCOMMAND_COPY`)
Copy,
/// The Cursor Select key.
CrSel,
/// Cut the current selection. (`APPCOMMAND_CUT`)
Cut,
/// Used to delete the character to the right of the cursor. This key value is also used for the
/// key labeled `Delete` on MacOS keyboards when `Fn` is active.
Delete,
/// The Erase to End of Field key. This key deletes all characters from the current cursor
/// position to the end of the current field.
EraseEof,
/// The Extend Selection (Exsel) key.
ExSel,
/// Toggle between text modes for insertion or overtyping.
/// (`KEYCODE_INSERT`)
Insert,
/// The Paste key. (`APPCOMMAND_PASTE`)
Paste,
/// Redo the last action. (`APPCOMMAND_REDO`)
Redo,
/// Undo the last action. (`APPCOMMAND_UNDO`)
Undo,
/// The Accept (Commit, OK) key. Accept current option or input method sequence conversion.
Accept,
/// Redo or repeat an action.
Again,
/// The Attention (Attn) key.
Attn,
Cancel,
/// Show the applications context menu.
/// This key is commonly found between the right `Super` key and the right `Control` key.
ContextMenu,
/// The `Esc` key. This key was originally used to initiate an escape sequence, but is
/// now more generally used to exit or "escape" the current context, such as closing a dialog
/// or exiting full screen mode.
Escape,
Execute,
/// Open the Find dialog. (`APPCOMMAND_FIND`)
Find,
/// Open a help dialog or toggle display of help information. (`APPCOMMAND_HELP`,
/// `KEYCODE_HELP`)
Help,
/// Pause the current state or application (as appropriate).
///
/// Note: Do not use this value for the `Pause` button on media controllers. Use `"MediaPause"`
/// instead.
Pause,
/// Play or resume the current state or application (as appropriate).
///
/// Note: Do not use this value for the `Play` button on media controllers. Use `"MediaPlay"`
/// instead.
Play,
/// The properties (Props) key.
Props,
Select,
/// The ZoomIn key. (`KEYCODE_ZOOM_IN`)
ZoomIn,
/// The ZoomOut key. (`KEYCODE_ZOOM_OUT`)
ZoomOut,
/// The Brightness Down key. Typically controls the display brightness.
/// (`KEYCODE_BRIGHTNESS_DOWN`)
BrightnessDown,
/// The Brightness Up key. Typically controls the display brightness. (`KEYCODE_BRIGHTNESS_UP`)
BrightnessUp,
/// Toggle removable media to eject (open) and insert (close) state. (`KEYCODE_MEDIA_EJECT`)
Eject,
LogOff,
/// Toggle power state. (`KEYCODE_POWER`)
/// Note: Note: Some devices might not expose this key to the operating environment.
Power,
/// The `PowerOff` key. Sometime called `PowerDown`.
PowerOff,
/// Initiate print-screen function.
PrintScreen,
/// The Hibernate key. This key saves the current state of the computer to disk so that it can
/// be restored. The computer will then shutdown.
Hibernate,
/// The Standby key. This key turns off the display and places the computer into a low-power
/// mode without completely shutting down. It is sometimes labelled `Suspend` or `Sleep` key.
/// (`KEYCODE_SLEEP`)
Standby,
/// The WakeUp key. (`KEYCODE_WAKEUP`)
WakeUp,
/// Initate the multi-candidate mode.
AllCandidates,
Alphanumeric,
/// Initiate the Code Input mode to allow characters to be entered by
/// their code points.
CodeInput,
/// The Compose key, also known as "Multi_key" on the X Window System. This key acts in a
/// manner similar to a dead key, triggering a mode where subsequent key presses are combined to
/// produce a different character.
Compose,
/// Convert the current input method sequence.
Convert,
/// The Final Mode `Final` key used on some Asian keyboards, to enable the final mode for IMEs.
FinalMode,
/// Switch to the first character group. (ISO/IEC 9995)
GroupFirst,
/// Switch to the last character group. (ISO/IEC 9995)
GroupLast,
/// Switch to the next character group. (ISO/IEC 9995)
GroupNext,
/// Switch to the previous character group. (ISO/IEC 9995)
GroupPrevious,
/// Toggle between or cycle through input modes of IMEs.
ModeChange,
NextCandidate,
/// Accept current input method sequence without
/// conversion in IMEs.
NonConvert,
PreviousCandidate,
Process,
SingleCandidate,
/// Toggle between Hangul and English modes.
HangulMode,
HanjaMode,
JunjaMode,
/// The Eisu key. This key may close the IME, but its purpose is defined by the current IME.
/// (`KEYCODE_EISU`)
Eisu,
/// The (Half-Width) Characters key.
Hankaku,
/// The Hiragana (Japanese Kana characters) key.
Hiragana,
/// The Hiragana/Katakana toggle key. (`KEYCODE_KATAKANA_HIRAGANA`)
HiraganaKatakana,
/// The Kana Mode (Kana Lock) key. This key is used to enter hiragana mode (typically from
/// romaji mode).
KanaMode,
/// The Kanji (Japanese name for ideographic characters of Chinese origin) Mode key. This key is
/// typically used to switch to a hiragana keyboard for the purpose of converting input into
/// kanji. (`KEYCODE_KANA`)
KanjiMode,
/// The Katakana (Japanese Kana characters) key.
Katakana,
/// The Roman characters function key.
Romaji,
/// The Zenkaku (Full-Width) Characters key.
Zenkaku,
/// The Zenkaku/Hankaku (full-width/half-width) toggle key. (`KEYCODE_ZENKAKU_HANKAKU`)
ZenkakuHankaku,
/// General purpose virtual function key, as index 1.
Soft1,
/// General purpose virtual function key, as index 2.
Soft2,
/// General purpose virtual function key, as index 3.
Soft3,
/// General purpose virtual function key, as index 4.
Soft4,
/// Select next (numerically or logically) lower channel. (`APPCOMMAND_MEDIA_CHANNEL_DOWN`,
/// `KEYCODE_CHANNEL_DOWN`)
ChannelDown,
/// Select next (numerically or logically) higher channel. (`APPCOMMAND_MEDIA_CHANNEL_UP`,
/// `KEYCODE_CHANNEL_UP`)
ChannelUp,
/// Close the current document or message (Note: This doesnt close the application).
/// (`APPCOMMAND_CLOSE`)
Close,
/// Open an editor to forward the current message. (`APPCOMMAND_FORWARD_MAIL`)
MailForward,
/// Open an editor to reply to the current message. (`APPCOMMAND_REPLY_TO_MAIL`)
MailReply,
/// Send the current message. (`APPCOMMAND_SEND_MAIL`)
MailSend,
/// Close the current media, for example to close a CD or DVD tray. (`KEYCODE_MEDIA_CLOSE`)
MediaClose,
/// Initiate or continue forward playback at faster than normal speed, or increase speed if
/// already fast forwarding. (`APPCOMMAND_MEDIA_FAST_FORWARD`, `KEYCODE_MEDIA_FAST_FORWARD`)
MediaFastForward,
/// Pause the currently playing media. (`APPCOMMAND_MEDIA_PAUSE`, `KEYCODE_MEDIA_PAUSE`)
///
/// Note: Media controller devices should use this value rather than `"Pause"` for their pause
/// keys.
MediaPause,
/// Initiate or continue media playback at normal speed, if not currently playing at normal
/// speed. (`APPCOMMAND_MEDIA_PLAY`, `KEYCODE_MEDIA_PLAY`)
MediaPlay,
/// Toggle media between play and pause states. (`APPCOMMAND_MEDIA_PLAY_PAUSE`,
/// `KEYCODE_MEDIA_PLAY_PAUSE`)
MediaPlayPause,
/// Initiate or resume recording of currently selected media. (`APPCOMMAND_MEDIA_RECORD`,
/// `KEYCODE_MEDIA_RECORD`)
MediaRecord,
/// Initiate or continue reverse playback at faster than normal speed, or increase speed if
/// already rewinding. (`APPCOMMAND_MEDIA_REWIND`, `KEYCODE_MEDIA_REWIND`)
MediaRewind,
/// Stop media playing, pausing, forwarding, rewinding, or recording, if not already stopped.
/// (`APPCOMMAND_MEDIA_STOP`, `KEYCODE_MEDIA_STOP`)
MediaStop,
/// Seek to next media or program track. (`APPCOMMAND_MEDIA_NEXTTRACK`, `KEYCODE_MEDIA_NEXT`)
MediaTrackNext,
/// Seek to previous media or program track. (`APPCOMMAND_MEDIA_PREVIOUSTRACK`,
/// `KEYCODE_MEDIA_PREVIOUS`)
MediaTrackPrevious,
/// Open a new document or message. (`APPCOMMAND_NEW`)
New,
/// Open an existing document or message. (`APPCOMMAND_OPEN`)
Open,
/// Print the current document or message. (`APPCOMMAND_PRINT`)
Print,
/// Save the current document or message. (`APPCOMMAND_SAVE`)
Save,
/// Spellcheck the current document or selection. (`APPCOMMAND_SPELL_CHECK`)
SpellCheck,
/// The `11` key found on media numpads that
/// have buttons from `1` ... `12`.
Key11,
/// The `12` key found on media numpads that
/// have buttons from `1` ... `12`.
Key12,
/// Adjust audio balance leftward. (`VK_AUDIO_BALANCE_LEFT`)
AudioBalanceLeft,
/// Adjust audio balance rightward. (`VK_AUDIO_BALANCE_RIGHT`)
AudioBalanceRight,
/// Decrease audio bass boost or cycle down through bass boost states. (`APPCOMMAND_BASS_DOWN`,
/// `VK_BASS_BOOST_DOWN`)
AudioBassBoostDown,
/// Toggle bass boost on/off. (`APPCOMMAND_BASS_BOOST`)
AudioBassBoostToggle,
/// Increase audio bass boost or cycle up through bass boost states. (`APPCOMMAND_BASS_UP`,
/// `VK_BASS_BOOST_UP`)
AudioBassBoostUp,
/// Adjust audio fader towards front. (`VK_FADER_FRONT`)
AudioFaderFront,
/// Adjust audio fader towards rear. (`VK_FADER_REAR`)
AudioFaderRear,
/// Advance surround audio mode to next available mode. (`VK_SURROUND_MODE_NEXT`)
AudioSurroundModeNext,
/// Decrease treble. (`APPCOMMAND_TREBLE_DOWN`)
AudioTrebleDown,
/// Increase treble. (`APPCOMMAND_TREBLE_UP`)
AudioTrebleUp,
/// Decrease audio volume. (`APPCOMMAND_VOLUME_DOWN`, `KEYCODE_VOLUME_DOWN`)
AudioVolumeDown,
/// Increase audio volume. (`APPCOMMAND_VOLUME_UP`, `KEYCODE_VOLUME_UP`)
AudioVolumeUp,
/// Toggle between muted state and prior volume level. (`APPCOMMAND_VOLUME_MUTE`,
/// `KEYCODE_VOLUME_MUTE`)
AudioVolumeMute,
/// Toggle the microphone on/off. (`APPCOMMAND_MIC_ON_OFF_TOGGLE`)
MicrophoneToggle,
/// Decrease microphone volume. (`APPCOMMAND_MICROPHONE_VOLUME_DOWN`)
MicrophoneVolumeDown,
/// Increase microphone volume. (`APPCOMMAND_MICROPHONE_VOLUME_UP`)
MicrophoneVolumeUp,
/// Mute the microphone. (`APPCOMMAND_MICROPHONE_VOLUME_MUTE`, `KEYCODE_MUTE`)
MicrophoneVolumeMute,
/// Show correction list when a word is incorrectly identified. (`APPCOMMAND_CORRECTION_LIST`)
SpeechCorrectionList,
/// Toggle between dictation mode and command/control mode.
/// (`APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE`)
SpeechInputToggle,
/// The first generic "LaunchApplication" key. This is commonly associated with launching "My
/// Computer", and may have a computer symbol on the key. (`APPCOMMAND_LAUNCH_APP1`)
LaunchApplication1,
/// The second generic "LaunchApplication" key. This is commonly associated with launching
/// "Calculator", and may have a calculator symbol on the key. (`APPCOMMAND_LAUNCH_APP2`,
/// `KEYCODE_CALCULATOR`)
LaunchApplication2,
/// The "Calendar" key. (`KEYCODE_CALENDAR`)
LaunchCalendar,
/// The "Contacts" key. (`KEYCODE_CONTACTS`)
LaunchContacts,
/// The "Mail" key. (`APPCOMMAND_LAUNCH_MAIL`)
LaunchMail,
/// The "Media Player" key. (`APPCOMMAND_LAUNCH_MEDIA_SELECT`)
LaunchMediaPlayer,
LaunchMusicPlayer,
LaunchPhone,
LaunchScreenSaver,
LaunchSpreadsheet,
LaunchWebBrowser,
LaunchWebCam,
LaunchWordProcessor,
/// Navigate to previous content or page in current history. (`APPCOMMAND_BROWSER_BACKWARD`)
BrowserBack,
/// Open the list of browser favorites. (`APPCOMMAND_BROWSER_FAVORITES`)
BrowserFavorites,
/// Navigate to next content or page in current history. (`APPCOMMAND_BROWSER_FORWARD`)
BrowserForward,
/// Go to the users preferred home page. (`APPCOMMAND_BROWSER_HOME`)
BrowserHome,
/// Refresh the current page or content. (`APPCOMMAND_BROWSER_REFRESH`)
BrowserRefresh,
/// Call up the users preferred search page. (`APPCOMMAND_BROWSER_SEARCH`)
BrowserSearch,
/// Stop loading the current page or content. (`APPCOMMAND_BROWSER_STOP`)
BrowserStop,
/// The Application switch key, which provides a list of recent apps to switch between.
/// (`KEYCODE_APP_SWITCH`)
AppSwitch,
/// The Call key. (`KEYCODE_CALL`)
Call,
/// The Camera key. (`KEYCODE_CAMERA`)
Camera,
/// The Camera focus key. (`KEYCODE_FOCUS`)
CameraFocus,
/// The End Call key. (`KEYCODE_ENDCALL`)
EndCall,
/// The Back key. (`KEYCODE_BACK`)
GoBack,
/// The Home key, which goes to the phones main screen. (`KEYCODE_HOME`)
GoHome,
/// The Headset Hook key. (`KEYCODE_HEADSETHOOK`)
HeadsetHook,
LastNumberRedial,
/// The Notification key. (`KEYCODE_NOTIFICATION`)
Notification,
/// Toggle between manner mode state: silent, vibrate, ring, ... (`KEYCODE_MANNER_MODE`)
MannerMode,
VoiceDial,
/// Switch to viewing TV. (`KEYCODE_TV`)
TV,
/// TV 3D Mode. (`KEYCODE_3D_MODE`)
TV3DMode,
/// Toggle between antenna and cable input. (`KEYCODE_TV_ANTENNA_CABLE`)
TVAntennaCable,
/// Audio description. (`KEYCODE_TV_AUDIO_DESCRIPTION`)
TVAudioDescription,
/// Audio description mixing volume down. (`KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN`)
TVAudioDescriptionMixDown,
/// Audio description mixing volume up. (`KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP`)
TVAudioDescriptionMixUp,
/// Contents menu. (`KEYCODE_TV_CONTENTS_MENU`)
TVContentsMenu,
/// Contents menu. (`KEYCODE_TV_DATA_SERVICE`)
TVDataService,
/// Switch the input mode on an external TV. (`KEYCODE_TV_INPUT`)
TVInput,
/// Switch to component input #1. (`KEYCODE_TV_INPUT_COMPONENT_1`)
TVInputComponent1,
/// Switch to component input #2. (`KEYCODE_TV_INPUT_COMPONENT_2`)
TVInputComponent2,
/// Switch to composite input #1. (`KEYCODE_TV_INPUT_COMPOSITE_1`)
TVInputComposite1,
/// Switch to composite input #2. (`KEYCODE_TV_INPUT_COMPOSITE_2`)
TVInputComposite2,
/// Switch to HDMI input #1. (`KEYCODE_TV_INPUT_HDMI_1`)
TVInputHDMI1,
/// Switch to HDMI input #2. (`KEYCODE_TV_INPUT_HDMI_2`)
TVInputHDMI2,
/// Switch to HDMI input #3. (`KEYCODE_TV_INPUT_HDMI_3`)
TVInputHDMI3,
/// Switch to HDMI input #4. (`KEYCODE_TV_INPUT_HDMI_4`)
TVInputHDMI4,
/// Switch to VGA input #1. (`KEYCODE_TV_INPUT_VGA_1`)
TVInputVGA1,
/// Media context menu. (`KEYCODE_TV_MEDIA_CONTEXT_MENU`)
TVMediaContext,
/// Toggle network. (`KEYCODE_TV_NETWORK`)
TVNetwork,
/// Number entry. (`KEYCODE_TV_NUMBER_ENTRY`)
TVNumberEntry,
/// Toggle the power on an external TV. (`KEYCODE_TV_POWER`)
TVPower,
/// Radio. (`KEYCODE_TV_RADIO_SERVICE`)
TVRadioService,
/// Satellite. (`KEYCODE_TV_SATELLITE`)
TVSatellite,
/// Broadcast Satellite. (`KEYCODE_TV_SATELLITE_BS`)
TVSatelliteBS,
/// Communication Satellite. (`KEYCODE_TV_SATELLITE_CS`)
TVSatelliteCS,
/// Toggle between available satellites. (`KEYCODE_TV_SATELLITE_SERVICE`)
TVSatelliteToggle,
/// Analog Terrestrial. (`KEYCODE_TV_TERRESTRIAL_ANALOG`)
TVTerrestrialAnalog,
/// Digital Terrestrial. (`KEYCODE_TV_TERRESTRIAL_DIGITAL`)
TVTerrestrialDigital,
/// Timer programming. (`KEYCODE_TV_TIMER_PROGRAMMING`)
TVTimer,
/// Switch the input mode on an external AVR (audio/video receiver). (`KEYCODE_AVR_INPUT`)
AVRInput,
/// Toggle the power on an external AVR (audio/video receiver). (`KEYCODE_AVR_POWER`)
AVRPower,
/// General purpose color-coded media function key, as index 0 (red). (`VK_COLORED_KEY_0`,
/// `KEYCODE_PROG_RED`)
ColorF0Red,
/// General purpose color-coded media function key, as index 1 (green). (`VK_COLORED_KEY_1`,
/// `KEYCODE_PROG_GREEN`)
ColorF1Green,
/// General purpose color-coded media function key, as index 2 (yellow). (`VK_COLORED_KEY_2`,
/// `KEYCODE_PROG_YELLOW`)
ColorF2Yellow,
/// General purpose color-coded media function key, as index 3 (blue). (`VK_COLORED_KEY_3`,
/// `KEYCODE_PROG_BLUE`)
ColorF3Blue,
/// General purpose color-coded media function key, as index 4 (grey). (`VK_COLORED_KEY_4`)
ColorF4Grey,
/// General purpose color-coded media function key, as index 5 (brown). (`VK_COLORED_KEY_5`)
ColorF5Brown,
/// Toggle the display of Closed Captions. (`VK_CC`, `KEYCODE_CAPTIONS`)
ClosedCaptionToggle,
/// Adjust brightness of device, by toggling between or cycling through states. (`VK_DIMMER`)
Dimmer,
/// Swap video sources. (`VK_DISPLAY_SWAP`)
DisplaySwap,
/// Select Digital Video Rrecorder. (`KEYCODE_DVR`)
DVR,
/// Exit the current application. (`VK_EXIT`)
Exit,
/// Clear program or content stored as favorite 0. (`VK_CLEAR_FAVORITE_0`)
FavoriteClear0,
/// Clear program or content stored as favorite 1. (`VK_CLEAR_FAVORITE_1`)
FavoriteClear1,
/// Clear program or content stored as favorite 2. (`VK_CLEAR_FAVORITE_2`)
FavoriteClear2,
/// Clear program or content stored as favorite 3. (`VK_CLEAR_FAVORITE_3`)
FavoriteClear3,
/// Select (recall) program or content stored as favorite 0. (`VK_RECALL_FAVORITE_0`)
FavoriteRecall0,
/// Select (recall) program or content stored as favorite 1. (`VK_RECALL_FAVORITE_1`)
FavoriteRecall1,
/// Select (recall) program or content stored as favorite 2. (`VK_RECALL_FAVORITE_2`)
FavoriteRecall2,
/// Select (recall) program or content stored as favorite 3. (`VK_RECALL_FAVORITE_3`)
FavoriteRecall3,
/// Store current program or content as favorite 0. (`VK_STORE_FAVORITE_0`)
FavoriteStore0,
/// Store current program or content as favorite 1. (`VK_STORE_FAVORITE_1`)
FavoriteStore1,
/// Store current program or content as favorite 2. (`VK_STORE_FAVORITE_2`)
FavoriteStore2,
/// Store current program or content as favorite 3. (`VK_STORE_FAVORITE_3`)
FavoriteStore3,
/// Toggle display of program or content guide. (`VK_GUIDE`, `KEYCODE_GUIDE`)
Guide,
/// If guide is active and displayed, then display next days content. (`VK_NEXT_DAY`)
GuideNextDay,
/// If guide is active and displayed, then display previous days content. (`VK_PREV_DAY`)
GuidePreviousDay,
/// Toggle display of information about currently selected context or media. (`VK_INFO`,
/// `KEYCODE_INFO`)
Info,
/// Toggle instant replay. (`VK_INSTANT_REPLAY`)
InstantReplay,
/// Launch linked content, if available and appropriate. (`VK_LINK`)
Link,
/// List the current program. (`VK_LIST`)
ListProgram,
/// Toggle display listing of currently available live content or programs. (`VK_LIVE`)
LiveContent,
/// Lock or unlock current content or program. (`VK_LOCK`)
Lock,
/// Show a list of media applications: audio/video players and image viewers. (`VK_APPS`)
///
/// Note: Do not confuse this key value with the Windows' `VK_APPS` / `VK_CONTEXT_MENU` key,
/// which is encoded as `"ContextMenu"`.
MediaApps,
/// Audio track key. (`KEYCODE_MEDIA_AUDIO_TRACK`)
MediaAudioTrack,
/// Select previously selected channel or media. (`VK_LAST`, `KEYCODE_LAST_CHANNEL`)
MediaLast,
/// Skip backward to next content or program. (`KEYCODE_MEDIA_SKIP_BACKWARD`)
MediaSkipBackward,
/// Skip forward to next content or program. (`VK_SKIP`, `KEYCODE_MEDIA_SKIP_FORWARD`)
MediaSkipForward,
/// Step backward to next content or program. (`KEYCODE_MEDIA_STEP_BACKWARD`)
MediaStepBackward,
/// Step forward to next content or program. (`KEYCODE_MEDIA_STEP_FORWARD`)
MediaStepForward,
/// Media top menu. (`KEYCODE_MEDIA_TOP_MENU`)
MediaTopMenu,
/// Navigate in. (`KEYCODE_NAVIGATE_IN`)
NavigateIn,
/// Navigate to next key. (`KEYCODE_NAVIGATE_NEXT`)
NavigateNext,
/// Navigate out. (`KEYCODE_NAVIGATE_OUT`)
NavigateOut,
/// Navigate to previous key. (`KEYCODE_NAVIGATE_PREVIOUS`)
NavigatePrevious,
/// Cycle to next favorite channel (in favorites list). (`VK_NEXT_FAVORITE_CHANNEL`)
NextFavoriteChannel,
/// Cycle to next user profile (if there are multiple user profiles). (`VK_USER`)
NextUserProfile,
/// Access on-demand content or programs. (`VK_ON_DEMAND`)
OnDemand,
/// Pairing key to pair devices. (`KEYCODE_PAIRING`)
Pairing,
/// Move picture-in-picture window down. (`VK_PINP_DOWN`)
PinPDown,
/// Move picture-in-picture window. (`VK_PINP_MOVE`)
PinPMove,
/// Toggle display of picture-in-picture window. (`VK_PINP_TOGGLE`)
PinPToggle,
/// Move picture-in-picture window up. (`VK_PINP_UP`)
PinPUp,
/// Decrease media playback speed. (`VK_PLAY_SPEED_DOWN`)
PlaySpeedDown,
/// Reset playback to normal speed. (`VK_PLAY_SPEED_RESET`)
PlaySpeedReset,
/// Increase media playback speed. (`VK_PLAY_SPEED_UP`)
PlaySpeedUp,
/// Toggle random media or content shuffle mode. (`VK_RANDOM_TOGGLE`)
RandomToggle,
/// Not a physical key, but this key code is sent when the remote control battery is low.
/// (`VK_RC_LOW_BATTERY`)
RcLowBattery,
/// Toggle or cycle between media recording speeds. (`VK_RECORD_SPEED_NEXT`)
RecordSpeedNext,
/// Toggle RF (radio frequency) input bypass mode (pass RF input directly to the RF output).
/// (`VK_RF_BYPASS`)
RfBypass,
/// Toggle scan channels mode. (`VK_SCAN_CHANNELS_TOGGLE`)
ScanChannelsToggle,
/// Advance display screen mode to next available mode. (`VK_SCREEN_MODE_NEXT`)
ScreenModeNext,
/// Toggle display of device settings screen. (`VK_SETTINGS`, `KEYCODE_SETTINGS`)
Settings,
/// Toggle split screen mode. (`VK_SPLIT_SCREEN_TOGGLE`)
SplitScreenToggle,
/// Switch the input mode on an external STB (set top box). (`KEYCODE_STB_INPUT`)
STBInput,
/// Toggle the power on an external STB (set top box). (`KEYCODE_STB_POWER`)
STBPower,
/// Toggle display of subtitles, if available. (`VK_SUBTITLE`)
Subtitle,
/// Toggle display of teletext, if available (`VK_TELETEXT`, `KEYCODE_TV_TELETEXT`).
Teletext,
/// Advance video mode to next available mode. (`VK_VIDEO_MODE_NEXT`)
VideoModeNext,
/// Cause device to identify itself in some manner, e.g., audibly or visibly. (`VK_WINK`)
Wink,
/// Toggle between full-screen and scaled content, or alter magnification level. (`VK_ZOOM`,
/// `KEYCODE_TV_ZOOM_MODE`)
ZoomToggle,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F1,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F2,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F3,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F4,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F5,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F6,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F7,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F8,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F9,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F10,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F11,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F12,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F13,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F14,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F15,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F16,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F17,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F18,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F19,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F20,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F21,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F22,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F23,
/// General-purpose function key.
/// Usually found at the top of the keyboard.
F24,
/// General-purpose function key.
F25,
/// General-purpose function key.
F26,
/// General-purpose function key.
F27,
/// General-purpose function key.
F28,
/// General-purpose function key.
F29,
/// General-purpose function key.
F30,
/// General-purpose function key.
F31,
/// General-purpose function key.
F32,
/// General-purpose function key.
F33,
/// General-purpose function key.
F34,
/// General-purpose function key.
F35,
}

View file

@ -1,203 +0,0 @@
/// The symbolic name of a keyboard key.
///
/// This is mostly the `KeyCode` type found in [`winit`].
///
/// [`winit`]: https://docs.rs/winit/0.20.0-alpha3/winit/
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
#[repr(u32)]
#[allow(missing_docs)]
pub enum KeyCode {
/// The '1' key over the letters.
Key1,
/// The '2' key over the letters.
Key2,
/// The '3' key over the letters.
Key3,
/// The '4' key over the letters.
Key4,
/// The '5' key over the letters.
Key5,
/// The '6' key over the letters.
Key6,
/// The '7' key over the letters.
Key7,
/// The '8' key over the letters.
Key8,
/// The '9' key over the letters.
Key9,
/// The '0' key over the 'O' and 'P' keys.
Key0,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
/// The Escape key, next to F1.
Escape,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
/// Print Screen/SysRq.
Snapshot,
/// Scroll Lock.
Scroll,
/// Pause/Break key, next to Scroll lock.
Pause,
/// `Insert`, next to Backspace.
Insert,
Home,
Delete,
End,
PageDown,
PageUp,
Left,
Up,
Right,
Down,
/// The Backspace key, right over Enter.
Backspace,
/// The Enter key.
Enter,
/// The space bar.
Space,
/// The "Compose" key on Linux.
Compose,
Caret,
Numlock,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
NumpadAdd,
NumpadDivide,
NumpadDecimal,
NumpadComma,
NumpadEnter,
NumpadEquals,
NumpadMultiply,
NumpadSubtract,
AbntC1,
AbntC2,
Apostrophe,
Apps,
Asterisk,
At,
Ax,
Backslash,
Calculator,
Capital,
Colon,
Comma,
Convert,
Equals,
Grave,
Kana,
Kanji,
LAlt,
LBracket,
LControl,
LShift,
LWin,
Mail,
MediaSelect,
MediaStop,
Minus,
Mute,
MyComputer,
NavigateForward, // also called "Next"
NavigateBackward, // also called "Prior"
NextTrack,
NoConvert,
OEM102,
Period,
PlayPause,
Plus,
Power,
PrevTrack,
RAlt,
RBracket,
RControl,
RShift,
RWin,
Semicolon,
Slash,
Sleep,
Stop,
Sysrq,
Tab,
Underline,
Unlabeled,
VolumeDown,
VolumeUp,
Wake,
WebBack,
WebFavorites,
WebForward,
WebHome,
WebRefresh,
WebSearch,
WebStop,
Yen,
Copy,
Paste,
Cut,
}

View file

@ -0,0 +1,12 @@
/// The location of a key on the keyboard.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Location {
/// The standard group of keys on the keyboard.
Standard,
/// The left side of the keyboard.
Left,
/// The right side of the keyboard.
Right,
/// The numpad of the keyboard.
Numpad,
}

View file

@ -134,8 +134,8 @@ impl Application for Editor {
}
fn subscription(&self) -> Subscription<Message> {
keyboard::on_key_press(|key_code, modifiers| match key_code {
keyboard::KeyCode::S if modifiers.command() => {
keyboard::on_key_press(|key, modifiers| match key.as_ref() {
keyboard::Key::Character("s") if modifiers.command() => {
Some(Message::SaveFile)
}
_ => None,

View file

@ -278,7 +278,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// Map window event to iced event
if let Some(event) = iced_winit::conversion::window_event(
window::Id::MAIN,
&event,
event,
window.scale_factor(),
modifiers,
) {

View file

@ -71,9 +71,13 @@ impl Application for Layout {
}
fn subscription(&self) -> Subscription<Message> {
keyboard::on_key_release(|key_code, _modifiers| match key_code {
keyboard::KeyCode::Left => Some(Message::Previous),
keyboard::KeyCode::Right => Some(Message::Next),
use keyboard::key;
keyboard::on_key_release(|key, _modifiers| match key {
keyboard::Key::Named(key::Named::ArrowLeft) => {
Some(Message::Previous)
}
keyboard::Key::Named(key::Named::ArrowRight) => Some(Message::Next),
_ => None,
})
}

View file

@ -1,6 +1,7 @@
use iced::event::{self, Event};
use iced::executor;
use iced::keyboard;
use iced::keyboard::key;
use iced::theme;
use iced::widget::{
self, button, column, container, horizontal_space, pick_list, row, text,
@ -85,7 +86,7 @@ impl Application for App {
}
Message::Event(event) => match event {
Event::Keyboard(keyboard::Event::KeyPressed {
key_code: keyboard::KeyCode::Tab,
key: keyboard::Key::Named(key::Named::Tab),
modifiers,
..
}) => {
@ -96,7 +97,7 @@ impl Application for App {
}
}
Event::Keyboard(keyboard::Event::KeyPressed {
key_code: keyboard::KeyCode::Escape,
key: keyboard::Key::Named(key::Named::Escape),
..
}) => {
self.hide_modal();

View file

@ -220,23 +220,26 @@ const PANE_ID_COLOR_FOCUSED: Color = Color::from_rgb(
0x47 as f32 / 255.0,
);
fn handle_hotkey(key_code: keyboard::KeyCode) -> Option<Message> {
use keyboard::KeyCode;
fn handle_hotkey(key: keyboard::Key) -> Option<Message> {
use keyboard::key::{self, Key};
use pane_grid::{Axis, Direction};
let direction = match key_code {
KeyCode::Up => Some(Direction::Up),
KeyCode::Down => Some(Direction::Down),
KeyCode::Left => Some(Direction::Left),
KeyCode::Right => Some(Direction::Right),
_ => None,
};
match key.as_ref() {
Key::Character("v") => Some(Message::SplitFocused(Axis::Vertical)),
Key::Character("h") => Some(Message::SplitFocused(Axis::Horizontal)),
Key::Character("w") => Some(Message::CloseFocused),
Key::Named(key) => {
let direction = match key {
key::Named::ArrowUp => Some(Direction::Up),
key::Named::ArrowDown => Some(Direction::Down),
key::Named::ArrowLeft => Some(Direction::Left),
key::Named::ArrowRight => Some(Direction::Right),
_ => None,
};
match key_code {
KeyCode::V => Some(Message::SplitFocused(Axis::Vertical)),
KeyCode::H => Some(Message::SplitFocused(Axis::Horizontal)),
KeyCode::W => Some(Message::CloseFocused),
_ => direction.map(Message::FocusAdjacent),
direction.map(Message::FocusAdjacent)
}
_ => None,
}
}

View file

@ -1,11 +1,13 @@
use iced::keyboard::KeyCode;
use iced::theme::{Button, Container};
use iced::alignment;
use iced::executor;
use iced::keyboard;
use iced::theme;
use iced::widget::{button, column, container, image, row, text, text_input};
use iced::window;
use iced::window::screenshot::{self, Screenshot};
use iced::{alignment, window};
use iced::{
event, executor, keyboard, Alignment, Application, Command, ContentFit,
Element, Event, Length, Rectangle, Renderer, Subscription, Theme,
Alignment, Application, Command, ContentFit, Element, Length, Rectangle,
Renderer, Subscription, Theme,
};
use ::image as img;
@ -147,7 +149,7 @@ impl Application for Example {
let image = container(image)
.padding(10)
.style(Container::Box)
.style(theme::Container::Box)
.width(Length::FillPortion(2))
.height(Length::Fill)
.center_x()
@ -202,9 +204,10 @@ impl Application for Example {
self.screenshot.is_some().then(|| Message::Png),
)
} else {
button(centered_text("Saving...")).style(Button::Secondary)
button(centered_text("Saving..."))
.style(theme::Button::Secondary)
}
.style(Button::Secondary)
.style(theme::Button::Secondary)
.padding([10, 20, 10, 20])
.width(Length::Fill)
]
@ -213,7 +216,7 @@ impl Application for Example {
crop_controls,
button(centered_text("Crop"))
.on_press(Message::Crop)
.style(Button::Destructive)
.style(theme::Button::Destructive)
.padding([10, 20, 10, 20])
.width(Length::Fill),
]
@ -256,16 +259,10 @@ impl Application for Example {
}
fn subscription(&self) -> Subscription<Self::Message> {
event::listen_with(|event, status| {
if let event::Status::Captured = status {
return None;
}
use keyboard::key;
if let Event::Keyboard(keyboard::Event::KeyPressed {
key_code: KeyCode::F5,
..
}) = event
{
keyboard::on_key_press(|key, _modifiers| {
if let keyboard::Key::Named(key::Named::F5) = key {
Some(Message::Screenshot)
} else {
None

View file

@ -86,12 +86,16 @@ impl Application for Stopwatch {
};
fn handle_hotkey(
key_code: keyboard::KeyCode,
key: keyboard::Key,
_modifiers: keyboard::Modifiers,
) -> Option<Message> {
match key_code {
keyboard::KeyCode::Space => Some(Message::Toggle),
keyboard::KeyCode::R => Some(Message::Reset),
use keyboard::key;
match key.as_ref() {
keyboard::Key::Named(key::Named::Space) => {
Some(Message::Toggle)
}
keyboard::Key::Character("r") => Some(Message::Reset),
_ => None,
}
}

View file

@ -1,6 +1,7 @@
use iced::event::{self, Event};
use iced::executor;
use iced::keyboard;
use iced::keyboard::key;
use iced::widget::{
self, button, column, container, pick_list, row, slider, text, text_input,
};
@ -93,12 +94,12 @@ impl Application for App {
Command::none()
}
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
key_code: keyboard::KeyCode::Tab,
key: keyboard::Key::Named(key::Named::Tab),
modifiers,
..
})) if modifiers.shift() => widget::focus_previous(),
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
key_code: keyboard::KeyCode::Tab,
key: keyboard::Key::Named(key::Named::Tab),
..
})) => widget::focus_next(),
Message::Event(_) => Command::none(),

View file

@ -260,15 +260,21 @@ impl Application for Todos {
}
fn subscription(&self) -> Subscription<Message> {
keyboard::on_key_press(|key_code, modifiers| {
match (key_code, modifiers) {
(keyboard::KeyCode::Tab, _) => Some(Message::TabPressed {
use keyboard::key;
keyboard::on_key_press(|key, modifiers| {
let keyboard::Key::Named(key) = key else {
return None;
};
match (key, modifiers) {
(key::Named::Tab, _) => Some(Message::TabPressed {
shift: modifiers.shift(),
}),
(keyboard::KeyCode::Up, keyboard::Modifiers::SHIFT) => {
(key::Named::ArrowUp, keyboard::Modifiers::SHIFT) => {
Some(Message::ToggleFullscreen(window::Mode::Fullscreen))
}
(keyboard::KeyCode::Down, keyboard::Modifiers::SHIFT) => {
(key::Named::ArrowDown, keyboard::Modifiers::SHIFT) => {
Some(Message::ToggleFullscreen(window::Mode::Windowed))
}
_ => None,

View file

@ -1,6 +1,6 @@
//! Listen to keyboard events.
use crate::core;
use crate::core::keyboard::{Event, KeyCode, Modifiers};
use crate::core::keyboard::{Event, Key, Modifiers};
use crate::subscription::{self, Subscription};
use crate::MaybeSend;
@ -10,7 +10,7 @@ use crate::MaybeSend;
/// If the function returns `None`, the key press will be simply
/// ignored.
pub fn on_key_press<Message>(
f: fn(KeyCode, Modifiers) -> Option<Message>,
f: fn(Key, Modifiers) -> Option<Message>,
) -> Subscription<Message>
where
Message: MaybeSend + 'static,
@ -22,12 +22,10 @@ where
match (event, status) {
(
core::Event::Keyboard(Event::KeyPressed {
key_code,
modifiers,
..
key, modifiers, ..
}),
core::event::Status::Ignored,
) => f(key_code, modifiers),
) => f(key, modifiers),
_ => None,
}
})
@ -39,7 +37,7 @@ where
/// If the function returns `None`, the key release will be simply
/// ignored.
pub fn on_key_release<Message>(
f: fn(KeyCode, Modifiers) -> Option<Message>,
f: fn(Key, Modifiers) -> Option<Message>,
) -> Subscription<Message>
where
Message: MaybeSend + 'static,
@ -51,11 +49,12 @@ where
match (event, status) {
(
core::Event::Keyboard(Event::KeyReleased {
key_code,
key,
modifiers,
..
}),
core::event::Status::Ignored,
) => f(key_code, modifiers),
) => f(key, modifiers),
_ => None,
}
})

View file

@ -230,7 +230,8 @@ pub mod event {
pub mod keyboard {
//! Listen and react to keyboard events.
pub use crate::core::keyboard::{Event, KeyCode, Modifiers};
pub use crate::core::keyboard::key;
pub use crate::core::keyboard::{Event, Key, Location, Modifiers};
pub use iced_futures::keyboard::{on_key_press, on_key_release};
}

View file

@ -1,6 +1,7 @@
//! Display a dropdown list of searchable and selectable options.
use crate::core::event::{self, Event};
use crate::core::keyboard;
use crate::core::keyboard::key;
use crate::core::layout::{self, Layout};
use crate::core::mouse;
use crate::core::overlay;
@ -436,14 +437,14 @@ where
}
if let Event::Keyboard(keyboard::Event::KeyPressed {
key_code,
key: keyboard::Key::Named(named_key),
modifiers,
..
}) = event
{
let shift_modifer = modifiers.shift();
match (key_code, shift_modifer) {
(keyboard::KeyCode::Enter, _) => {
match (named_key, shift_modifer) {
(key::Named::Enter, _) => {
if let Some(index) = &menu.hovered_option {
if let Some(option) =
state.filtered_options.options.get(*index)
@ -455,8 +456,7 @@ where
event_status = event::Status::Captured;
}
(keyboard::KeyCode::Up, _)
| (keyboard::KeyCode::Tab, true) => {
(key::Named::ArrowUp, _) | (key::Named::Tab, true) => {
if let Some(index) = &mut menu.hovered_option {
if *index == 0 {
*index = state
@ -492,8 +492,8 @@ where
event_status = event::Status::Captured;
}
(keyboard::KeyCode::Down, _)
| (keyboard::KeyCode::Tab, false)
(key::Named::ArrowDown, _)
| (key::Named::Tab, false)
if !modifiers.shift() =>
{
if let Some(index) = &mut menu.hovered_option {

View file

@ -1,6 +1,7 @@
//! Display a multi-line text input for text editing.
use crate::core::event::{self, Event};
use crate::core::keyboard;
use crate::core::keyboard::key;
use crate::core::layout::{self, Layout};
use crate::core::mouse;
use crate::core::renderer;
@ -646,34 +647,48 @@ impl Update {
},
Event::Keyboard(event) => match event {
keyboard::Event::KeyPressed {
key_code,
key,
modifiers,
text,
..
} if state.is_focused => {
if let Some(motion) = motion(key_code) {
let motion =
if platform::is_jump_modifier_pressed(modifiers) {
if let keyboard::Key::Named(named_key) = key.as_ref() {
if let Some(motion) = motion(named_key) {
let motion = if platform::is_jump_modifier_pressed(
modifiers,
) {
motion.widen()
} else {
motion
};
return action(if modifiers.shift() {
Action::Select(motion)
} else {
Action::Move(motion)
});
return action(if modifiers.shift() {
Action::Select(motion)
} else {
Action::Move(motion)
});
}
}
match key_code {
keyboard::KeyCode::Enter => edit(Edit::Enter),
keyboard::KeyCode::Backspace => edit(Edit::Backspace),
keyboard::KeyCode::Delete => edit(Edit::Delete),
keyboard::KeyCode::Escape => Some(Self::Unfocus),
keyboard::KeyCode::C if modifiers.command() => {
match key.as_ref() {
keyboard::Key::Named(key::Named::Enter) => {
edit(Edit::Enter)
}
keyboard::Key::Named(key::Named::Backspace) => {
edit(Edit::Backspace)
}
keyboard::Key::Named(key::Named::Delete) => {
edit(Edit::Delete)
}
keyboard::Key::Named(key::Named::Escape) => {
Some(Self::Unfocus)
}
keyboard::Key::Character("c")
if modifiers.command() =>
{
Some(Self::Copy)
}
keyboard::KeyCode::V
keyboard::Key::Character("v")
if modifiers.command() && !modifiers.alt() =>
{
Some(Self::Paste)
@ -694,16 +709,16 @@ impl Update {
}
}
fn motion(key_code: keyboard::KeyCode) -> Option<Motion> {
match key_code {
keyboard::KeyCode::Left => Some(Motion::Left),
keyboard::KeyCode::Right => Some(Motion::Right),
keyboard::KeyCode::Up => Some(Motion::Up),
keyboard::KeyCode::Down => Some(Motion::Down),
keyboard::KeyCode::Home => Some(Motion::Home),
keyboard::KeyCode::End => Some(Motion::End),
keyboard::KeyCode::PageUp => Some(Motion::PageUp),
keyboard::KeyCode::PageDown => Some(Motion::PageDown),
fn motion(key: key::Named) -> Option<Motion> {
match key {
key::Named::ArrowLeft => Some(Motion::Left),
key::Named::ArrowRight => Some(Motion::Right),
key::Named::ArrowUp => Some(Motion::Up),
key::Named::ArrowDown => Some(Motion::Down),
key::Named::Home => Some(Motion::Home),
key::Named::End => Some(Motion::End),
key::Named::PageUp => Some(Motion::PageUp),
key::Named::PageDown => Some(Motion::PageDown),
_ => None,
}
}

View file

@ -14,6 +14,7 @@ use editor::Editor;
use crate::core::alignment;
use crate::core::event::{self, Event};
use crate::core::keyboard;
use crate::core::keyboard::key;
use crate::core::layout;
use crate::core::mouse::{self, click};
use crate::core::renderer;
@ -748,9 +749,7 @@ where
return event::Status::Captured;
}
}
Event::Keyboard(keyboard::Event::KeyPressed {
key_code, text, ..
}) => {
Event::Keyboard(keyboard::Event::KeyPressed { key, text, .. }) => {
let state = state();
if let Some(focus) = &mut state.is_focused {
@ -761,14 +760,13 @@ where
let modifiers = state.keyboard_modifiers;
focus.updated_at = Instant::now();
match key_code {
keyboard::KeyCode::Enter
| keyboard::KeyCode::NumpadEnter => {
match key.as_ref() {
keyboard::Key::Named(key::Named::Enter) => {
if let Some(on_submit) = on_submit.clone() {
shell.publish(on_submit);
}
}
keyboard::KeyCode::Backspace => {
keyboard::Key::Named(key::Named::Backspace) => {
if platform::is_jump_modifier_pressed(modifiers)
&& state.cursor.selection(value).is_none()
{
@ -788,7 +786,7 @@ where
update_cache(state, value);
}
keyboard::KeyCode::Delete => {
keyboard::Key::Named(key::Named::Delete) => {
if platform::is_jump_modifier_pressed(modifiers)
&& state.cursor.selection(value).is_none()
{
@ -810,7 +808,7 @@ where
update_cache(state, value);
}
keyboard::KeyCode::Left => {
keyboard::Key::Named(key::Named::ArrowLeft) => {
if platform::is_jump_modifier_pressed(modifiers)
&& !is_secure
{
@ -825,7 +823,7 @@ where
state.cursor.move_left(value);
}
}
keyboard::KeyCode::Right => {
keyboard::Key::Named(key::Named::ArrowRight) => {
if platform::is_jump_modifier_pressed(modifiers)
&& !is_secure
{
@ -840,7 +838,7 @@ where
state.cursor.move_right(value);
}
}
keyboard::KeyCode::Home => {
keyboard::Key::Named(key::Named::Home) => {
if modifiers.shift() {
state
.cursor
@ -849,7 +847,7 @@ where
state.cursor.move_to(0);
}
}
keyboard::KeyCode::End => {
keyboard::Key::Named(key::Named::End) => {
if modifiers.shift() {
state.cursor.select_range(
state.cursor.start(value),
@ -859,7 +857,7 @@ where
state.cursor.move_to(value.len());
}
}
keyboard::KeyCode::C
keyboard::Key::Character("c")
if state.keyboard_modifiers.command() =>
{
if let Some((start, end)) =
@ -869,7 +867,7 @@ where
.write(value.select(start, end).to_string());
}
}
keyboard::KeyCode::X
keyboard::Key::Character("x")
if state.keyboard_modifiers.command() =>
{
if let Some((start, end)) =
@ -887,7 +885,7 @@ where
update_cache(state, value);
}
keyboard::KeyCode::V => {
keyboard::Key::Character("v") => {
if state.keyboard_modifiers.command()
&& !state.keyboard_modifiers.alt()
{
@ -924,12 +922,12 @@ where
state.is_pasting = None;
}
}
keyboard::KeyCode::A
keyboard::Key::Character("a")
if state.keyboard_modifiers.command() =>
{
state.cursor.select_all(value);
}
keyboard::KeyCode::Escape => {
keyboard::Key::Named(key::Named::Escape) => {
state.is_focused = None;
state.is_dragging = false;
state.is_pasting = None;
@ -937,9 +935,11 @@ where
state.keyboard_modifiers =
keyboard::Modifiers::default();
}
keyboard::KeyCode::Tab
| keyboard::KeyCode::Up
| keyboard::KeyCode::Down => {
keyboard::Key::Named(
key::Named::Tab
| key::Named::ArrowUp
| key::Named::ArrowDown,
) => {
return event::Status::Ignored;
}
_ => {
@ -971,17 +971,19 @@ where
return event::Status::Captured;
}
}
Event::Keyboard(keyboard::Event::KeyReleased { key_code, .. }) => {
Event::Keyboard(keyboard::Event::KeyReleased { key, .. }) => {
let state = state();
if state.is_focused.is_some() {
match key_code {
keyboard::KeyCode::V => {
match key.as_ref() {
keyboard::Key::Character("v") => {
state.is_pasting = None;
}
keyboard::KeyCode::Tab
| keyboard::KeyCode::Up
| keyboard::KeyCode::Down => {
keyboard::Key::Named(
key::Named::Tab
| key::Named::ArrowUp
| key::Named::ArrowDown,
) => {
return event::Status::Ignored;
}
_ => {}

View file

@ -462,7 +462,7 @@ async fn run_instance<A, E, C>(
if let Some(event) = conversion::window_event(
window::Id::MAIN,
&window_event,
window_event,
state.scale_factor(),
state.modifiers(),
) {

View file

@ -128,7 +128,7 @@ pub fn window_settings(
/// Converts a winit window event into an iced event.
pub fn window_event(
id: window::Id,
event: &winit::event::WindowEvent,
event: winit::event::WindowEvent,
scale_factor: f64,
modifiers: winit::keyboard::ModifiersState,
) -> Option<Event> {
@ -163,7 +163,7 @@ pub fn window_event(
Some(Event::Mouse(mouse::Event::CursorLeft))
}
WindowEvent::MouseInput { button, state, .. } => {
let button = mouse_button(*button);
let button = mouse_button(button);
Some(Event::Mouse(match state {
winit::event::ElementState::Pressed => {
@ -178,8 +178,8 @@ pub fn window_event(
winit::event::MouseScrollDelta::LineDelta(delta_x, delta_y) => {
Some(Event::Mouse(mouse::Event::WheelScrolled {
delta: mouse::ScrollDelta::Lines {
x: *delta_x,
y: *delta_y,
x: delta_x,
y: delta_y,
},
}))
}
@ -198,18 +198,33 @@ pub fn window_event(
logical_key,
state,
text,
location,
..
},
..
} => Some(Event::Keyboard({
let key_code = key_code(logical_key);
let key = key(logical_key);
let modifiers = self::modifiers(modifiers);
let location = match location {
winit::keyboard::KeyLocation::Standard => {
keyboard::Location::Standard
}
winit::keyboard::KeyLocation::Left => keyboard::Location::Left,
winit::keyboard::KeyLocation::Right => {
keyboard::Location::Right
}
winit::keyboard::KeyLocation::Numpad => {
keyboard::Location::Numpad
}
};
match state {
winit::event::ElementState::Pressed => {
keyboard::Event::KeyPressed {
key_code,
key,
modifiers,
location,
text: text
.as_ref()
.map(winit::keyboard::SmolStr::to_string),
@ -217,8 +232,9 @@ pub fn window_event(
}
winit::event::ElementState::Released => {
keyboard::Event::KeyReleased {
key_code,
key,
modifiers,
location,
}
}
}
@ -230,7 +246,7 @@ pub fn window_event(
}
WindowEvent::Focused(focused) => Some(Event::Window(
id,
if *focused {
if focused {
window::Event::Focused
} else {
window::Event::Unfocused
@ -246,7 +262,7 @@ pub fn window_event(
Some(Event::Window(id, window::Event::FilesHoveredLeft))
}
WindowEvent::Touch(touch) => {
Some(Event::Touch(touch_event(*touch, scale_factor)))
Some(Event::Touch(touch_event(touch, scale_factor)))
}
WindowEvent::Moved(position) => {
let winit::dpi::LogicalPosition { x, y } =
@ -449,125 +465,328 @@ pub fn touch_event(
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced`]: https://github.com/iced-rs/iced/tree/0.10
pub fn key_code(key: &winit::keyboard::Key) -> keyboard::KeyCode {
use keyboard::KeyCode;
pub fn key(key: winit::keyboard::Key) -> keyboard::Key {
use keyboard::key::Named;
use winit::keyboard::NamedKey;
match key {
winit::keyboard::Key::Character(c) => match c.as_str() {
"1" => KeyCode::Key1,
"2" => KeyCode::Key2,
"3" => KeyCode::Key3,
"4" => KeyCode::Key4,
"5" => KeyCode::Key5,
"6" => KeyCode::Key6,
"7" => KeyCode::Key7,
"8" => KeyCode::Key8,
"9" => KeyCode::Key9,
"0" => KeyCode::Key0,
"a" => KeyCode::A,
"b" => KeyCode::B,
"c" => KeyCode::C,
"d" => KeyCode::D,
"e" => KeyCode::E,
"f" => KeyCode::F,
"g" => KeyCode::G,
"h" => KeyCode::H,
"i" => KeyCode::I,
"j" => KeyCode::J,
"k" => KeyCode::K,
"l" => KeyCode::L,
"m" => KeyCode::M,
"n" => KeyCode::N,
"o" => KeyCode::O,
"p" => KeyCode::P,
"q" => KeyCode::Q,
"r" => KeyCode::R,
"s" => KeyCode::S,
"t" => KeyCode::T,
"u" => KeyCode::U,
"v" => KeyCode::V,
"w" => KeyCode::W,
"x" => KeyCode::X,
"y" => KeyCode::Y,
"z" => KeyCode::Z,
_ => KeyCode::Unlabeled,
},
winit::keyboard::Key::Named(named_key) => match named_key {
NamedKey::Escape => KeyCode::Escape,
NamedKey::F1 => KeyCode::F1,
NamedKey::F2 => KeyCode::F2,
NamedKey::F3 => KeyCode::F3,
NamedKey::F4 => KeyCode::F4,
NamedKey::F5 => KeyCode::F5,
NamedKey::F6 => KeyCode::F6,
NamedKey::F7 => KeyCode::F7,
NamedKey::F8 => KeyCode::F8,
NamedKey::F9 => KeyCode::F9,
NamedKey::F10 => KeyCode::F10,
NamedKey::F11 => KeyCode::F11,
NamedKey::F12 => KeyCode::F12,
NamedKey::F13 => KeyCode::F13,
NamedKey::F14 => KeyCode::F14,
NamedKey::F15 => KeyCode::F15,
NamedKey::F16 => KeyCode::F16,
NamedKey::F17 => KeyCode::F17,
NamedKey::F18 => KeyCode::F18,
NamedKey::F19 => KeyCode::F19,
NamedKey::F20 => KeyCode::F20,
NamedKey::F21 => KeyCode::F21,
NamedKey::F22 => KeyCode::F22,
NamedKey::F23 => KeyCode::F23,
NamedKey::F24 => KeyCode::F24,
NamedKey::PrintScreen => KeyCode::Snapshot,
NamedKey::ScrollLock => KeyCode::Scroll,
NamedKey::Pause => KeyCode::Pause,
NamedKey::Insert => KeyCode::Insert,
NamedKey::Home => KeyCode::Home,
NamedKey::Delete => KeyCode::Delete,
NamedKey::End => KeyCode::End,
NamedKey::PageDown => KeyCode::PageDown,
NamedKey::PageUp => KeyCode::PageUp,
NamedKey::ArrowLeft => KeyCode::Left,
NamedKey::ArrowUp => KeyCode::Up,
NamedKey::ArrowRight => KeyCode::Right,
NamedKey::ArrowDown => KeyCode::Down,
NamedKey::Backspace => KeyCode::Backspace,
NamedKey::Enter => KeyCode::Enter,
NamedKey::Space => KeyCode::Space,
NamedKey::Compose => KeyCode::Compose,
NamedKey::NumLock => KeyCode::Numlock,
NamedKey::AppSwitch => KeyCode::Apps,
NamedKey::Convert => KeyCode::Convert,
NamedKey::LaunchMail => KeyCode::Mail,
NamedKey::MediaApps => KeyCode::MediaSelect,
NamedKey::MediaStop => KeyCode::MediaStop,
NamedKey::AudioVolumeMute => KeyCode::Mute,
NamedKey::MediaStepForward => KeyCode::NavigateForward,
NamedKey::MediaStepBackward => KeyCode::NavigateBackward,
NamedKey::MediaSkipForward => KeyCode::NextTrack,
NamedKey::NonConvert => KeyCode::NoConvert,
NamedKey::MediaPlayPause => KeyCode::PlayPause,
NamedKey::Power => KeyCode::Power,
NamedKey::MediaSkipBackward => KeyCode::PrevTrack,
NamedKey::PowerOff => KeyCode::Sleep,
NamedKey::Tab => KeyCode::Tab,
NamedKey::AudioVolumeDown => KeyCode::VolumeDown,
NamedKey::AudioVolumeUp => KeyCode::VolumeUp,
NamedKey::WakeUp => KeyCode::Wake,
NamedKey::BrowserBack => KeyCode::WebBack,
NamedKey::BrowserFavorites => KeyCode::WebFavorites,
NamedKey::BrowserForward => KeyCode::WebForward,
NamedKey::BrowserHome => KeyCode::WebHome,
NamedKey::BrowserRefresh => KeyCode::WebRefresh,
NamedKey::BrowserSearch => KeyCode::WebSearch,
NamedKey::BrowserStop => KeyCode::WebStop,
NamedKey::Copy => KeyCode::Copy,
NamedKey::Paste => KeyCode::Paste,
NamedKey::Cut => KeyCode::Cut,
_ => KeyCode::Unlabeled,
},
_ => KeyCode::Unlabeled,
winit::keyboard::Key::Character(c) => keyboard::Key::Character(c),
winit::keyboard::Key::Named(named_key) => {
keyboard::Key::Named(match named_key {
NamedKey::Alt => Named::Alt,
NamedKey::AltGraph => Named::AltGraph,
NamedKey::CapsLock => Named::CapsLock,
NamedKey::Control => Named::Control,
NamedKey::Fn => Named::Fn,
NamedKey::FnLock => Named::FnLock,
NamedKey::NumLock => Named::NumLock,
NamedKey::ScrollLock => Named::ScrollLock,
NamedKey::Shift => Named::Shift,
NamedKey::Symbol => Named::Symbol,
NamedKey::SymbolLock => Named::SymbolLock,
NamedKey::Meta => Named::Meta,
NamedKey::Hyper => Named::Hyper,
NamedKey::Super => Named::Super,
NamedKey::Enter => Named::Enter,
NamedKey::Tab => Named::Tab,
NamedKey::Space => Named::Space,
NamedKey::ArrowDown => Named::ArrowDown,
NamedKey::ArrowLeft => Named::ArrowLeft,
NamedKey::ArrowRight => Named::ArrowRight,
NamedKey::ArrowUp => Named::ArrowUp,
NamedKey::End => Named::End,
NamedKey::Home => Named::Home,
NamedKey::PageDown => Named::PageDown,
NamedKey::PageUp => Named::PageUp,
NamedKey::Backspace => Named::Backspace,
NamedKey::Clear => Named::Clear,
NamedKey::Copy => Named::Copy,
NamedKey::CrSel => Named::CrSel,
NamedKey::Cut => Named::Cut,
NamedKey::Delete => Named::Delete,
NamedKey::EraseEof => Named::EraseEof,
NamedKey::ExSel => Named::ExSel,
NamedKey::Insert => Named::Insert,
NamedKey::Paste => Named::Paste,
NamedKey::Redo => Named::Redo,
NamedKey::Undo => Named::Undo,
NamedKey::Accept => Named::Accept,
NamedKey::Again => Named::Again,
NamedKey::Attn => Named::Attn,
NamedKey::Cancel => Named::Cancel,
NamedKey::ContextMenu => Named::ContextMenu,
NamedKey::Escape => Named::Escape,
NamedKey::Execute => Named::Execute,
NamedKey::Find => Named::Find,
NamedKey::Help => Named::Help,
NamedKey::Pause => Named::Pause,
NamedKey::Play => Named::Play,
NamedKey::Props => Named::Props,
NamedKey::Select => Named::Select,
NamedKey::ZoomIn => Named::ZoomIn,
NamedKey::ZoomOut => Named::ZoomOut,
NamedKey::BrightnessDown => Named::BrightnessDown,
NamedKey::BrightnessUp => Named::BrightnessUp,
NamedKey::Eject => Named::Eject,
NamedKey::LogOff => Named::LogOff,
NamedKey::Power => Named::Power,
NamedKey::PowerOff => Named::PowerOff,
NamedKey::PrintScreen => Named::PrintScreen,
NamedKey::Hibernate => Named::Hibernate,
NamedKey::Standby => Named::Standby,
NamedKey::WakeUp => Named::WakeUp,
NamedKey::AllCandidates => Named::AllCandidates,
NamedKey::Alphanumeric => Named::Alphanumeric,
NamedKey::CodeInput => Named::CodeInput,
NamedKey::Compose => Named::Compose,
NamedKey::Convert => Named::Convert,
NamedKey::FinalMode => Named::FinalMode,
NamedKey::GroupFirst => Named::GroupFirst,
NamedKey::GroupLast => Named::GroupLast,
NamedKey::GroupNext => Named::GroupNext,
NamedKey::GroupPrevious => Named::GroupPrevious,
NamedKey::ModeChange => Named::ModeChange,
NamedKey::NextCandidate => Named::NextCandidate,
NamedKey::NonConvert => Named::NonConvert,
NamedKey::PreviousCandidate => Named::PreviousCandidate,
NamedKey::Process => Named::Process,
NamedKey::SingleCandidate => Named::SingleCandidate,
NamedKey::HangulMode => Named::HangulMode,
NamedKey::HanjaMode => Named::HanjaMode,
NamedKey::JunjaMode => Named::JunjaMode,
NamedKey::Eisu => Named::Eisu,
NamedKey::Hankaku => Named::Hankaku,
NamedKey::Hiragana => Named::Hiragana,
NamedKey::HiraganaKatakana => Named::HiraganaKatakana,
NamedKey::KanaMode => Named::KanaMode,
NamedKey::KanjiMode => Named::KanjiMode,
NamedKey::Katakana => Named::Katakana,
NamedKey::Romaji => Named::Romaji,
NamedKey::Zenkaku => Named::Zenkaku,
NamedKey::ZenkakuHankaku => Named::ZenkakuHankaku,
NamedKey::Soft1 => Named::Soft1,
NamedKey::Soft2 => Named::Soft2,
NamedKey::Soft3 => Named::Soft3,
NamedKey::Soft4 => Named::Soft4,
NamedKey::ChannelDown => Named::ChannelDown,
NamedKey::ChannelUp => Named::ChannelUp,
NamedKey::Close => Named::Close,
NamedKey::MailForward => Named::MailForward,
NamedKey::MailReply => Named::MailReply,
NamedKey::MailSend => Named::MailSend,
NamedKey::MediaClose => Named::MediaClose,
NamedKey::MediaFastForward => Named::MediaFastForward,
NamedKey::MediaPause => Named::MediaPause,
NamedKey::MediaPlay => Named::MediaPlay,
NamedKey::MediaPlayPause => Named::MediaPlayPause,
NamedKey::MediaRecord => Named::MediaRecord,
NamedKey::MediaRewind => Named::MediaRewind,
NamedKey::MediaStop => Named::MediaStop,
NamedKey::MediaTrackNext => Named::MediaTrackNext,
NamedKey::MediaTrackPrevious => Named::MediaTrackPrevious,
NamedKey::New => Named::New,
NamedKey::Open => Named::Open,
NamedKey::Print => Named::Print,
NamedKey::Save => Named::Save,
NamedKey::SpellCheck => Named::SpellCheck,
NamedKey::Key11 => Named::Key11,
NamedKey::Key12 => Named::Key12,
NamedKey::AudioBalanceLeft => Named::AudioBalanceLeft,
NamedKey::AudioBalanceRight => Named::AudioBalanceRight,
NamedKey::AudioBassBoostDown => Named::AudioBassBoostDown,
NamedKey::AudioBassBoostToggle => Named::AudioBassBoostToggle,
NamedKey::AudioBassBoostUp => Named::AudioBassBoostUp,
NamedKey::AudioFaderFront => Named::AudioFaderFront,
NamedKey::AudioFaderRear => Named::AudioFaderRear,
NamedKey::AudioSurroundModeNext => Named::AudioSurroundModeNext,
NamedKey::AudioTrebleDown => Named::AudioTrebleDown,
NamedKey::AudioTrebleUp => Named::AudioTrebleUp,
NamedKey::AudioVolumeDown => Named::AudioVolumeDown,
NamedKey::AudioVolumeUp => Named::AudioVolumeUp,
NamedKey::AudioVolumeMute => Named::AudioVolumeMute,
NamedKey::MicrophoneToggle => Named::MicrophoneToggle,
NamedKey::MicrophoneVolumeDown => Named::MicrophoneVolumeDown,
NamedKey::MicrophoneVolumeUp => Named::MicrophoneVolumeUp,
NamedKey::MicrophoneVolumeMute => Named::MicrophoneVolumeMute,
NamedKey::SpeechCorrectionList => Named::SpeechCorrectionList,
NamedKey::SpeechInputToggle => Named::SpeechInputToggle,
NamedKey::LaunchApplication1 => Named::LaunchApplication1,
NamedKey::LaunchApplication2 => Named::LaunchApplication2,
NamedKey::LaunchCalendar => Named::LaunchCalendar,
NamedKey::LaunchContacts => Named::LaunchContacts,
NamedKey::LaunchMail => Named::LaunchMail,
NamedKey::LaunchMediaPlayer => Named::LaunchMediaPlayer,
NamedKey::LaunchMusicPlayer => Named::LaunchMusicPlayer,
NamedKey::LaunchPhone => Named::LaunchPhone,
NamedKey::LaunchScreenSaver => Named::LaunchScreenSaver,
NamedKey::LaunchSpreadsheet => Named::LaunchSpreadsheet,
NamedKey::LaunchWebBrowser => Named::LaunchWebBrowser,
NamedKey::LaunchWebCam => Named::LaunchWebCam,
NamedKey::LaunchWordProcessor => Named::LaunchWordProcessor,
NamedKey::BrowserBack => Named::BrowserBack,
NamedKey::BrowserFavorites => Named::BrowserFavorites,
NamedKey::BrowserForward => Named::BrowserForward,
NamedKey::BrowserHome => Named::BrowserHome,
NamedKey::BrowserRefresh => Named::BrowserRefresh,
NamedKey::BrowserSearch => Named::BrowserSearch,
NamedKey::BrowserStop => Named::BrowserStop,
NamedKey::AppSwitch => Named::AppSwitch,
NamedKey::Call => Named::Call,
NamedKey::Camera => Named::Camera,
NamedKey::CameraFocus => Named::CameraFocus,
NamedKey::EndCall => Named::EndCall,
NamedKey::GoBack => Named::GoBack,
NamedKey::GoHome => Named::GoHome,
NamedKey::HeadsetHook => Named::HeadsetHook,
NamedKey::LastNumberRedial => Named::LastNumberRedial,
NamedKey::Notification => Named::Notification,
NamedKey::MannerMode => Named::MannerMode,
NamedKey::VoiceDial => Named::VoiceDial,
NamedKey::TV => Named::TV,
NamedKey::TV3DMode => Named::TV3DMode,
NamedKey::TVAntennaCable => Named::TVAntennaCable,
NamedKey::TVAudioDescription => Named::TVAudioDescription,
NamedKey::TVAudioDescriptionMixDown => {
Named::TVAudioDescriptionMixDown
}
NamedKey::TVAudioDescriptionMixUp => {
Named::TVAudioDescriptionMixUp
}
NamedKey::TVContentsMenu => Named::TVContentsMenu,
NamedKey::TVDataService => Named::TVDataService,
NamedKey::TVInput => Named::TVInput,
NamedKey::TVInputComponent1 => Named::TVInputComponent1,
NamedKey::TVInputComponent2 => Named::TVInputComponent2,
NamedKey::TVInputComposite1 => Named::TVInputComposite1,
NamedKey::TVInputComposite2 => Named::TVInputComposite2,
NamedKey::TVInputHDMI1 => Named::TVInputHDMI1,
NamedKey::TVInputHDMI2 => Named::TVInputHDMI2,
NamedKey::TVInputHDMI3 => Named::TVInputHDMI3,
NamedKey::TVInputHDMI4 => Named::TVInputHDMI4,
NamedKey::TVInputVGA1 => Named::TVInputVGA1,
NamedKey::TVMediaContext => Named::TVMediaContext,
NamedKey::TVNetwork => Named::TVNetwork,
NamedKey::TVNumberEntry => Named::TVNumberEntry,
NamedKey::TVPower => Named::TVPower,
NamedKey::TVRadioService => Named::TVRadioService,
NamedKey::TVSatellite => Named::TVSatellite,
NamedKey::TVSatelliteBS => Named::TVSatelliteBS,
NamedKey::TVSatelliteCS => Named::TVSatelliteCS,
NamedKey::TVSatelliteToggle => Named::TVSatelliteToggle,
NamedKey::TVTerrestrialAnalog => Named::TVTerrestrialAnalog,
NamedKey::TVTerrestrialDigital => Named::TVTerrestrialDigital,
NamedKey::TVTimer => Named::TVTimer,
NamedKey::AVRInput => Named::AVRInput,
NamedKey::AVRPower => Named::AVRPower,
NamedKey::ColorF0Red => Named::ColorF0Red,
NamedKey::ColorF1Green => Named::ColorF1Green,
NamedKey::ColorF2Yellow => Named::ColorF2Yellow,
NamedKey::ColorF3Blue => Named::ColorF3Blue,
NamedKey::ColorF4Grey => Named::ColorF4Grey,
NamedKey::ColorF5Brown => Named::ColorF5Brown,
NamedKey::ClosedCaptionToggle => Named::ClosedCaptionToggle,
NamedKey::Dimmer => Named::Dimmer,
NamedKey::DisplaySwap => Named::DisplaySwap,
NamedKey::DVR => Named::DVR,
NamedKey::Exit => Named::Exit,
NamedKey::FavoriteClear0 => Named::FavoriteClear0,
NamedKey::FavoriteClear1 => Named::FavoriteClear1,
NamedKey::FavoriteClear2 => Named::FavoriteClear2,
NamedKey::FavoriteClear3 => Named::FavoriteClear3,
NamedKey::FavoriteRecall0 => Named::FavoriteRecall0,
NamedKey::FavoriteRecall1 => Named::FavoriteRecall1,
NamedKey::FavoriteRecall2 => Named::FavoriteRecall2,
NamedKey::FavoriteRecall3 => Named::FavoriteRecall3,
NamedKey::FavoriteStore0 => Named::FavoriteStore0,
NamedKey::FavoriteStore1 => Named::FavoriteStore1,
NamedKey::FavoriteStore2 => Named::FavoriteStore2,
NamedKey::FavoriteStore3 => Named::FavoriteStore3,
NamedKey::Guide => Named::Guide,
NamedKey::GuideNextDay => Named::GuideNextDay,
NamedKey::GuidePreviousDay => Named::GuidePreviousDay,
NamedKey::Info => Named::Info,
NamedKey::InstantReplay => Named::InstantReplay,
NamedKey::Link => Named::Link,
NamedKey::ListProgram => Named::ListProgram,
NamedKey::LiveContent => Named::LiveContent,
NamedKey::Lock => Named::Lock,
NamedKey::MediaApps => Named::MediaApps,
NamedKey::MediaAudioTrack => Named::MediaAudioTrack,
NamedKey::MediaLast => Named::MediaLast,
NamedKey::MediaSkipBackward => Named::MediaSkipBackward,
NamedKey::MediaSkipForward => Named::MediaSkipForward,
NamedKey::MediaStepBackward => Named::MediaStepBackward,
NamedKey::MediaStepForward => Named::MediaStepForward,
NamedKey::MediaTopMenu => Named::MediaTopMenu,
NamedKey::NavigateIn => Named::NavigateIn,
NamedKey::NavigateNext => Named::NavigateNext,
NamedKey::NavigateOut => Named::NavigateOut,
NamedKey::NavigatePrevious => Named::NavigatePrevious,
NamedKey::NextFavoriteChannel => Named::NextFavoriteChannel,
NamedKey::NextUserProfile => Named::NextUserProfile,
NamedKey::OnDemand => Named::OnDemand,
NamedKey::Pairing => Named::Pairing,
NamedKey::PinPDown => Named::PinPDown,
NamedKey::PinPMove => Named::PinPMove,
NamedKey::PinPToggle => Named::PinPToggle,
NamedKey::PinPUp => Named::PinPUp,
NamedKey::PlaySpeedDown => Named::PlaySpeedDown,
NamedKey::PlaySpeedReset => Named::PlaySpeedReset,
NamedKey::PlaySpeedUp => Named::PlaySpeedUp,
NamedKey::RandomToggle => Named::RandomToggle,
NamedKey::RcLowBattery => Named::RcLowBattery,
NamedKey::RecordSpeedNext => Named::RecordSpeedNext,
NamedKey::RfBypass => Named::RfBypass,
NamedKey::ScanChannelsToggle => Named::ScanChannelsToggle,
NamedKey::ScreenModeNext => Named::ScreenModeNext,
NamedKey::Settings => Named::Settings,
NamedKey::SplitScreenToggle => Named::SplitScreenToggle,
NamedKey::STBInput => Named::STBInput,
NamedKey::STBPower => Named::STBPower,
NamedKey::Subtitle => Named::Subtitle,
NamedKey::Teletext => Named::Teletext,
NamedKey::VideoModeNext => Named::VideoModeNext,
NamedKey::Wink => Named::Wink,
NamedKey::ZoomToggle => Named::ZoomToggle,
NamedKey::F1 => Named::F1,
NamedKey::F2 => Named::F2,
NamedKey::F3 => Named::F3,
NamedKey::F4 => Named::F4,
NamedKey::F5 => Named::F5,
NamedKey::F6 => Named::F6,
NamedKey::F7 => Named::F7,
NamedKey::F8 => Named::F8,
NamedKey::F9 => Named::F9,
NamedKey::F10 => Named::F10,
NamedKey::F11 => Named::F11,
NamedKey::F12 => Named::F12,
NamedKey::F13 => Named::F13,
NamedKey::F14 => Named::F14,
NamedKey::F15 => Named::F15,
NamedKey::F16 => Named::F16,
NamedKey::F17 => Named::F17,
NamedKey::F18 => Named::F18,
NamedKey::F19 => Named::F19,
NamedKey::F20 => Named::F20,
NamedKey::F21 => Named::F21,
NamedKey::F22 => Named::F22,
NamedKey::F23 => Named::F23,
NamedKey::F24 => Named::F24,
NamedKey::F25 => Named::F25,
NamedKey::F26 => Named::F26,
NamedKey::F27 => Named::F27,
NamedKey::F28 => Named::F28,
NamedKey::F29 => Named::F29,
NamedKey::F30 => Named::F30,
NamedKey::F31 => Named::F31,
NamedKey::F32 => Named::F32,
NamedKey::F33 => Named::F33,
NamedKey::F34 => Named::F34,
NamedKey::F35 => Named::F35,
_ => return keyboard::Key::Unidentified,
})
}
_ => keyboard::Key::Unidentified,
}
}

View file

@ -645,7 +645,7 @@ async fn run_instance<A, E, C>(
if let Some(event) = conversion::window_event(
id,
&window_event,
window_event,
window.state.scale_factor(),
window.state.modifiers(),
) {