Skip to content

Commit

Permalink
Support function keys up to F12 in Windows keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler committed Mar 7, 2023
1 parent 5d81e78 commit e454b61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ pub enum Key {
Up,
Char(char),
Super,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
}

mod private {
Expand Down
24 changes: 24 additions & 0 deletions src/win32/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ const VK_RIGHT: u16 = 0x27;
const VK_UP: u16 = 0x26;
const VK_DOWN: u16 = 0x28;
const VK_DELETE: u16 = 0x2E;
const VK_F1: u16 = 0x70;
const VK_F2: u16 = 0x71;
const VK_F3: u16 = 0x72;
const VK_F4: u16 = 0x73;
const VK_F5: u16 = 0x74;
const VK_F6: u16 = 0x75;
const VK_F7: u16 = 0x76;
const VK_F8: u16 = 0x77;
const VK_F9: u16 = 0x78;
const VK_F10: u16 = 0x79;
const VK_F11: u16 = 0x7A;
const VK_F12: u16 = 0x7B;

fn keycode_from_char(char_as_string: String) -> Result<WORD, Error> {
let buf = &mut [0; 2];
Expand Down Expand Up @@ -73,6 +85,18 @@ fn get_keycode(key: &Key) -> Result<WORD, Error> {
Key::Super => VK_LWIN,
Key::Tab => VK_TAB,
Key::Up => VK_UP,
Key::F1 => VK_F1,
Key::F2 => VK_F2,
Key::F3 => VK_F3,
Key::F4 => VK_F4,
Key::F5 => VK_F5,
Key::F6 => VK_F6,
Key::F7 => VK_F7,
Key::F8 => VK_F8,
Key::F9 => VK_F9,
Key::F10 => VK_F10,
Key::F11 => VK_F11,
Key::F12 => VK_F12,
})
}

Expand Down

0 comments on commit e454b61

Please sign in to comment.