Skip to content

Commit e454b61

Browse files
Support function keys up to F12 in Windows keyboard
1 parent 5d81e78 commit e454b61

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ pub enum Key {
2424
Up,
2525
Char(char),
2626
Super,
27+
F1,
28+
F2,
29+
F3,
30+
F4,
31+
F5,
32+
F6,
33+
F7,
34+
F8,
35+
F9,
36+
F10,
37+
F11,
38+
F12,
2739
}
2840

2941
mod private {

src/win32/keyboard.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ const VK_RIGHT: u16 = 0x27;
3434
const VK_UP: u16 = 0x26;
3535
const VK_DOWN: u16 = 0x28;
3636
const VK_DELETE: u16 = 0x2E;
37+
const VK_F1: u16 = 0x70;
38+
const VK_F2: u16 = 0x71;
39+
const VK_F3: u16 = 0x72;
40+
const VK_F4: u16 = 0x73;
41+
const VK_F5: u16 = 0x74;
42+
const VK_F6: u16 = 0x75;
43+
const VK_F7: u16 = 0x76;
44+
const VK_F8: u16 = 0x77;
45+
const VK_F9: u16 = 0x78;
46+
const VK_F10: u16 = 0x79;
47+
const VK_F11: u16 = 0x7A;
48+
const VK_F12: u16 = 0x7B;
3749

3850
fn keycode_from_char(char_as_string: String) -> Result<WORD, Error> {
3951
let buf = &mut [0; 2];
@@ -73,6 +85,18 @@ fn get_keycode(key: &Key) -> Result<WORD, Error> {
7385
Key::Super => VK_LWIN,
7486
Key::Tab => VK_TAB,
7587
Key::Up => VK_UP,
88+
Key::F1 => VK_F1,
89+
Key::F2 => VK_F2,
90+
Key::F3 => VK_F3,
91+
Key::F4 => VK_F4,
92+
Key::F5 => VK_F5,
93+
Key::F6 => VK_F6,
94+
Key::F7 => VK_F7,
95+
Key::F8 => VK_F8,
96+
Key::F9 => VK_F9,
97+
Key::F10 => VK_F10,
98+
Key::F11 => VK_F11,
99+
Key::F12 => VK_F12,
76100
})
77101
}
78102

0 commit comments

Comments
 (0)