Skip to content

Commit

Permalink
feat: support accelerator key strings , - . Space Tab and `…
Browse files Browse the repository at this point in the history
…F13`-`F24` (#228)

* feat(macOS): support more accelerator key strings

* Move function keys together

* Add `,` `-` `.` `Space` `F20-F24` for Windows

* Remove support for accelerators not found in `winapi`

* Add `,` `-` `.` `Space` `F13-F24` for Linux

* Update .changes

* Add the rest for Windows

* Add the rest for Linux

* Add the rest on macOS

* Update accelerator-strings.md
  • Loading branch information
probablykasper committed Nov 15, 2021
1 parent f0a3dce commit b047ae4
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/accelerator-strings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tao: minor
---

Add support for more accelerator keys: `,` `-` `.` `=` `;` `/` `\` `'` `` ` `` `[` `]` `Space` `Tab` and `F13`-`F24`
12 changes: 12 additions & 0 deletions src/platform_impl/linux/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ pub fn key_to_raw_key(src: &KeyCode) -> Option<RawKey> {
KeyCode::F10 => F10,
KeyCode::F11 => F11,
KeyCode::F12 => F12,
KeyCode::F13 => F13,
KeyCode::F14 => F14,
KeyCode::F15 => F15,
KeyCode::F16 => F16,
KeyCode::F17 => F17,
KeyCode::F18 => F18,
KeyCode::F19 => F19,
KeyCode::F20 => F20,
KeyCode::F21 => F21,
KeyCode::F22 => F22,
KeyCode::F23 => F23,
KeyCode::F24 => F24,

KeyCode::PrintScreen => Print,
KeyCode::ScrollLock => Scroll_Lock,
Expand Down
12 changes: 12 additions & 0 deletions src/platform_impl/linux/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ fn register_accelerator(item: &GtkMenuItem, accel_group: &AccelGroup, menu_key:
KeyCode::Digit7 => '7' as u32,
KeyCode::Digit8 => '8' as u32,
KeyCode::Digit9 => '9' as u32,
KeyCode::Comma => ',' as u32,
KeyCode::Minus => '-' as u32,
KeyCode::Period => '.' as u32,
KeyCode::Space => ' ' as u32,
KeyCode::Equal => '=' as u32,
KeyCode::Semicolon => ';' as u32,
KeyCode::Slash => '/' as u32,
KeyCode::Backslash => '\\' as u32,
KeyCode::Quote => '\'' as u32,
KeyCode::Backquote => '`' as u32,
KeyCode::BracketLeft => '[' as u32,
KeyCode::BracketRight => ']' as u32,
k => {
if let Some(gdk_key) = key_to_raw_key(k) {
*gdk_key
Expand Down
28 changes: 25 additions & 3 deletions src/platform_impl/macos/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,6 @@ impl Accelerator {
/// Returns the empty string if no key equivalent is known.
fn key_equivalent(self) -> String {
match self.key {
KeyCode::Minus => "-".into(),
KeyCode::Equal => "=".into(),
KeyCode::KeyA => "a".into(),
KeyCode::KeyB => "b".into(),
KeyCode::KeyC => "c".into(),
Expand Down Expand Up @@ -507,8 +505,20 @@ impl Accelerator {
KeyCode::Digit7 => "7".into(),
KeyCode::Digit8 => "8".into(),
KeyCode::Digit9 => "9".into(),
KeyCode::Escape => "\u{1b}".into(),
KeyCode::Comma => ",".into(),
KeyCode::Minus => "-".into(),
KeyCode::Period => ".".into(),
KeyCode::Space => "\u{0020}".into(),
KeyCode::Equal => "=".into(),
KeyCode::Semicolon => ";".into(),
KeyCode::Slash => "/".into(),
KeyCode::Backslash => "\\".into(),
KeyCode::Quote => "\'".into(),
KeyCode::Backquote => "`".into(),
KeyCode::BracketLeft => "[".into(),
KeyCode::BracketRight => "]".into(),
KeyCode::Tab => "⇥".into(),
KeyCode::Escape => "\u{001b}".into(),
// from NSText.h
KeyCode::Enter => "\u{0003}".into(),
KeyCode::Backspace => "\u{0008}".into(),
Expand Down Expand Up @@ -537,6 +547,18 @@ impl Accelerator {
KeyCode::F10 => "\u{F70D}".into(),
KeyCode::F11 => "\u{F70E}".into(),
KeyCode::F12 => "\u{F70F}".into(),
KeyCode::F13 => "\u{F710}".into(),
KeyCode::F14 => "\u{F711}".into(),
KeyCode::F15 => "\u{F712}".into(),
KeyCode::F16 => "\u{F713}".into(),
KeyCode::F17 => "\u{F714}".into(),
KeyCode::F18 => "\u{F715}".into(),
KeyCode::F19 => "\u{F716}".into(),
KeyCode::F20 => "\u{F717}".into(),
KeyCode::F21 => "\u{F718}".into(),
KeyCode::F22 => "\u{F719}".into(),
KeyCode::F23 => "\u{F71A}".into(),
KeyCode::F24 => "\u{F71B}".into(),
_ => {
eprintln!("no key equivalent for {:?}", self);
"".into()
Expand Down
21 changes: 19 additions & 2 deletions src/platform_impl/windows/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,13 +827,25 @@ pub(crate) fn key_to_vk(key: &KeyCode) -> Option<i32> {
KeyCode::Digit7 => unsafe { winuser::VkKeyScanW('7' as u16) as i32 },
KeyCode::Digit8 => unsafe { winuser::VkKeyScanW('8' as u16) as i32 },
KeyCode::Digit9 => unsafe { winuser::VkKeyScanW('9' as u16) as i32 },
KeyCode::Backspace => winuser::VK_BACK,
KeyCode::Comma => winuser::VK_OEM_COMMA,
KeyCode::Minus => winuser::VK_OEM_MINUS,
KeyCode::Period => winuser::VK_OEM_PERIOD,
KeyCode::Space => winuser::VK_SPACE,
KeyCode::Equal => unsafe { winuser::VkKeyScanW('=' as u16) as i32 },
KeyCode::Semicolon => unsafe { winuser::VkKeyScanW(';' as u16) as i32 },
KeyCode::Slash => unsafe { winuser::VkKeyScanW('/' as u16) as i32 },
KeyCode::Backslash => unsafe { winuser::VkKeyScanW('\\' as u16) as i32 },
KeyCode::Quote => unsafe { winuser::VkKeyScanW('\'' as u16) as i32 },
KeyCode::Backquote => unsafe { winuser::VkKeyScanW('`' as u16) as i32 },
KeyCode::BracketLeft => unsafe { winuser::VkKeyScanW('[' as u16) as i32 },
KeyCode::BracketRight => unsafe { winuser::VkKeyScanW(']' as u16) as i32 },
KeyCode::Tab => winuser::VK_TAB,
KeyCode::Escape => winuser::VK_ESCAPE,
KeyCode::Backspace => winuser::VK_BACK,
KeyCode::Enter => winuser::VK_RETURN,
KeyCode::Pause => winuser::VK_PAUSE,
KeyCode::CapsLock => winuser::VK_CAPITAL,
KeyCode::KanaMode => winuser::VK_KANA,
KeyCode::Escape => winuser::VK_ESCAPE,
KeyCode::NonConvert => winuser::VK_NONCONVERT,
KeyCode::PageUp => winuser::VK_PRIOR,
KeyCode::PageDown => winuser::VK_NEXT,
Expand Down Expand Up @@ -867,6 +879,11 @@ pub(crate) fn key_to_vk(key: &KeyCode) -> Option<i32> {
KeyCode::F17 => winuser::VK_F17,
KeyCode::F18 => winuser::VK_F18,
KeyCode::F19 => winuser::VK_F19,
KeyCode::F20 => winuser::VK_F20,
KeyCode::F21 => winuser::VK_F21,
KeyCode::F22 => winuser::VK_F22,
KeyCode::F23 => winuser::VK_F23,
KeyCode::F24 => winuser::VK_F24,
KeyCode::NumLock => winuser::VK_NUMLOCK,
KeyCode::ScrollLock => winuser::VK_SCROLL,
KeyCode::BrowserBack => winuser::VK_BROWSER_BACK,
Expand Down
13 changes: 13 additions & 0 deletions src/platform_impl/windows/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,19 @@ fn format_hotkey(key: Accelerator, s: &mut String) {
KeyCode::Digit7 => s.push('7'),
KeyCode::Digit8 => s.push('8'),
KeyCode::Digit9 => s.push('9'),
KeyCode::Comma => s.push(','),
KeyCode::Minus => s.push('-'),
KeyCode::Period => s.push('.'),
KeyCode::Space => s.push_str("Space"),
KeyCode::Equal => s.push('='),
KeyCode::Semicolon => s.push(';'),
KeyCode::Slash => s.push('/'),
KeyCode::Backslash => s.push('\\'),
KeyCode::Quote => s.push('\''),
KeyCode::Backquote => s.push('`'),
KeyCode::BracketLeft => s.push('['),
KeyCode::BracketRight => s.push(']'),
KeyCode::Tab => s.push_str("Tab"),
KeyCode::Escape => s.push_str("Esc"),
KeyCode::Delete => s.push_str("Del"),
KeyCode::Insert => s.push_str("Ins"),
Expand Down

0 comments on commit b047ae4

Please sign in to comment.