Skip to content

Commit

Permalink
feat: support Code::Backquote on Linux (#44)
Browse files Browse the repository at this point in the history
closes #41
  • Loading branch information
amrbashir authored Nov 23, 2023
1 parent 6fb2bb4 commit a8345a9
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 80 deletions.
5 changes: 5 additions & 0 deletions .changes/backquote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"global-hotkey": "patch"
---

Add support for `Code::Backquote` on Linux.
88 changes: 44 additions & 44 deletions src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,53 +173,53 @@ pub fn get_instance_handle() -> windows_sys::Win32::Foundation::HMODULE {
// used to build accelerators table from Key
fn key_to_vk(key: &Code) -> Option<VIRTUAL_KEY> {
Some(match key {
Code::KeyA => unsafe { VkKeyScanW('a' as u16) as u16 },
Code::KeyB => unsafe { VkKeyScanW('b' as u16) as u16 },
Code::KeyC => unsafe { VkKeyScanW('c' as u16) as u16 },
Code::KeyD => unsafe { VkKeyScanW('d' as u16) as u16 },
Code::KeyE => unsafe { VkKeyScanW('e' as u16) as u16 },
Code::KeyF => unsafe { VkKeyScanW('f' as u16) as u16 },
Code::KeyG => unsafe { VkKeyScanW('g' as u16) as u16 },
Code::KeyH => unsafe { VkKeyScanW('h' as u16) as u16 },
Code::KeyI => unsafe { VkKeyScanW('i' as u16) as u16 },
Code::KeyJ => unsafe { VkKeyScanW('j' as u16) as u16 },
Code::KeyK => unsafe { VkKeyScanW('k' as u16) as u16 },
Code::KeyL => unsafe { VkKeyScanW('l' as u16) as u16 },
Code::KeyM => unsafe { VkKeyScanW('m' as u16) as u16 },
Code::KeyN => unsafe { VkKeyScanW('n' as u16) as u16 },
Code::KeyO => unsafe { VkKeyScanW('o' as u16) as u16 },
Code::KeyP => unsafe { VkKeyScanW('p' as u16) as u16 },
Code::KeyQ => unsafe { VkKeyScanW('q' as u16) as u16 },
Code::KeyR => unsafe { VkKeyScanW('r' as u16) as u16 },
Code::KeyS => unsafe { VkKeyScanW('s' as u16) as u16 },
Code::KeyT => unsafe { VkKeyScanW('t' as u16) as u16 },
Code::KeyU => unsafe { VkKeyScanW('u' as u16) as u16 },
Code::KeyV => unsafe { VkKeyScanW('v' as u16) as u16 },
Code::KeyW => unsafe { VkKeyScanW('w' as u16) as u16 },
Code::KeyX => unsafe { VkKeyScanW('x' as u16) as u16 },
Code::KeyY => unsafe { VkKeyScanW('y' as u16) as u16 },
Code::KeyZ => unsafe { VkKeyScanW('z' as u16) as u16 },
Code::Digit0 => unsafe { VkKeyScanW('0' as u16) as u16 },
Code::Digit1 => unsafe { VkKeyScanW('1' as u16) as u16 },
Code::Digit2 => unsafe { VkKeyScanW('2' as u16) as u16 },
Code::Digit3 => unsafe { VkKeyScanW('3' as u16) as u16 },
Code::Digit4 => unsafe { VkKeyScanW('4' as u16) as u16 },
Code::Digit5 => unsafe { VkKeyScanW('5' as u16) as u16 },
Code::Digit6 => unsafe { VkKeyScanW('6' as u16) as u16 },
Code::Digit7 => unsafe { VkKeyScanW('7' as u16) as u16 },
Code::Digit8 => unsafe { VkKeyScanW('8' as u16) as u16 },
Code::Digit9 => unsafe { VkKeyScanW('9' as u16) as u16 },
Code::KeyA => VK_A,
Code::KeyB => VK_B,
Code::KeyC => VK_C,
Code::KeyD => VK_D,
Code::KeyE => VK_E,
Code::KeyF => VK_F,
Code::KeyG => VK_G,
Code::KeyH => VK_H,
Code::KeyI => VK_I,
Code::KeyJ => VK_J,
Code::KeyK => VK_K,
Code::KeyL => VK_L,
Code::KeyM => VK_M,
Code::KeyN => VK_N,
Code::KeyO => VK_O,
Code::KeyP => VK_P,
Code::KeyQ => VK_Q,
Code::KeyR => VK_R,
Code::KeyS => VK_S,
Code::KeyT => VK_T,
Code::KeyU => VK_U,
Code::KeyV => VK_V,
Code::KeyW => VK_W,
Code::KeyX => VK_X,
Code::KeyY => VK_Y,
Code::KeyZ => VK_Z,
Code::Digit0 => VK_0,
Code::Digit1 => VK_1,
Code::Digit2 => VK_2,
Code::Digit3 => VK_3,
Code::Digit4 => VK_4,
Code::Digit5 => VK_5,
Code::Digit6 => VK_6,
Code::Digit7 => VK_7,
Code::Digit8 => VK_8,
Code::Digit9 => VK_9,
Code::Equal => VK_OEM_PLUS,
Code::Comma => VK_OEM_COMMA,
Code::Minus => VK_OEM_MINUS,
Code::Period => VK_OEM_PERIOD,
Code::Equal => unsafe { VkKeyScanW('=' as u16) as u16 },
Code::Semicolon => unsafe { VkKeyScanW(';' as u16) as u16 },
Code::Slash => unsafe { VkKeyScanW('/' as u16) as u16 },
Code::Backslash => unsafe { VkKeyScanW('\\' as u16) as u16 },
Code::Quote => unsafe { VkKeyScanW('\'' as u16) as u16 },
Code::Backquote => unsafe { VkKeyScanW('`' as u16) as u16 },
Code::BracketLeft => unsafe { VkKeyScanW('[' as u16) as u16 },
Code::BracketRight => unsafe { VkKeyScanW(']' as u16) as u16 },
Code::Semicolon => VK_OEM_1,
Code::Slash => VK_OEM_2,
Code::Backquote => VK_OEM_3,
Code::BracketLeft => VK_OEM_4,
Code::Backslash => VK_OEM_5,
Code::BracketRight => VK_OEM_6,
Code::Quote => VK_OEM_7,
Code::Backspace => VK_BACK,
Code::Tab => VK_TAB,
Code::Space => VK_SPACE,
Expand Down
73 changes: 37 additions & 36 deletions src/platform_impl/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,46 +226,47 @@ fn events_processor(thread_rx: Receiver<ThreadMessage>) {

fn keycode_to_x11_scancode(key: Code) -> Option<u32> {
Some(match key {
Code::KeyA => 'A' as u32,
Code::KeyB => 'B' as u32,
Code::KeyC => 'C' as u32,
Code::KeyD => 'D' as u32,
Code::KeyE => 'E' as u32,
Code::KeyF => 'F' as u32,
Code::KeyG => 'G' as u32,
Code::KeyH => 'H' as u32,
Code::KeyI => 'I' as u32,
Code::KeyJ => 'J' as u32,
Code::KeyK => 'K' as u32,
Code::KeyL => 'L' as u32,
Code::KeyM => 'M' as u32,
Code::KeyN => 'N' as u32,
Code::KeyO => 'O' as u32,
Code::KeyP => 'P' as u32,
Code::KeyQ => 'Q' as u32,
Code::KeyR => 'R' as u32,
Code::KeyS => 'S' as u32,
Code::KeyT => 'T' as u32,
Code::KeyU => 'U' as u32,
Code::KeyV => 'V' as u32,
Code::KeyW => 'W' as u32,
Code::KeyX => 'X' as u32,
Code::KeyY => 'Y' as u32,
Code::KeyZ => 'Z' as u32,
Code::KeyA => keysym::XK_A,
Code::KeyB => keysym::XK_B,
Code::KeyC => keysym::XK_C,
Code::KeyD => keysym::XK_D,
Code::KeyE => keysym::XK_E,
Code::KeyF => keysym::XK_F,
Code::KeyG => keysym::XK_G,
Code::KeyH => keysym::XK_H,
Code::KeyI => keysym::XK_I,
Code::KeyJ => keysym::XK_J,
Code::KeyK => keysym::XK_K,
Code::KeyL => keysym::XK_L,
Code::KeyM => keysym::XK_M,
Code::KeyN => keysym::XK_N,
Code::KeyO => keysym::XK_O,
Code::KeyP => keysym::XK_P,
Code::KeyQ => keysym::XK_Q,
Code::KeyR => keysym::XK_R,
Code::KeyS => keysym::XK_S,
Code::KeyT => keysym::XK_T,
Code::KeyU => keysym::XK_U,
Code::KeyV => keysym::XK_V,
Code::KeyW => keysym::XK_W,
Code::KeyX => keysym::XK_X,
Code::KeyY => keysym::XK_Y,
Code::KeyZ => keysym::XK_Z,
Code::Backslash => keysym::XK_backslash,
Code::BracketLeft => keysym::XK_bracketleft,
Code::BracketRight => keysym::XK_bracketright,
Code::Backquote => keysym::XK_quoteleft,
Code::Comma => keysym::XK_comma,
Code::Digit0 => '0' as u32,
Code::Digit1 => '1' as u32,
Code::Digit2 => '2' as u32,
Code::Digit3 => '3' as u32,
Code::Digit4 => '4' as u32,
Code::Digit5 => '5' as u32,
Code::Digit6 => '6' as u32,
Code::Digit7 => '7' as u32,
Code::Digit8 => '8' as u32,
Code::Digit9 => '9' as u32,
Code::Digit0 => keysym::XK_0,
Code::Digit1 => keysym::XK_1,
Code::Digit2 => keysym::XK_2,
Code::Digit3 => keysym::XK_3,
Code::Digit4 => keysym::XK_4,
Code::Digit5 => keysym::XK_5,
Code::Digit6 => keysym::XK_6,
Code::Digit7 => keysym::XK_7,
Code::Digit8 => keysym::XK_8,
Code::Digit9 => keysym::XK_9,
Code::Equal => keysym::XK_equal,
Code::Minus => keysym::XK_minus,
Code::Period => keysym::XK_period,
Expand Down

0 comments on commit a8345a9

Please sign in to comment.