Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include <AK/Types.h>
30
31enum KeyCode : u8 {
32 Key_Invalid = 0,
33 Key_Escape,
34 Key_Tab,
35 Key_Backspace,
36 Key_Return,
37 Key_Insert,
38 Key_Delete,
39 Key_PrintScreen,
40 Key_SysRq,
41 Key_Home,
42 Key_End,
43 Key_Left,
44 Key_Up,
45 Key_Right,
46 Key_Down,
47 Key_PageUp,
48 Key_PageDown,
49 Key_LeftShift,
50 Key_RightShift,
51 Key_Control,
52 Key_Alt,
53 Key_CapsLock,
54 Key_NumLock,
55 Key_ScrollLock,
56 Key_F1,
57 Key_F2,
58 Key_F3,
59 Key_F4,
60 Key_F5,
61 Key_F6,
62 Key_F7,
63 Key_F8,
64 Key_F9,
65 Key_F10,
66 Key_F11,
67 Key_F12,
68 Key_Space,
69 Key_ExclamationPoint,
70 Key_DoubleQuote,
71 Key_Hashtag,
72 Key_Dollar,
73 Key_Percent,
74 Key_Ampersand,
75 Key_Apostrophe,
76 Key_LeftParen,
77 Key_RightParen,
78 Key_Asterisk,
79 Key_Plus,
80 Key_Comma,
81 Key_Minus,
82 Key_Period,
83 Key_Slash,
84 Key_0,
85 Key_1,
86 Key_2,
87 Key_3,
88 Key_4,
89 Key_5,
90 Key_6,
91 Key_7,
92 Key_8,
93 Key_9,
94 Key_Colon,
95 Key_Semicolon,
96 Key_LessThan,
97 Key_Equal,
98 Key_GreaterThan,
99 Key_QuestionMark,
100 Key_AtSign,
101 Key_A,
102 Key_B,
103 Key_C,
104 Key_D,
105 Key_E,
106 Key_F,
107 Key_G,
108 Key_H,
109 Key_I,
110 Key_J,
111 Key_K,
112 Key_L,
113 Key_M,
114 Key_N,
115 Key_O,
116 Key_P,
117 Key_Q,
118 Key_R,
119 Key_S,
120 Key_T,
121 Key_U,
122 Key_V,
123 Key_W,
124 Key_X,
125 Key_Y,
126 Key_Z,
127 Key_LeftBracket,
128 Key_RightBracket,
129 Key_Backslash,
130 Key_Circumflex,
131 Key_Underscore,
132 Key_LeftBrace,
133 Key_RightBrace,
134 Key_Pipe,
135 Key_Tilde,
136 Key_Backtick,
137 Key_Logo,
138
139 Key_Shift = Key_LeftShift,
140};
141const int key_code_count = Key_Logo;
142
143enum KeyModifier {
144 Mod_None = 0x00,
145 Mod_Alt = 0x01,
146 Mod_Ctrl = 0x02,
147 Mod_Shift = 0x04,
148 Mod_Logo = 0x08,
149 Mod_AltGr = 0x10,
150 Mod_Mask = 0x1f,
151
152 Is_Press = 0x80,
153};
154
155struct KeyEvent {
156 KeyCode key { Key_Invalid };
157 u8 character { 0 };
158 u8 flags { 0 };
159 bool alt() const { return flags & Mod_Alt; }
160 bool ctrl() const { return flags & Mod_Ctrl; }
161 bool shift() const { return flags & Mod_Shift; }
162 bool logo() const { return flags & Mod_Logo; }
163 bool altgr() const { return flags & Mod_AltGr; }
164 unsigned modifiers() const { return flags & Mod_Mask; }
165 bool is_press() const { return flags & Is_Press; }
166};