1 /***************************************************************************
2 **
3 ** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias Koenig <tobias.koenig@kdab.com>
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include "qhaikukeymapper.h"
41
42 QT_BEGIN_NAMESPACE
43
44 uint32 Haiku_ScanCodes[] = {
45 Qt::Key_Escape, 0x01,
46 Qt::Key_F1, 0x02,
47 Qt::Key_F2, 0x03,
48 Qt::Key_F3, 0x04,
49 Qt::Key_F4, 0x05,
50 Qt::Key_F5, 0x06,
51 Qt::Key_F6, 0x07,
52 Qt::Key_F7, 0x08,
53 Qt::Key_F8, 0x09,
54 Qt::Key_F9, 0x0A,
55 Qt::Key_F10, 0x0B,
56 Qt::Key_F11, 0x0C,
57 Qt::Key_F12, 0x0D,
58 Qt::Key_Print, 0x0E,
59 Qt::Key_Pause, 0x22,
60 Qt::Key_AsciiTilde, 0x11,
61 Qt::Key_1, 0x12,
62 Qt::Key_2, 0x13,
63 Qt::Key_3, 0x14,
64 Qt::Key_4, 0x15,
65 Qt::Key_5, 0x16,
66 Qt::Key_6, 0x17,
67 Qt::Key_7, 0x18,
68 Qt::Key_8, 0x19,
69 Qt::Key_9, 0x1A,
70 Qt::Key_0, 0x1B,
71 Qt::Key_Minus, 0x1C,
72 Qt::Key_Plus, 0x1D,
73 Qt::Key_Backspace, 0x1E,
74 Qt::Key_Insert, 0x1F,
75 Qt::Key_Home, 0x20,
76 Qt::Key_PageUp, 0x21,
77 Qt::Key_Slash, 0x23,
78 Qt::Key_Asterisk, 0x24,
79 Qt::Key_Minus, 0x25,
80 Qt::Key_Tab, 0x26,
81 Qt::Key_Q, 0x27,
82 Qt::Key_W, 0x28,
83 Qt::Key_E, 0x29,
84 Qt::Key_R, 0x2A,
85 Qt::Key_T, 0x2B,
86 Qt::Key_Y, 0x2C,
87 Qt::Key_U, 0x2D,
88 Qt::Key_I, 0x2E,
89 Qt::Key_O, 0x2F,
90 Qt::Key_P, 0x30,
91 Qt::Key_BracketLeft, 0x31,
92 Qt::Key_BracketRight, 0x32,
93 Qt::Key_Backslash, 0x33,
94 Qt::Key_Delete, 0x34,
95 Qt::Key_End, 0x35,
96 Qt::Key_PageDown, 0x36,
97 Qt::Key_Home, 0x37, // numpad
98 Qt::Key_Up, 0x38, // numpad
99 Qt::Key_PageUp, 0x39, // numpad
100 Qt::Key_Plus, 0x3A, // numpad
101 Qt::Key_A, 0x3C,
102 Qt::Key_S, 0x3D,
103 Qt::Key_D, 0x3E,
104 Qt::Key_F, 0x3F,
105 Qt::Key_G, 0x40,
106 Qt::Key_H, 0x41,
107 Qt::Key_J, 0x42,
108 Qt::Key_K, 0x43,
109 Qt::Key_L, 0x44,
110 Qt::Key_Colon, 0x45,
111 Qt::Key_QuoteDbl, 0x46,
112 Qt::Key_Return, 0x47,
113 Qt::Key_Left, 0x48, // numpad
114 Qt::Key_5, 0x49, // numpad ???
115 Qt::Key_Right, 0x4A, // numpad
116 Qt::Key_Z, 0x4C,
117 Qt::Key_X, 0x4D,
118 Qt::Key_C, 0x4E,
119 Qt::Key_V, 0x4F,
120 Qt::Key_B, 0x50,
121 Qt::Key_N, 0x51,
122 Qt::Key_M, 0x51,
123 Qt::Key_Less, 0x52,
124 Qt::Key_Greater, 0x54,
125 Qt::Key_Question, 0x55,
126 Qt::Key_Up, 0x57, // cursor
127 Qt::Key_End, 0x58, // numpad
128 Qt::Key_Down, 0x59, // numpad
129 Qt::Key_PageDown, 0x5A, // numpad
130 Qt::Key_Enter, 0x5B, // numpad
131 Qt::Key_Space, 0x5E,
132 Qt::Key_Left, 0x61, // cursor
133 Qt::Key_Down, 0x62, // cursor
134 Qt::Key_Right, 0x63, // cursor
135 Qt::Key_Insert, 0x64, // cursor
136 Qt::Key_Delete, 0x65, // numpad
137 0, 0x00
138 };
139
140 uint32 Haiku_ScanCodes_Numlock[] = {
141 Qt::Key_7, 0x37,
142 Qt::Key_8, 0x38,
143 Qt::Key_9, 0x39,
144 Qt::Key_Plus, 0x3A,
145 Qt::Key_4, 0x48,
146 Qt::Key_5, 0x49,
147 Qt::Key_6, 0x4A,
148 Qt::Key_1, 0x58,
149 Qt::Key_2, 0x59,
150 Qt::Key_3, 0x5A,
151 Qt::Key_Enter, 0x5B,
152 Qt::Key_Comma, 0x65,
153 0, 0x00
154 };
155
translateKeyCode(uint32 key,bool numlockActive)156 uint32 QHaikuKeyMapper::translateKeyCode(uint32 key, bool numlockActive)
157 {
158 uint32 code = 0;
159 int i = 0;
160
161 if (numlockActive) {
162 while (Haiku_ScanCodes_Numlock[i]) {
163 if (key == Haiku_ScanCodes_Numlock[i + 1]) {
164 code = Haiku_ScanCodes_Numlock[i];
165 break;
166 }
167 i += 2;
168 }
169
170 if (code > 0)
171 return code;
172 }
173
174 i = 0;
175 while (Haiku_ScanCodes[i]) {
176 if (key == Haiku_ScanCodes[i + 1]) {
177 code = Haiku_ScanCodes[i];
178 break;
179 }
180 i += 2;
181 }
182
183 return code;
184 }
185
186 QT_END_NAMESPACE
187