libnotcurses_sys/key/
key.rs

1//!
2
3/// A synthesized input event.
4///
5/// This means any input event we can report that isn't representative
6/// of some Unicode. This covers both keyboard and mouse events, as well as
7/// signals and even window events.
8///
9/// See also [`PRETERUNICODEBASE`][c_api::PRETERUNICODEBASE].
10#[repr(transparent)]
11#[derive(Clone, Copy, PartialEq, Eq)]
12pub struct NcKey(pub u32);
13
14mod core_impls {
15    use super::NcKey;
16    use core::fmt;
17
18    impl fmt::Display for NcKey {
19        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20            write!(f, "{}", self.name())
21        }
22    }
23
24    impl fmt::Debug for NcKey {
25        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26            write!(f, "NcKey::{}", self)
27        }
28    }
29
30    impl From<NcKey> for u32 {
31        fn from(k: NcKey) -> Self {
32            k.0
33        }
34    }
35}
36
37/// # Constants
38impl NcKey {
39    pub const Invalid: NcKey = NcKey(c_api::NCKEY_INVALID);
40    /// we received `SIGWINCH`.
41    pub const Resize: NcKey = NcKey(c_api::NCKEY_RESIZE);
42    pub const Up: NcKey = NcKey(c_api::NCKEY_UP);
43    pub const Right: NcKey = NcKey(c_api::NCKEY_RIGHT);
44    pub const Down: NcKey = NcKey(c_api::NCKEY_DOWN);
45    pub const Left: NcKey = NcKey(c_api::NCKEY_LEFT);
46    pub const Ins: NcKey = NcKey(c_api::NCKEY_INS);
47    pub const Del: NcKey = NcKey(c_api::NCKEY_DEL);
48    pub const Backspace: NcKey = NcKey(c_api::NCKEY_BACKSPACE);
49    pub const PgDown: NcKey = NcKey(c_api::NCKEY_PGDOWN);
50    pub const PgUp: NcKey = NcKey(c_api::NCKEY_PGUP);
51    pub const Home: NcKey = NcKey(c_api::NCKEY_HOME);
52    pub const End: NcKey = NcKey(c_api::NCKEY_END);
53    pub const F00: NcKey = NcKey(c_api::NCKEY_F00);
54    pub const F01: NcKey = NcKey(c_api::NCKEY_F01);
55    pub const F02: NcKey = NcKey(c_api::NCKEY_F02);
56    pub const F03: NcKey = NcKey(c_api::NCKEY_F03);
57    pub const F04: NcKey = NcKey(c_api::NCKEY_F04);
58    pub const F05: NcKey = NcKey(c_api::NCKEY_F05);
59    pub const F06: NcKey = NcKey(c_api::NCKEY_F06);
60    pub const F07: NcKey = NcKey(c_api::NCKEY_F07);
61    pub const F08: NcKey = NcKey(c_api::NCKEY_F08);
62    pub const F09: NcKey = NcKey(c_api::NCKEY_F09);
63    pub const F10: NcKey = NcKey(c_api::NCKEY_F10);
64    pub const F11: NcKey = NcKey(c_api::NCKEY_F11);
65    pub const F12: NcKey = NcKey(c_api::NCKEY_F12);
66    pub const F13: NcKey = NcKey(c_api::NCKEY_F13);
67    pub const F14: NcKey = NcKey(c_api::NCKEY_F14);
68    pub const F15: NcKey = NcKey(c_api::NCKEY_F15);
69    pub const F16: NcKey = NcKey(c_api::NCKEY_F16);
70    pub const F17: NcKey = NcKey(c_api::NCKEY_F17);
71    pub const F18: NcKey = NcKey(c_api::NCKEY_F18);
72    pub const F19: NcKey = NcKey(c_api::NCKEY_F19);
73    pub const F20: NcKey = NcKey(c_api::NCKEY_F20);
74    pub const F21: NcKey = NcKey(c_api::NCKEY_F21);
75    pub const F22: NcKey = NcKey(c_api::NCKEY_F22);
76    pub const F23: NcKey = NcKey(c_api::NCKEY_F23);
77    pub const F24: NcKey = NcKey(c_api::NCKEY_F24);
78    pub const F25: NcKey = NcKey(c_api::NCKEY_F25);
79    pub const F26: NcKey = NcKey(c_api::NCKEY_F26);
80    pub const F27: NcKey = NcKey(c_api::NCKEY_F27);
81    pub const F28: NcKey = NcKey(c_api::NCKEY_F28);
82    pub const F29: NcKey = NcKey(c_api::NCKEY_F29);
83    pub const F30: NcKey = NcKey(c_api::NCKEY_F30);
84    pub const F31: NcKey = NcKey(c_api::NCKEY_F31);
85    pub const F32: NcKey = NcKey(c_api::NCKEY_F32);
86    pub const F33: NcKey = NcKey(c_api::NCKEY_F33);
87    pub const F34: NcKey = NcKey(c_api::NCKEY_F34);
88    pub const F35: NcKey = NcKey(c_api::NCKEY_F35);
89    pub const F36: NcKey = NcKey(c_api::NCKEY_F36);
90    pub const F37: NcKey = NcKey(c_api::NCKEY_F37);
91    pub const F38: NcKey = NcKey(c_api::NCKEY_F38);
92    pub const F39: NcKey = NcKey(c_api::NCKEY_F39);
93    pub const F40: NcKey = NcKey(c_api::NCKEY_F40);
94    pub const F41: NcKey = NcKey(c_api::NCKEY_F41);
95    pub const F42: NcKey = NcKey(c_api::NCKEY_F42);
96    pub const F43: NcKey = NcKey(c_api::NCKEY_F43);
97    pub const F44: NcKey = NcKey(c_api::NCKEY_F44);
98    pub const F45: NcKey = NcKey(c_api::NCKEY_F45);
99    pub const F46: NcKey = NcKey(c_api::NCKEY_F46);
100    pub const F47: NcKey = NcKey(c_api::NCKEY_F47);
101    pub const F48: NcKey = NcKey(c_api::NCKEY_F48);
102    pub const F49: NcKey = NcKey(c_api::NCKEY_F49);
103    pub const F50: NcKey = NcKey(c_api::NCKEY_F50);
104    pub const F51: NcKey = NcKey(c_api::NCKEY_F51);
105    pub const F52: NcKey = NcKey(c_api::NCKEY_F52);
106    pub const F53: NcKey = NcKey(c_api::NCKEY_F53);
107    pub const F54: NcKey = NcKey(c_api::NCKEY_F54);
108    pub const F55: NcKey = NcKey(c_api::NCKEY_F55);
109    pub const F56: NcKey = NcKey(c_api::NCKEY_F56);
110    pub const F57: NcKey = NcKey(c_api::NCKEY_F57);
111    pub const F58: NcKey = NcKey(c_api::NCKEY_F58);
112    pub const F59: NcKey = NcKey(c_api::NCKEY_F59);
113    pub const F60: NcKey = NcKey(c_api::NCKEY_F60);
114
115    // ... leave room for function keys.
116
117    pub const Enter: NcKey = NcKey(c_api::NCKEY_ENTER);
118    /// "clear-screen or erase"
119    pub const Cls: NcKey = NcKey(c_api::NCKEY_CLS);
120    /// down + left on keypad
121    pub const DLeft: NcKey = NcKey(c_api::NCKEY_DLEFT);
122    pub const DRight: NcKey = NcKey(c_api::NCKEY_DRIGHT);
123    /// up + left on keypad
124    pub const ULeft: NcKey = NcKey(c_api::NCKEY_ULEFT);
125    pub const URight: NcKey = NcKey(c_api::NCKEY_URIGHT);
126    pub const Center: NcKey = NcKey(c_api::NCKEY_CENTER);
127    pub const Begin: NcKey = NcKey(c_api::NCKEY_BEGIN);
128    pub const Cancel: NcKey = NcKey(c_api::NCKEY_CANCEL);
129    pub const Close: NcKey = NcKey(c_api::NCKEY_CLOSE);
130    pub const Command: NcKey = NcKey(c_api::NCKEY_COMMAND);
131    pub const Copy: NcKey = NcKey(c_api::NCKEY_COPY);
132    pub const Exit: NcKey = NcKey(c_api::NCKEY_EXIT);
133    pub const Print: NcKey = NcKey(c_api::NCKEY_PRINT);
134    pub const Refresh: NcKey = NcKey(c_api::NCKEY_REFRESH);
135
136    // these keys aren't generally available outside of the kitty protocol:
137
138    pub const CapsLock: NcKey = NcKey(c_api::NCKEY_CAPS_LOCK);
139    pub const ScrollLock: NcKey = NcKey(c_api::NCKEY_SCROLL_LOCK);
140    pub const NumLock: NcKey = NcKey(c_api::NCKEY_NUM_LOCK);
141    pub const PrintScreen: NcKey = NcKey(c_api::NCKEY_PRINT_SCREEN);
142    pub const Pause: NcKey = NcKey(c_api::NCKEY_PAUSE);
143    pub const Menu: NcKey = NcKey(c_api::NCKEY_MENU);
144
145    // media keys, similarly only available through kitty's protocol:
146
147    pub const MediaPlay: NcKey = NcKey(c_api::NCKEY_MEDIA_PLAY);
148    pub const MediaPause: NcKey = NcKey(c_api::NCKEY_MEDIA_PAUSE);
149    pub const MediaPPause: NcKey = NcKey(c_api::NCKEY_MEDIA_PPAUSE);
150    pub const MediaRev: NcKey = NcKey(c_api::NCKEY_MEDIA_REV);
151    pub const MediaStop: NcKey = NcKey(c_api::NCKEY_MEDIA_STOP);
152    pub const MediaFF: NcKey = NcKey(c_api::NCKEY_MEDIA_FF);
153    pub const MediaRewind: NcKey = NcKey(c_api::NCKEY_MEDIA_REWIND);
154    pub const MediaNext: NcKey = NcKey(c_api::NCKEY_MEDIA_NEXT);
155    pub const MediaPrev: NcKey = NcKey(c_api::NCKEY_MEDIA_PREV);
156    pub const MediaRecord: NcKey = NcKey(c_api::NCKEY_MEDIA_RECORD);
157    pub const MediaLVol: NcKey = NcKey(c_api::NCKEY_MEDIA_LVOL);
158    pub const MediaRVol: NcKey = NcKey(c_api::NCKEY_MEDIA_RVOL);
159    pub const MediaMute: NcKey = NcKey(c_api::NCKEY_MEDIA_MUTE);
160
161    // modifiers when pressed by themselves. this ordering comes from the Kitty
162    // keyboard protocol, and mustn't be changed without updating handlers:
163
164    pub const LShift: NcKey = NcKey(c_api::NCKEY_LSHIFT);
165    pub const LCtrl: NcKey = NcKey(c_api::NCKEY_LCTRL);
166    pub const LAlt: NcKey = NcKey(c_api::NCKEY_LALT);
167    pub const LSuper: NcKey = NcKey(c_api::NCKEY_LSUPER);
168    pub const LHyper: NcKey = NcKey(c_api::NCKEY_LHYPER);
169    pub const LMeta: NcKey = NcKey(c_api::NCKEY_LMETA);
170    pub const RShift: NcKey = NcKey(c_api::NCKEY_RSHIFT);
171    pub const RCtrl: NcKey = NcKey(c_api::NCKEY_RCTRL);
172    pub const RAlt: NcKey = NcKey(c_api::NCKEY_RALT);
173    pub const RSuper: NcKey = NcKey(c_api::NCKEY_RSUPER);
174    pub const RHyper: NcKey = NcKey(c_api::NCKEY_RHYPER);
175    pub const RMeta: NcKey = NcKey(c_api::NCKEY_RMETA);
176    /// `AltGr` in european keyboards
177    pub const L3Shift: NcKey = NcKey(c_api::NCKEY_L3SHIFT);
178    pub const L5Shift: NcKey = NcKey(c_api::NCKEY_L5SHIFT);
179
180    // Mouse events. We encode which button was pressed into the number,
181    // but position information is embedded in the larger ncinput event:
182
183    pub const Motion: NcKey = NcKey(c_api::NCKEY_MOTION);
184    pub const Button1: NcKey = NcKey(c_api::NCKEY_BUTTON1);
185    pub const Button2: NcKey = NcKey(c_api::NCKEY_BUTTON2);
186    pub const Button3: NcKey = NcKey(c_api::NCKEY_BUTTON3);
187    /// scrollwheel up
188    pub const Button4: NcKey = NcKey(c_api::NCKEY_BUTTON4);
189    /// scrollwheel down
190    pub const Button5: NcKey = NcKey(c_api::NCKEY_BUTTON5);
191    pub const Button6: NcKey = NcKey(c_api::NCKEY_BUTTON6);
192    pub const Button7: NcKey = NcKey(c_api::NCKEY_BUTTON7);
193    pub const Button8: NcKey = NcKey(c_api::NCKEY_BUTTON8);
194    pub const Button9: NcKey = NcKey(c_api::NCKEY_BUTTON9);
195    pub const Button10: NcKey = NcKey(c_api::NCKEY_BUTTON10);
196    pub const Button11: NcKey = NcKey(c_api::NCKEY_BUTTON11);
197
198    /// we received SIGCONT
199    pub const Signal: NcKey = NcKey(c_api::NCKEY_SIGNAL);
200
201    /// Will be returned upon reaching the end of input.
202    pub const Eof: NcKey = NcKey(c_api::NCKEY_EOF);
203
204    // Aliases from the 128 characters common to ASCII+UTF8:
205    pub const Tab: NcKey = NcKey(c_api::NCKEY_TAB);
206    pub const Esc: NcKey = NcKey(c_api::NCKEY_ESC);
207    pub const Space: NcKey = NcKey(c_api::NCKEY_SPACE);
208}
209
210/// # Aliases
211impl NcKey {
212    /// Alias of [`Button4`][NcKey::Button4]
213    pub const ScrollUp: NcKey = NcKey(c_api::NCKEY_SCROLL_UP);
214    /// Alias of [`Button5`][NcKey::Button5]
215    pub const Scrolldown: NcKey = NcKey(c_api::NCKEY_SCROLL_DOWN);
216    /// Alias of [`Enter`][NcKey::Enter]
217    pub const Return: NcKey = NcKey(c_api::NCKEY_RETURN);
218}
219
220/// # Methods
221impl NcKey {
222    /// Checks whether a number falls in the range of synthesized events.
223    pub fn is(num: u32) -> bool {
224        crate::c_api::nckey_synthesized_p(num) || num == NcKey::Esc.0 || num == NcKey::Tab.0
225    }
226
227    /// Returns a new `NcKey` if the provided number falls in the correct range.
228    pub fn new(num: u32) -> Option<Self> {
229        if Self::is(num) {
230            Some(Self(num))
231        } else {
232            None
233        }
234    }
235
236    //
237
238    /// Returns true if it's a function key event.
239    pub fn is_function(&self) -> bool {
240        matches!(self.0, c_api::NCKEY_F00..=c_api::NCKEY_F60)
241    }
242
243    /// Returns true if it's a multimedia key event.
244    pub fn is_media(&self) -> bool {
245        matches!(self.0, c_api::NCKEY_MEDIA_PLAY..=c_api::NCKEY_MEDIA_MUTE)
246    }
247
248    /// Returns true if it's a mouse event.
249    pub fn is_mouse(&self) -> bool {
250        matches!(self.0, c_api::NCKEY_MOTION..=c_api::NCKEY_BUTTON11)
251    }
252
253    /// Returns true if it's a resize event.
254    pub fn is_resize(&self) -> bool {
255        matches!(self.0, c_api::NCKEY_RESIZE)
256    }
257
258    //
259
260    /// Returns the name of the current `NcKey`.
261    pub fn name(&self) -> &'static str {
262        Self::check_name(self.0)
263    }
264
265    /// Returns the name of the `NcKey` the number would be.
266    pub fn check_name(num: u32) -> &'static str {
267        if Self::is(num) {
268            match Self(num) {
269                Self::Invalid => "Invalid",
270                Self::Resize => "Resize",
271                Self::Up => "Up",
272                Self::Right => "Right",
273                Self::Down => "Down",
274                Self::Left => "Left",
275                Self::Ins => "Ins",
276                Self::Del => "Del",
277                Self::Backspace => "Backspace",
278                Self::PgDown => "PgDown",
279                Self::PgUp => "PgUp",
280                Self::Home => "Home",
281                Self::End => "End",
282                Self::F00 => "F00",
283                Self::F01 => "F01",
284                Self::F02 => "F02",
285                Self::F03 => "F03",
286                Self::F04 => "F04",
287                Self::F05 => "F05",
288                Self::F06 => "F06",
289                Self::F07 => "F07",
290                Self::F08 => "F08",
291                Self::F09 => "F09",
292                Self::F10 => "F10",
293                Self::F11 => "F11",
294                Self::F12 => "F12",
295                Self::F13 => "F13",
296                Self::F14 => "F14",
297                Self::F15 => "F15",
298                Self::F16 => "F16",
299                Self::F17 => "F17",
300                Self::F18 => "F18",
301                Self::F19 => "F19",
302                Self::F20 => "F20",
303                Self::F21 => "F21",
304                Self::F22 => "F22",
305                Self::F23 => "F23",
306                Self::F24 => "F24",
307                Self::F25 => "F25",
308                Self::F26 => "F26",
309                Self::F27 => "F27",
310                Self::F28 => "F28",
311                Self::F29 => "F29",
312                Self::F30 => "F30",
313                Self::F31 => "F31",
314                Self::F32 => "F32",
315                Self::F33 => "F33",
316                Self::F34 => "F34",
317                Self::F35 => "F35",
318                Self::F36 => "F36",
319                Self::F37 => "F37",
320                Self::F38 => "F38",
321                Self::F39 => "F39",
322                Self::F40 => "F40",
323                Self::F41 => "F41",
324                Self::F42 => "F42",
325                Self::F43 => "F43",
326                Self::F44 => "F44",
327                Self::F45 => "F45",
328                Self::F46 => "F46",
329                Self::F47 => "F47",
330                Self::F48 => "F48",
331                Self::F49 => "F49",
332                Self::F50 => "F50",
333                Self::F51 => "F51",
334                Self::F52 => "F52",
335                Self::F53 => "F53",
336                Self::F54 => "F54",
337                Self::F55 => "F55",
338                Self::F56 => "F56",
339                Self::F57 => "F57",
340                Self::F58 => "F58",
341                Self::F59 => "F59",
342                Self::F60 => "F60",
343
344                Self::Enter => "Enter",
345                Self::Cls => "Cls",
346                Self::DLeft => "DLeft",
347                Self::DRight => "DRight",
348                Self::ULeft => "ULeft",
349                Self::URight => "URight",
350                Self::Center => "Center",
351                Self::Begin => "Begin",
352                Self::Cancel => "Cancel",
353                Self::Close => "Close",
354                Self::Command => "Command",
355                Self::Copy => "Copy",
356                Self::Exit => "Exit",
357                Self::Print => "Print",
358                Self::Refresh => "Refresh",
359
360                Self::CapsLock => "CapsLock",
361                Self::ScrollLock => "ScrollLock",
362                Self::NumLock => "NumLock",
363                Self::PrintScreen => "PrintScreen",
364                Self::Pause => "Pause",
365                Self::Menu => "Menu",
366
367                Self::MediaPlay => "MediaPlay",
368                Self::MediaPause => "MediaPause",
369                Self::MediaPPause => "MediaPPause",
370                Self::MediaRev => "MediaRev",
371                Self::MediaStop => "MediaStop",
372                Self::MediaFF => "MediaFF",
373                Self::MediaRewind => "MediaRewind",
374                Self::MediaNext => "MediaNext",
375                Self::MediaPrev => "MediaPrev",
376                Self::MediaRecord => "MediaRecord",
377                Self::MediaLVol => "MediaLVol",
378                Self::MediaRVol => "MediaRVol",
379                Self::MediaMute => "MediaMute",
380
381                Self::LShift => "LShift",
382                Self::LCtrl => "LCtrl",
383                Self::LAlt => "LAlt",
384                Self::LSuper => "LSuper",
385                Self::LHyper => "LHyper",
386                Self::LMeta => "LMeta",
387                Self::RShift => "RShift",
388                Self::RCtrl => "RCtrl",
389                Self::RAlt => "RAlt",
390                Self::RSuper => "RSuper",
391                Self::RHyper => "RHyper",
392                Self::RMeta => "RMeta",
393                Self::L3Shift => "L3Shift",
394                Self::L5Shift => "L5Shift",
395
396                Self::Motion => "Motion",
397                Self::Button1 => "Button1",
398                Self::Button2 => "Button2",
399                Self::Button3 => "Button3",
400                // scrollwheel up
401                Self::Button4 => "Button4",
402                // scrollwheel down
403                Self::Button5 => "Button5",
404                Self::Button6 => "Button6",
405                Self::Button7 => "Button7",
406                Self::Button8 => "Button8",
407                Self::Button9 => "Button9",
408                Self::Button10 => "Button10",
409                Self::Button11 => "Button11",
410                Self::Eof => "Eof",
411
412                Self::Tab => "Tab",
413                Self::Esc => "Esc",
414                Self::Space => "Space",
415                _ => "",
416            }
417        } else {
418            ""
419        }
420    }
421}
422
423pub(crate) mod c_api {
424    /// Offset for `NCKEY_*` values.
425    ///
426    /// Rather than using one of the Private Use Areas of Unicode, we use the
427    /// area beyond the 17 × 65_536-entry Planes (1_114_112).
428    /// We round up to 5_000 so that it's trivial to identify synthesized
429    /// characters based on their numeric definition here.
430    /// This is safe, since we needn't convert these synthesized characters
431    /// into UTF8 (they would otherwise require more than four bytes).
432    pub const PRETERUNICODEBASE: u32 = 1_115_000;
433
434    const fn preterunicode(w: u32) -> u32 {
435        w + PRETERUNICODEBASE
436    }
437
438    pub const NCKEY_INVALID: u32 = preterunicode(0);
439    /// we received SIGWINCH
440    pub const NCKEY_RESIZE: u32 = preterunicode(1);
441    pub const NCKEY_UP: u32 = preterunicode(2);
442    pub const NCKEY_RIGHT: u32 = preterunicode(3);
443    pub const NCKEY_DOWN: u32 = preterunicode(4);
444    pub const NCKEY_LEFT: u32 = preterunicode(5);
445    pub const NCKEY_INS: u32 = preterunicode(6);
446    pub const NCKEY_DEL: u32 = preterunicode(7);
447    pub const NCKEY_BACKSPACE: u32 = preterunicode(8);
448    pub const NCKEY_PGDOWN: u32 = preterunicode(9);
449    pub const NCKEY_PGUP: u32 = preterunicode(10);
450    pub const NCKEY_HOME: u32 = preterunicode(11);
451    pub const NCKEY_END: u32 = preterunicode(12);
452    pub const NCKEY_F00: u32 = preterunicode(20);
453    pub const NCKEY_F01: u32 = preterunicode(21);
454    pub const NCKEY_F02: u32 = preterunicode(22);
455    pub const NCKEY_F03: u32 = preterunicode(23);
456    pub const NCKEY_F04: u32 = preterunicode(24);
457    pub const NCKEY_F05: u32 = preterunicode(25);
458    pub const NCKEY_F06: u32 = preterunicode(26);
459    pub const NCKEY_F07: u32 = preterunicode(27);
460    pub const NCKEY_F08: u32 = preterunicode(28);
461    pub const NCKEY_F09: u32 = preterunicode(29);
462    pub const NCKEY_F10: u32 = preterunicode(30);
463    pub const NCKEY_F11: u32 = preterunicode(31);
464    pub const NCKEY_F12: u32 = preterunicode(32);
465    pub const NCKEY_F13: u32 = preterunicode(33);
466    pub const NCKEY_F14: u32 = preterunicode(34);
467    pub const NCKEY_F15: u32 = preterunicode(35);
468    pub const NCKEY_F16: u32 = preterunicode(36);
469    pub const NCKEY_F17: u32 = preterunicode(37);
470    pub const NCKEY_F18: u32 = preterunicode(38);
471    pub const NCKEY_F19: u32 = preterunicode(39);
472    pub const NCKEY_F20: u32 = preterunicode(40);
473    pub const NCKEY_F21: u32 = preterunicode(41);
474    pub const NCKEY_F22: u32 = preterunicode(42);
475    pub const NCKEY_F23: u32 = preterunicode(43);
476    pub const NCKEY_F24: u32 = preterunicode(44);
477    pub const NCKEY_F25: u32 = preterunicode(45);
478    pub const NCKEY_F26: u32 = preterunicode(46);
479    pub const NCKEY_F27: u32 = preterunicode(47);
480    pub const NCKEY_F28: u32 = preterunicode(48);
481    pub const NCKEY_F29: u32 = preterunicode(49);
482    pub const NCKEY_F30: u32 = preterunicode(50);
483    pub const NCKEY_F31: u32 = preterunicode(51);
484    pub const NCKEY_F32: u32 = preterunicode(52);
485    pub const NCKEY_F33: u32 = preterunicode(53);
486    pub const NCKEY_F34: u32 = preterunicode(54);
487    pub const NCKEY_F35: u32 = preterunicode(55);
488    pub const NCKEY_F36: u32 = preterunicode(56);
489    pub const NCKEY_F37: u32 = preterunicode(57);
490    pub const NCKEY_F38: u32 = preterunicode(58);
491    pub const NCKEY_F39: u32 = preterunicode(59);
492    pub const NCKEY_F40: u32 = preterunicode(60);
493    pub const NCKEY_F41: u32 = preterunicode(61);
494    pub const NCKEY_F42: u32 = preterunicode(62);
495    pub const NCKEY_F43: u32 = preterunicode(63);
496    pub const NCKEY_F44: u32 = preterunicode(64);
497    pub const NCKEY_F45: u32 = preterunicode(65);
498    pub const NCKEY_F46: u32 = preterunicode(66);
499    pub const NCKEY_F47: u32 = preterunicode(67);
500    pub const NCKEY_F48: u32 = preterunicode(68);
501    pub const NCKEY_F49: u32 = preterunicode(69);
502    pub const NCKEY_F50: u32 = preterunicode(70);
503    pub const NCKEY_F51: u32 = preterunicode(71);
504    pub const NCKEY_F52: u32 = preterunicode(72);
505    pub const NCKEY_F53: u32 = preterunicode(73);
506    pub const NCKEY_F54: u32 = preterunicode(74);
507    pub const NCKEY_F55: u32 = preterunicode(75);
508    pub const NCKEY_F56: u32 = preterunicode(76);
509    pub const NCKEY_F57: u32 = preterunicode(77);
510    pub const NCKEY_F58: u32 = preterunicode(78);
511    pub const NCKEY_F59: u32 = preterunicode(79);
512    pub const NCKEY_F60: u32 = preterunicode(80);
513
514    // ... leave room for function keys.
515
516    pub const NCKEY_ENTER: u32 = preterunicode(121);
517    /// "clear-screen or erase"
518    pub const NCKEY_CLS: u32 = preterunicode(122);
519    /// down + left on keypad
520    pub const NCKEY_DLEFT: u32 = preterunicode(123);
521    pub const NCKEY_DRIGHT: u32 = preterunicode(124);
522    /// up + left on keypad
523    pub const NCKEY_ULEFT: u32 = preterunicode(125);
524    pub const NCKEY_URIGHT: u32 = preterunicode(126);
525    pub const NCKEY_CENTER: u32 = preterunicode(127);
526    pub const NCKEY_BEGIN: u32 = preterunicode(128);
527    pub const NCKEY_CANCEL: u32 = preterunicode(129);
528    pub const NCKEY_CLOSE: u32 = preterunicode(130);
529    pub const NCKEY_COMMAND: u32 = preterunicode(131);
530    pub const NCKEY_COPY: u32 = preterunicode(132);
531    pub const NCKEY_EXIT: u32 = preterunicode(133);
532    pub const NCKEY_PRINT: u32 = preterunicode(134);
533    pub const NCKEY_REFRESH: u32 = preterunicode(135);
534
535    // these keys aren't generally available outside of the kitty protocol:
536
537    pub const NCKEY_CAPS_LOCK: u32 = preterunicode(150);
538    pub const NCKEY_SCROLL_LOCK: u32 = preterunicode(151);
539    pub const NCKEY_NUM_LOCK: u32 = preterunicode(152);
540    pub const NCKEY_PRINT_SCREEN: u32 = preterunicode(153);
541    pub const NCKEY_PAUSE: u32 = preterunicode(154);
542    pub const NCKEY_MENU: u32 = preterunicode(155);
543
544    // media keys, similarly only available through kitty's protocol:
545
546    pub const NCKEY_MEDIA_PLAY: u32 = preterunicode(158);
547    pub const NCKEY_MEDIA_PAUSE: u32 = preterunicode(159);
548    pub const NCKEY_MEDIA_PPAUSE: u32 = preterunicode(160);
549    pub const NCKEY_MEDIA_REV: u32 = preterunicode(161);
550    pub const NCKEY_MEDIA_STOP: u32 = preterunicode(162);
551    pub const NCKEY_MEDIA_FF: u32 = preterunicode(163);
552    pub const NCKEY_MEDIA_REWIND: u32 = preterunicode(164);
553    pub const NCKEY_MEDIA_NEXT: u32 = preterunicode(165);
554    pub const NCKEY_MEDIA_PREV: u32 = preterunicode(166);
555    pub const NCKEY_MEDIA_RECORD: u32 = preterunicode(167);
556    pub const NCKEY_MEDIA_LVOL: u32 = preterunicode(168);
557    pub const NCKEY_MEDIA_RVOL: u32 = preterunicode(169);
558    pub const NCKEY_MEDIA_MUTE: u32 = preterunicode(170);
559
560    // modifiers when pressed by themselves. this ordering comes from the Kitty
561    // keyboard protocol, and mustn't be changed without updating handlers:
562
563    pub const NCKEY_LSHIFT: u32 = preterunicode(171);
564    pub const NCKEY_LCTRL: u32 = preterunicode(172);
565    pub const NCKEY_LALT: u32 = preterunicode(173);
566    pub const NCKEY_LSUPER: u32 = preterunicode(174);
567    pub const NCKEY_LHYPER: u32 = preterunicode(175);
568    pub const NCKEY_LMETA: u32 = preterunicode(176);
569    pub const NCKEY_RSHIFT: u32 = preterunicode(177);
570    pub const NCKEY_RCTRL: u32 = preterunicode(178);
571    pub const NCKEY_RALT: u32 = preterunicode(179);
572    pub const NCKEY_RSUPER: u32 = preterunicode(180);
573    pub const NCKEY_RHYPER: u32 = preterunicode(181);
574    pub const NCKEY_RMETA: u32 = preterunicode(182);
575    /// `AltGr` in european keyboards
576    pub const NCKEY_L3SHIFT: u32 = preterunicode(183);
577    pub const NCKEY_L5SHIFT: u32 = preterunicode(184);
578
579    // Mouse events. We encode which button was pressed into the char,
580    // but position information is embedded in the larger ncinput event:
581
582    /// no buttons pressed
583    pub const NCKEY_MOTION: u32 = preterunicode(200);
584    pub const NCKEY_BUTTON1: u32 = preterunicode(201);
585    pub const NCKEY_BUTTON2: u32 = preterunicode(202);
586    pub const NCKEY_BUTTON3: u32 = preterunicode(203);
587    /// scrollwheel up
588    pub const NCKEY_BUTTON4: u32 = preterunicode(204);
589    /// scrollwheel down
590    pub const NCKEY_BUTTON5: u32 = preterunicode(205);
591    pub const NCKEY_BUTTON6: u32 = preterunicode(206);
592    pub const NCKEY_BUTTON7: u32 = preterunicode(207);
593    pub const NCKEY_BUTTON8: u32 = preterunicode(208);
594    pub const NCKEY_BUTTON9: u32 = preterunicode(209);
595    pub const NCKEY_BUTTON10: u32 = preterunicode(210);
596    pub const NCKEY_BUTTON11: u32 = preterunicode(211);
597
598    /// we received SIGCONT
599    pub const NCKEY_SIGNAL: u32 = preterunicode(400);
600
601    /// Indicates that we have reached the end of input. Any further calls
602    /// will continue to return this immediately.
603    pub const NCKEY_EOF: u32 = preterunicode(500);
604
605    // Synonyms (so far as we're concerned):
606
607    /// Alias of [`NCKEY_BUTTON4`].
608    pub const NCKEY_SCROLL_UP: u32 = NCKEY_BUTTON4;
609    /// Alias of [`NCKEY_BUTTON5`].
610    pub const NCKEY_SCROLL_DOWN: u32 = NCKEY_BUTTON5;
611    /// Alias of [`NCKEY_ENTER`].
612    pub const NCKEY_RETURN: u32 = NCKEY_ENTER;
613
614    // Aliases, from the 128 characters common to ASCII+UTF8:
615
616    pub const NCKEY_TAB: u32 = 0x09;
617    pub const NCKEY_ESC: u32 = 0x1b;
618    pub const NCKEY_SPACE: u32 = 0x20;
619}