1 // Copyright (c) 2019 OPEN CASCADE SAS
3 // This file is part of the examples of the Open CASCADE Technology software library.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
22 #ifndef _WasmVKeys_HeaderFile
23 #define _WasmVKeys_HeaderFile
25 #include <Aspect_VKey.hxx>
27 #include <emscripten/key_codes.h>
29 //! Convert Emscripten mouse buttons into Aspect_VKeyMouse.
30 inline Aspect_VKeyMouse WasmVKeys_MouseButtonsFromNative (unsigned short theButtons)
32 Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
33 if ((theButtons & 0x1) != 0)
35 aButtons |= Aspect_VKeyMouse_LeftButton;
37 if ((theButtons & 0x2) != 0)
39 aButtons |= Aspect_VKeyMouse_RightButton;
41 if ((theButtons & 0x4) != 0)
43 aButtons |= Aspect_VKeyMouse_MiddleButton;
48 //! Convert DOM virtual key into Aspect_VKey.
49 inline Aspect_VKey WasmVKeys_VirtualKeyFromNative (Standard_Integer theKey)
51 if (theKey >= DOM_VK_0
52 && theKey <= DOM_VK_9)
55 return Aspect_VKey((theKey - DOM_VK_0) + Aspect_VKey_0);
57 if (theKey >= DOM_VK_A
58 && theKey <= DOM_VK_Z)
60 // main latin alphabet keys
61 return Aspect_VKey((theKey - DOM_VK_A) + Aspect_VKey_A);
63 if (theKey >= DOM_VK_F1
64 && theKey <= DOM_VK_F24)
67 if (theKey <= DOM_VK_F12)
69 return Aspect_VKey((theKey - DOM_VK_F1) + Aspect_VKey_F1);
71 return Aspect_VKey_UNKNOWN;
73 if (theKey >= DOM_VK_NUMPAD0
74 && theKey <= DOM_VK_NUMPAD9)
77 return Aspect_VKey((theKey - DOM_VK_NUMPAD0) + Aspect_VKey_Numpad0);
84 return Aspect_VKey_UNKNOWN;
85 case DOM_VK_BACK_SPACE:
86 return Aspect_VKey_Backspace;
88 return Aspect_VKey_Tab;
90 return Aspect_VKey_UNKNOWN;
93 return Aspect_VKey_Enter;
95 return Aspect_VKey_Shift;
97 return Aspect_VKey_Control;
99 return Aspect_VKey_Alt;
101 case DOM_VK_CAPS_LOCK:
103 //case DOM_VK_HANGUL:
109 return Aspect_VKey_UNKNOWN;
111 return Aspect_VKey_Escape;
113 case DOM_VK_NONCONVERT:
115 case DOM_VK_MODECHANGE:
116 return Aspect_VKey_UNKNOWN;
118 return Aspect_VKey_Space;
120 return Aspect_VKey_PageUp;
121 case DOM_VK_PAGE_DOWN:
122 return Aspect_VKey_PageDown;
124 return Aspect_VKey_End;
126 return Aspect_VKey_Home;
128 return Aspect_VKey_Left;
130 return Aspect_VKey_Up;
132 return Aspect_VKey_Right;
134 return Aspect_VKey_Down;
138 case DOM_VK_PRINTSCREEN:
140 return Aspect_VKey_UNKNOWN;
142 return Aspect_VKey_Delete;
144 return Aspect_VKey_Comma;
145 case DOM_VK_SEMICOLON:
146 return Aspect_VKey_Semicolon;
147 case DOM_VK_LESS_THAN:
148 return Aspect_VKey_UNKNOWN;
150 return Aspect_VKey_Equal;
151 case DOM_VK_GREATER_THAN:
152 return Aspect_VKey_UNKNOWN;
153 case DOM_VK_QUESTION_MARK:
154 return Aspect_VKey_Slash;
155 case DOM_VK_AT: // @ key
156 return Aspect_VKey_UNKNOWN;
158 return Aspect_VKey_Meta;
159 case DOM_VK_CONTEXT_MENU:
161 return Aspect_VKey_UNKNOWN;
162 case DOM_VK_MULTIPLY:
163 return Aspect_VKey_NumpadMultiply;
165 return Aspect_VKey_NumpadAdd;
166 case DOM_VK_SEPARATOR:
167 return Aspect_VKey_UNKNOWN;
168 case DOM_VK_SUBTRACT:
169 return Aspect_VKey_NumpadSubtract;
171 return Aspect_VKey_UNKNOWN;
173 return Aspect_VKey_NumpadDivide;
174 case DOM_VK_NUM_LOCK:
175 return Aspect_VKey_Numlock;
176 case DOM_VK_SCROLL_LOCK:
177 return Aspect_VKey_Scroll;
178 case DOM_VK_WIN_OEM_FJ_JISHO:
179 case DOM_VK_WIN_OEM_FJ_MASSHOU:
180 case DOM_VK_WIN_OEM_FJ_TOUROKU:
181 case DOM_VK_WIN_OEM_FJ_LOYA:
182 case DOM_VK_WIN_OEM_FJ_ROYA:
183 case DOM_VK_CIRCUMFLEX:
184 return Aspect_VKey_UNKNOWN;
185 case DOM_VK_EXCLAMATION:
186 case DOM_VK_DOUBLE_QUOTE:
190 case DOM_VK_AMPERSAND:
191 case DOM_VK_UNDERSCORE:
192 case DOM_VK_OPEN_PAREN:
193 case DOM_VK_CLOSE_PAREN:
194 case DOM_VK_ASTERISK:
195 return Aspect_VKey_UNKNOWN;
197 return Aspect_VKey_Plus;
199 case DOM_VK_HYPHEN_MINUS:
200 return Aspect_VKey_UNKNOWN;
201 case DOM_VK_OPEN_CURLY_BRACKET:
202 return Aspect_VKey_BracketLeft;
203 case DOM_VK_CLOSE_CURLY_BRACKET:
204 return Aspect_VKey_BracketRight;
206 return Aspect_VKey_Tilde;
207 case DOM_VK_VOLUME_MUTE:
208 return Aspect_VKey_VolumeMute;
209 case DOM_VK_VOLUME_DOWN:
210 return Aspect_VKey_VolumeDown;
211 case DOM_VK_VOLUME_UP:
212 return Aspect_VKey_VolumeUp;
214 return Aspect_VKey_Comma;
216 return Aspect_VKey_Period;
218 return Aspect_VKey_Slash;
219 case DOM_VK_BACK_QUOTE:
220 return Aspect_VKey_UNKNOWN;
221 case DOM_VK_OPEN_BRACKET:
222 return Aspect_VKey_BracketLeft;
223 case DOM_VK_BACK_SLASH:
224 return Aspect_VKey_Backslash;
225 case DOM_VK_CLOSE_BRACKET:
226 return Aspect_VKey_BracketRight;
228 return Aspect_VKey_UNKNOWN;
230 return Aspect_VKey_Meta;
232 return Aspect_VKey_Alt;
233 case DOM_VK_WIN_ICO_HELP:
234 case DOM_VK_WIN_ICO_00:
235 case DOM_VK_WIN_ICO_CLEAR:
236 case DOM_VK_WIN_OEM_RESET:
237 case DOM_VK_WIN_OEM_JUMP:
238 case DOM_VK_WIN_OEM_PA1:
239 case DOM_VK_WIN_OEM_PA2:
240 case DOM_VK_WIN_OEM_PA3:
241 case DOM_VK_WIN_OEM_WSCTRL:
242 case DOM_VK_WIN_OEM_CUSEL:
243 case DOM_VK_WIN_OEM_ATTN:
244 case DOM_VK_WIN_OEM_FINISH:
245 case DOM_VK_WIN_OEM_COPY:
246 case DOM_VK_WIN_OEM_AUTO:
247 case DOM_VK_WIN_OEM_ENLW:
248 case DOM_VK_WIN_OEM_BACKTAB:
253 return Aspect_VKey_UNKNOWN;
255 return Aspect_VKey_MediaPlayPause;
258 case DOM_VK_WIN_OEM_CLEAR:
259 return Aspect_VKey_UNKNOWN;
261 return Aspect_VKey_UNKNOWN;
264 #endif // _WasmVKeys_HeaderFile