Repository navigation
Conversation
Add EventHandler::key_down_with_character_event, which carries what the key types on the keyboard's layout alongside its KeyCode, the key's place. It hands the key on to key_down_event unless implemented, so existing handlers are unchanged. macOS, the web, Windows, X11 and Wayland report the character; Android and iOS report None. This lets an app match letter shortcuts by the letter on the key, as macOS and browsers do, so Cmd+Z undoes from the key labelled Z on AZERTY, QWERTZ or Dvorak, rather than from the key in QWERTY's Z place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KeyCodeis the key's place on macOS (the hardware key code), the web (event.code) and Windows (the scan code): the key a US QWERTY layout has there. That's right for keys picked for where they sit, like WASD, but a letter shortcut such as Cmd+Z should follow the key labelled Z, as macOS menus and browsers do. On a French AZERTY layout, Z is where QWERTY has W, so an app matchingKeyCode::Zundoes from the key labelled W.char_eventcan't fill the gap: it's for typing, so Ctrl turns letters into control characters, Alt into other characters, and the web sends nokeypresswith Ctrl.This adds
EventHandler::key_down_with_character_event, which carries, with each key going down, the character it types on the keyboard's current layout as Shift (and Command on macOS) change it, but not Control:'z'for Ctrl+Z, and for Cmd+Z on AZERTY. It'sNonewhen the key types no character, or several, or the platform doesn't say. Unless implemented, it hands the key on tokey_down_event, so existing handlers are unchanged. Every platform now calls it for every key down, modifier keys included (withNone), so a handler implementing only the new method misses no key.charactersByApplyingModifiers:with only Shift and Command kept, so a layout that types QWERTY's letters while Command is held (Dvorak – QWERTY ⌘) is followed, as macOS menus follow it.charactersIgnoringModifiersbefore macOS 10.15.event.key, when it's one character, passed tokey_downas a code point.ToUnicodeExwith a keyboard state holding only Shift, and flag0x4so the dead-key state is left forWM_CHAR.char_event.Nonefor now.Checked with
cargo checkfor macOS, iOS, tvOS, Android, Linux, Windows (GNU) and wasm32. On macOS, a key event on the U.S. layout readszfor Cmd+Z, Ctrl+Cmd+Z, Shift+Cmd+Z and Ctrl+Z. In a browser,key: "m", code: "Semicolon"(AZERTY's M) reaches the handler asKeyCode::SemicolonwithSome('m').