pub enum VKey {
Show 153 variants
Back,
Tab,
Clear,
Return,
Shift,
Control,
Menu,
Pause,
Capital,
Escape,
Space,
Prior,
Next,
End,
Home,
Left,
Up,
Right,
Down,
Select,
Print,
Execute,
Snapshot,
Insert,
Delete,
Help,
LWin,
RWin,
Apps,
Sleep,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
Multiply,
Add,
Separator,
Subtract,
Decimal,
Divide,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
Numlock,
Scroll,
LShift,
RShift,
LControl,
RControl,
LMenu,
RMenu,
BrowserBack,
BrowserForward,
BrowserRefresh,
BrowserStop,
BrowserSearch,
BrowserFavorites,
BrowserHome,
VolumeMute,
VolumeDown,
VolumeUp,
MediaNextTrack,
MediaPrevTrack,
MediaStop,
MediaPlayPause,
LaunchMail,
LaunchMediaSelect,
LaunchApp1,
LaunchApp2,
Oem1,
OemPlus,
OemComma,
OemMinus,
OemPeriod,
Oem2,
Oem3,
Oem4,
Oem5,
Oem6,
Oem7,
Oem8,
Oem102,
Attn,
Crsel,
Exsel,
Play,
Zoom,
Pa1,
OemClear,
Vk0,
Vk1,
Vk2,
Vk3,
Vk4,
Vk5,
Vk6,
Vk7,
Vk8,
Vk9,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
CustomKeyCode(u16),
}Expand description
Variants§
Back
Tab
Clear
Return
Shift
Control
Menu
Pause
Capital
Escape
Space
Prior
Next
End
Home
Left
Up
Right
Down
Select
Execute
Snapshot
Insert
Delete
Help
LWin
RWin
Apps
Sleep
Numpad0
Numpad1
Numpad2
Numpad3
Numpad4
Numpad5
Numpad6
Numpad7
Numpad8
Numpad9
Multiply
Add
Separator
Subtract
Decimal
Divide
F1
F2
F3
F4
F5
F6
F7
F8
F9
F10
F11
F12
F13
F14
F15
F16
F17
F18
F19
F20
F21
F22
F23
F24
Numlock
Scroll
LShift
RShift
LControl
RControl
LMenu
RMenu
BrowserBack
BrowserForward
BrowserRefresh
BrowserStop
BrowserSearch
BrowserFavorites
BrowserHome
VolumeMute
VolumeDown
VolumeUp
MediaNextTrack
MediaPrevTrack
MediaStop
MediaPlayPause
LaunchMail
LaunchMediaSelect
LaunchApp1
LaunchApp2
Oem1
OemPlus
OemComma
OemMinus
OemPeriod
Oem2
Oem3
Oem4
Oem5
Oem6
Oem7
Oem8
Oem102
Attn
Crsel
Exsel
Play
Zoom
Pa1
OemClear
Vk0
Vk1
Vk2
Vk3
Vk4
Vk5
Vk6
Vk7
Vk8
Vk9
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
CustomKeyCode(u16)
Implementations§
Source§impl VKey
impl VKey
Sourcepub const fn to_vk_code(&self) -> u16
pub const fn to_vk_code(&self) -> u16
Converts a VKey to its corresponding Windows Virtual-Key (VK) code.
§See Also
Sourcepub const fn from_vk_code(vk_code: u16) -> VKey
pub const fn from_vk_code(vk_code: u16) -> VKey
Examples found in repository?
examples/vkeys.rs (line 11)
5fn main() {
6 // Create HotkeyManager
7 let mut hkm = HotkeyManager::<()>::new();
8
9 let vk_a1 = VKey::A;
10 let vk_a2 = VKey::from_keyname("a").unwrap();
11 let vk_a3 = VKey::from_vk_code(0x41);
12 let vk_a4 = VKey::from_vk_code(VK_A.0);
13
14 // Create custom keycode equivalent to A
15 let vk_a5 = VKey::CustomKeyCode(0x41);
16
17 assert_eq!(vk_a1, vk_a2);
18 assert_eq!(vk_a1, vk_a3);
19 assert_eq!(vk_a1, vk_a4);
20 assert_eq!(vk_a1, vk_a5);
21
22 // NOTE
23 // When matching `CustomKeyCodes` you must include a guard if statement
24 match vk_a5 {
25 VKey::A => {
26 // This will never show up
27 println!("CustomKeyCode(0x41) matches against VKey::A");
28 }
29 _ => {
30 println!("You didn't use the match statement correctly!");
31 }
32 }
33
34 // Instead match like this
35 match vk_a5 {
36 _ if VKey::A == vk_a5 => {
37 // This will match
38 println!("CustomKeyCode(0x41) matches against VKey::A");
39 }
40 _ => {}
41 }
42
43 hkm.register_hotkey(vk_a5, &[], || {
44 println!("You pressed A");
45 })
46 .unwrap();
47
48 hkm.event_loop();
49}More examples
examples/simple.rs (line 17)
4fn main() {
5 let mut hkm = HotkeyManager::new();
6
7 // Register a system-wide hotkey with the trigger key 'A' and the modifier key 'ALT'
8 let trigger_key = VKey::from_keyname("a").unwrap();
9 let mod_key = VKey::from_keyname("alt").unwrap();
10 hkm.register_hotkey(trigger_key, &[mod_key], || {
11 println!("Hotkey ALT + A was pressed");
12 })
13 .unwrap();
14
15 // Register a system-wide hotkey with the trigger key 'B' and the modifier key 'f24'
16 let trigger_key = VKey::from_keyname("b").unwrap();
17 let modifiers = &[VKey::from_vk_code(0x87)];
18 hkm.register_hotkey(trigger_key, modifiers, || {
19 println!("Hotkey F24 + B was pressed");
20 })
21 .unwrap();
22
23 // Register a system-wide hotkey with the trigger key 'C' and multiple modifier key
24 hkm.register_hotkey(VKey::C, &[VKey::LWin, VKey::Menu], || {
25 println!("Hotkey WIN + ALT + C was pressed");
26 })
27 .unwrap();
28
29 // Register and store id for system-wide hotkey with trigger key 'D' and modifier key 'ALT'
30 let hotkey_id = hkm
31 .register_hotkey(
32 VKey::from_vk_code(0x44),
33 &[VKey::from_vk_code(0xA4)],
34 || {
35 println!("Hotkey ALT + D was pressed");
36 },
37 )
38 .unwrap();
39
40 // Unregister hotkey with ID
41 hkm.unregister_hotkey(hotkey_id);
42
43 // Run the event handler in a blocking loop. This will block forever and execute the set
44 // callbacks when the registered hotkeys are detected
45 hkm.event_loop();
46}Sourcepub fn from_keyname(name: &str) -> Result<VKey, WHKError>
pub fn from_keyname(name: &str) -> Result<VKey, WHKError>
Creates a VKey from a string representation of the key.
NOTE: Certain common aliases for keys are accepted in addition to the Microsoft Virtual-Key Codes names
WIN maps to VKey::LWin
CTRL maps to VKey::Control
ALT maps to VKey::Menu
§See Also
Examples found in repository?
examples/vkeys.rs (line 10)
5fn main() {
6 // Create HotkeyManager
7 let mut hkm = HotkeyManager::<()>::new();
8
9 let vk_a1 = VKey::A;
10 let vk_a2 = VKey::from_keyname("a").unwrap();
11 let vk_a3 = VKey::from_vk_code(0x41);
12 let vk_a4 = VKey::from_vk_code(VK_A.0);
13
14 // Create custom keycode equivalent to A
15 let vk_a5 = VKey::CustomKeyCode(0x41);
16
17 assert_eq!(vk_a1, vk_a2);
18 assert_eq!(vk_a1, vk_a3);
19 assert_eq!(vk_a1, vk_a4);
20 assert_eq!(vk_a1, vk_a5);
21
22 // NOTE
23 // When matching `CustomKeyCodes` you must include a guard if statement
24 match vk_a5 {
25 VKey::A => {
26 // This will never show up
27 println!("CustomKeyCode(0x41) matches against VKey::A");
28 }
29 _ => {
30 println!("You didn't use the match statement correctly!");
31 }
32 }
33
34 // Instead match like this
35 match vk_a5 {
36 _ if VKey::A == vk_a5 => {
37 // This will match
38 println!("CustomKeyCode(0x41) matches against VKey::A");
39 }
40 _ => {}
41 }
42
43 hkm.register_hotkey(vk_a5, &[], || {
44 println!("You pressed A");
45 })
46 .unwrap();
47
48 hkm.event_loop();
49}More examples
examples/simple.rs (line 8)
4fn main() {
5 let mut hkm = HotkeyManager::new();
6
7 // Register a system-wide hotkey with the trigger key 'A' and the modifier key 'ALT'
8 let trigger_key = VKey::from_keyname("a").unwrap();
9 let mod_key = VKey::from_keyname("alt").unwrap();
10 hkm.register_hotkey(trigger_key, &[mod_key], || {
11 println!("Hotkey ALT + A was pressed");
12 })
13 .unwrap();
14
15 // Register a system-wide hotkey with the trigger key 'B' and the modifier key 'f24'
16 let trigger_key = VKey::from_keyname("b").unwrap();
17 let modifiers = &[VKey::from_vk_code(0x87)];
18 hkm.register_hotkey(trigger_key, modifiers, || {
19 println!("Hotkey F24 + B was pressed");
20 })
21 .unwrap();
22
23 // Register a system-wide hotkey with the trigger key 'C' and multiple modifier key
24 hkm.register_hotkey(VKey::C, &[VKey::LWin, VKey::Menu], || {
25 println!("Hotkey WIN + ALT + C was pressed");
26 })
27 .unwrap();
28
29 // Register and store id for system-wide hotkey with trigger key 'D' and modifier key 'ALT'
30 let hotkey_id = hkm
31 .register_hotkey(
32 VKey::from_vk_code(0x44),
33 &[VKey::from_vk_code(0xA4)],
34 || {
35 println!("Hotkey ALT + D was pressed");
36 },
37 )
38 .unwrap();
39
40 // Unregister hotkey with ID
41 hkm.unregister_hotkey(hotkey_id);
42
43 // Run the event handler in a blocking loop. This will block forever and execute the set
44 // callbacks when the registered hotkeys are detected
45 hkm.event_loop();
46}Trait Implementations§
impl Copy for VKey
impl Eq for VKey
Auto Trait Implementations§
impl Freeze for VKey
impl RefUnwindSafe for VKey
impl Send for VKey
impl Sync for VKey
impl Unpin for VKey
impl UnwindSafe for VKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more