i_slint_common/
key_codes.rs

1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4//! This module is meant to be included by different crates and each crate must define the macro for_each_special_keys
5//!
6//! The key code comes from <https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/CORPCHAR.TXT>
7//! the names comes should match with <https://www.w3.org/TR/uievents-key/#named-key-attribute-values>,
8//!
9//! The format is a semicolon separated list of keys
10//! `<char code>  # Slint name # Qt code # Winit code # xkb code`
11//!
12//! ## Example
13//!
14//! ```
15//! macro_rules! do_something_with_keys {
16//!     ($($char:literal # $name:ident # $($qt:ident)|* # $($winit:ident $(($_pos:ident))?)|* # $($xkb:ident)|* ;)*) => {
17//!         //...
18//!     };
19//! }
20//! i_slint_common::for_each_special_keys!(do_something_with_keys);
21//! ```
22//!
23// NOTE: Update docs/astro/src/content/docs/reference/keyboard-input/overview.mdx when changing/adding/removing keys, to keep the docs in sync!
24#[macro_export]
25macro_rules! for_each_special_keys {
26    ($macro:ident) => {
27        $macro![
28'\u{0008}'  # Backspace   # Qt_Key_Key_Backspace    # Backspace    # BackSpace  ;
29'\u{0009}'  # Tab         # Qt_Key_Key_Tab          # Tab          # Tab        ;
30'\u{000a}'  # Return      # Qt_Key_Key_Enter|Qt_Key_Key_Return # Enter # Return;
31'\u{001b}'  # Escape      # Qt_Key_Key_Escape       # Escape       # Escape     ;
32'\u{0019}'  # Backtab     # Qt_Key_Key_Backtab      #              # BackTab    ;
33'\u{007f}'  # Delete      # Qt_Key_Key_Delete       # Delete       # Delete     ;
34
35// The modifier key codes comes from https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode.
36'\u{0010}'  # Shift       # Qt_Key_Key_Shift        # Shift(Left)  # Shift_L    ;
37'\u{0011}'  # Control     # Qt_Key_Key_Control      # Control(Left)# Control_L  ;
38'\u{0012}'  # Alt         # Qt_Key_Key_Alt          # Alt          # Alt_L      ;
39'\u{0013}'  # AltGr       # Qt_Key_Key_AltGr        # AltGraph     # Mode_switch;
40'\u{0014}'  # CapsLock    # Qt_Key_Key_CapsLock     #              # Caps_Lock  ;
41
42'\u{0015}'  # ShiftR      #                         # Shift(Right) # Shift_R    ;
43'\u{0016}'  # ControlR    #                         # Control(Right)# Control_R  ;
44
45// Use custom codes instead of DOM_VK_META for meta, because the Mozilla defined code is a regular character (E0; LATIN SMALL LETTER A WITH GRAVE)
46// which makes those keys appear as text.
47'\u{0017}'  # Meta        # Qt_Key_Key_Meta         # Super(Left)  # Meta_L     ;
48'\u{0018}'  # MetaR       #                         # Super(Right) # Meta_R     ;
49
50'\u{0020}'  # Space       # Qt_Key_Key_Space        # Space # space     ;
51
52'\u{F700}'	# UpArrow     # Qt_Key_Key_Up           # ArrowUp           # Up         ;
53'\u{F701}'	# DownArrow   # Qt_Key_Key_Down         # ArrowDown         # Down       ;
54'\u{F702}'	# LeftArrow   # Qt_Key_Key_Left         # ArrowLeft         # Left       ;
55'\u{F703}'	# RightArrow  # Qt_Key_Key_Right        # ArrowRight        # Right      ;
56'\u{F704}'	# F1          # Qt_Key_Key_F1           # F1           # F1         ;
57'\u{F705}'	# F2          # Qt_Key_Key_F2           # F2           # F2         ;
58'\u{F706}'	# F3          # Qt_Key_Key_F3           # F3           # F3         ;
59'\u{F707}'	# F4          # Qt_Key_Key_F4           # F4           # F4         ;
60'\u{F708}'	# F5          # Qt_Key_Key_F5           # F5           # F5         ;
61'\u{F709}'	# F6          # Qt_Key_Key_F6           # F6           # F6         ;
62'\u{F70A}'	# F7          # Qt_Key_Key_F7           # F7           # F7         ;
63'\u{F70B}'	# F8          # Qt_Key_Key_F8           # F8           # F8         ;
64'\u{F70C}'	# F9          # Qt_Key_Key_F9           # F9           # F9         ;
65'\u{F70D}'	# F10         # Qt_Key_Key_F10          # F10          # F10        ;
66'\u{F70E}'	# F11         # Qt_Key_Key_F11          # F11          # F11        ;
67'\u{F70F}'	# F12         # Qt_Key_Key_F12          # F12          # F12        ;
68'\u{F710}'	# F13         # Qt_Key_Key_F13          # F13          # F13        ;
69'\u{F711}'	# F14         # Qt_Key_Key_F14          # F14          # F14        ;
70'\u{F712}'	# F15         # Qt_Key_Key_F15          # F15          # F15        ;
71'\u{F713}'	# F16         # Qt_Key_Key_F16          # F16          # F16        ;
72'\u{F714}'	# F17         # Qt_Key_Key_F17          # F17          # F17        ;
73'\u{F715}'	# F18         # Qt_Key_Key_F18          # F18          # F18        ;
74'\u{F716}'	# F19         # Qt_Key_Key_F19          # F19          # F19        ;
75'\u{F717}'	# F20         # Qt_Key_Key_F20          # F20          # F20        ;
76'\u{F718}'	# F21         # Qt_Key_Key_F21          # F21          # F21        ;
77'\u{F719}'	# F22         # Qt_Key_Key_F22          # F22          # F22        ;
78'\u{F71A}'	# F23         # Qt_Key_Key_F23          # F23          # F23        ;
79'\u{F71B}'	# F24         # Qt_Key_Key_F24          # F24          # F24        ;
80//'\u{F71C}'# F25         # Qt_Key_Key_F25          # F25          # F25        ;
81//'\u{F71D}'# F26         # Qt_Key_Key_F26          # F26          # F26        ;
82//'\u{F71E}'# F27         # Qt_Key_Key_F27          # F27          # F27        ;
83//'\u{F71F}'# F28         # Qt_Key_Key_F28          # F28          # F28        ;
84//'\u{F720}'# F29         # Qt_Key_Key_F29          # F29          # F29        ;
85//'\u{F721}'# F30         # Qt_Key_Key_F30          # F30          # F30        ;
86//'\u{F722}'# F31         # Qt_Key_Key_F31          # F31          # F31        ;
87//'\u{F723}'# F32         # Qt_Key_Key_F32          # F32          # F32        ;
88//'\u{F724}'# F33         # Qt_Key_Key_F33          # F33          # F33        ;
89//'\u{F725}'# F34         # Qt_Key_Key_F34          # F34          # F34        ;
90//'\u{F726}'# F35         # Qt_Key_Key_F35          # F35          # F35        ;
91'\u{F727}'	# Insert      # Qt_Key_Key_Insert       # Insert       # Insert     ;
92//'\u{F728}'	# Delete     ;  // already as a control code
93'\u{F729}'	# Home        # Qt_Key_Key_Home         # Home         # Home       ;
94//'\u{F72A}'	# Begin       #                         #              ;
95'\u{F72B}'	# End         # Qt_Key_Key_End          # End          # End        ;
96'\u{F72C}'	# PageUp      # Qt_Key_Key_PageUp       # PageUp       # Page_Up    ;
97'\u{F72D}'	# PageDown    # Qt_Key_Key_PageDown     # PageDown     # Page_Down  ;
98//'\u{F72E}'	# PrintScreen #                         # Snapshot     ;
99'\u{F72F}'	# ScrollLock  # Qt_Key_Key_ScrollLock   # ScrollLock   # Scroll_Lock;
100'\u{F730}'	# Pause       # Qt_Key_Key_Pause        # Pause        # Pause      ;
101'\u{F731}'	# SysReq      # Qt_Key_Key_SysReq       # PrintScreen  # Sys_Req    ;
102//'\u{F732}'	# Break       #                         #              ;
103//'\u{F733}'	# Reset       #                         #              ;
104'\u{F734}'	# Stop        # Qt_Key_Key_Stop         #              # XF86_Stop       ;
105'\u{F735}'	# Menu        # Qt_Key_Key_Menu         # ContextMenu  # Menu       ;
106//'\u{F736}'	# User        #                         #              ;
107//'\u{F737}'	# System      #                         #              ;
108//'\u{F738}'	# Print       # Qt_Key_Key_Print        #              ;
109//'\u{F739}'	# ClearLine   #                         #              ;
110//'\u{F73A}'	# ClearDisplay#                         #              ;
111//'\u{F73B}'	# InsertLine  #                         #              ;
112//'\u{F73C}'	# DeleteLine  #                         #              ;
113//'\u{F73D}'	# InsertChar  #                         #              ;
114//'\u{F73E}'	# DeleteChar  #                         #              ;
115//'\u{F73F}'	# Prev        #                         #              ;
116//'\u{F740}'	# Next        #                         #              ;
117//'\u{F741}'	# Select      # Qt_Key_Key_Select       #              ;
118//'\u{F742}'	# Execute     # Qt_Key_Key_Execute      #              ;
119//'\u{F743}'	# Undo        # Qt_Key_Key_Undo         #              ;
120//'\u{F744}'	# Redo        # Qt_Key_Key_Redo         #              ;
121//'\u{F745}'	# Find        # Qt_Key_Key_Find         #              ;
122//'\u{F746}'	# Help        # Qt_Key_Key_Help         #              ;
123//'\u{F747}'	# ModeSwitch  # Qt_Key_Key_Mode_switch  #            ;
124'\u{F748}'	# Back  # Qt_Key_Key_Back  #           #    ;
125];
126    };
127}