advanced_parsing/
advanced_parsing.rs1use keyboard_codes::{
6 parse_shortcut_flexible, parse_shortcut_sequence, CustomKey, CustomKeyMap, Platform,
7};
8
9fn main() {
10 println!("=== 高级解析功能示例 ===\n");
11
12 println!("1. 灵活的分隔符支持:");
14 let shortcuts = ["ctrl+c", "ctrl-c", "ctrl c", "ctrl+shift+esc"];
15 for shortcut in shortcuts {
16 if let Ok(parsed) = parse_shortcut_flexible(shortcut) {
17 println!(" '{}' -> {}", shortcut, parsed);
18 }
19 }
20
21 println!("\n2. 快捷方式序列:");
23 let sequence = "ctrl+c, ctrl+v, ctrl+z, ctrl+y";
24 if let Ok(shortcuts) = parse_shortcut_sequence(sequence) {
25 for (i, shortcut) in shortcuts.iter().enumerate() {
26 println!(" {}: {}", i + 1, shortcut);
27 }
28 }
29
30 println!("\n3. 自定义键映射:");
32 let mut custom_map = CustomKeyMap::new();
33 let mut custom_key = CustomKey::new("MyCustomKey");
34 custom_key
35 .add_platform_code(Platform::Windows, 0x100)
36 .add_platform_code(Platform::Linux, 500);
37
38 if custom_map.add_key(custom_key).is_ok() {
39 println!(" 自定义键添加成功");
40 }
41
42 println!("\n示例完成!");
43}