blob: 8566ded5f4afd34fca60ce378a3a5902926e91ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/*
client/keyboard.cc
This file is part of the Osirion project and is distributed under
the terms and conditions of the GNU General Public License version 2
*/
#include "client/keyboard.h"
#include <iostream>
namespace client {
void setkeyboardmode(bool input)
{
if(input)
SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL);
else
SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
}
int translate_keysym(const SDL_keysym &keysym)
{
int key = keysym.sym;
bool shift = false;
bool numlock = false;
// keypad keys
if (keysym.mod & KMOD_NUM) {
numlock = true;
switch(key) {
case SDLK_KP0:
return '0';
break;
case SDLK_KP1:
return '1';
break;
case SDLK_KP2:
return '2';
break;
case SDLK_KP3:
return '3';
break;
case SDLK_KP4:
return '4';
break;
case SDLK_KP5:
return '5';
break;
case SDLK_KP6:
return '6';
break;
case SDLK_KP7:
return '7';
break;
case SDLK_KP8:
return '8';
break;
case SDLK_KP9:
return '9';
break;
}
} else {
switch(key) {
case SDLK_KP0:
return SDLK_INSERT;
break;
case SDLK_KP1:
return SDLK_END;
break;
case SDLK_KP2:
return SDLK_DOWN;
break;
case SDLK_KP3:
return SDLK_PAGEDOWN;
break;
case SDLK_KP4:
return SDLK_LEFT;
break;
case SDLK_KP6:
return SDLK_RIGHT;
break;
case SDLK_KP7:
return SDLK_HOME;
break;
case SDLK_KP8:
return SDLK_UP;
break;
case SDLK_KP9:
return SDLK_PAGEUP;
break;
}
}
// special keys
switch(key) {
case SDLK_KP_ENTER:
return SDLK_RETURN;
break;
case SDLK_KP_PERIOD:
return '.';
break;
case SDLK_KP_DIVIDE:
return '/';
break;
case SDLK_KP_MULTIPLY:
return '*';
break;
case SDLK_KP_MINUS:
return '-';
break;
case SDLK_KP_PLUS:
return '+';
break;
case SDLK_KP_EQUALS:
return '=';
break;
}
// caps lock
if (keysym.mod & KMOD_CAPS)
shift = true;
// left/right shift
if ((keysym.mod & KMOD_LSHIFT) || (keysym.mod & KMOD_RSHIFT)) {
shift = !shift;
}
if (shift) {
if ((key >= 'a' && key <= 'z')) {
key = key + 'A' - 'a';
return key;
}
switch (key) {
case '`':
key = '~';
break;
case '1':
key = '!';
break;
case '2':
key = '@';
break;
case '3':
key = '#';
break;
case '4':
key = '$';
break;
case '5':
key = '%';
break;
case '6':
key = '^';
break;
case '7':
key = '&';
break;
case '8':
key = '*';
break;
case '9':
key = '(';
break;
case '0':
key = ')';
break;
case '-':
key = '_';
break;
case '=':
key = '+';
break;
// second row
case '[':
key = '{';
break;
case ']':
key = '}';
break;
case '|':
key = '\\';
break;
// third row
case ';':
key = ':';
break;
case '\'':
key = '"';
break;
// fourth row
case ',':
key = '<';
break;
case '.':
key = '>';
break;
case '/':
key = '?';
break;
}
}
return key;
}
} // namespace client
|