basic_usage/
basic_usage.rs1use keyboard_codes::{
5 current_platform, parse_keyboard_input, parse_shortcut_with_aliases, Key, KeyCodeMapper,
6 Platform,
7};
8
9fn main() {
10 println!("=== 键盘代码库基础用法示例 ===\n");
11
12 println!("1. 基本键解析:");
14 let key: Key = "Enter".parse().unwrap();
15 println!(
16 " 'Enter' -> {:?} -> Windows VK: {:02X}",
17 key,
18 key.to_code(Platform::Windows)
19 );
20
21 println!("\n2. 别名支持:");
23 let inputs = ["ctrl", "esc", "return", "del", "cmd"];
24 for input in inputs {
25 if let Ok(ki) = parse_keyboard_input(input) {
26 println!(
27 " '{}' -> {} -> VK: {:02X}",
28 input,
29 ki,
30 ki.to_code(Platform::Windows)
31 );
32 }
33 }
34
35 println!("\n3. 快捷方式解析:");
37 let shortcuts = ["ctrl+c", "shift+tab", "ctrl+alt+del", "cmd+q"];
38 for shortcut in shortcuts {
39 if let Ok(parsed) = parse_shortcut_with_aliases(shortcut) {
40 println!(" '{}' -> {}", shortcut, parsed);
41 }
42 }
43
44 println!("\n4. 跨平台代码转换:");
46 let key = Key::A;
47 println!(" Key::A 代码:");
48 println!(" - Windows: {:02X}", key.to_code(Platform::Windows));
49 println!(" - Linux: {}", key.to_code(Platform::Linux));
50 println!(" - macOS: {}", key.to_code(Platform::MacOS));
51
52 println!("\n5. 当前平台: {}", current_platform());
54}