]> git.jsancho.org Git - lugaru.git/blob - Source/WinInput.cpp
merge & removing debug printf. (in Settings.cpp, by myself, useless)
[lugaru.git] / Source / WinInput.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 /**> HEADER FILES <**/
23 #include "WinInput.h"
24 #include "SDL.h"
25
26 #ifdef WIN32
27 #include <string.h>
28 #else
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #endif
33
34 extern bool keyboardfrozen;
35 /********************> IsKeyDown() <*****/
36
37 unsigned short  CharToKey(const char* which)
38 {
39         for(unsigned short i=0;i<SDLK_LAST;i++) {
40                 if(!strcasecmp(which,SDL_GetKeyName(SDLKey(i))))
41                         return i;
42         }
43         if(!strcasecmp(which,"mouse1")){
44                 return MOUSEBUTTON1;
45         }
46         if(!strcasecmp(which,"mouse2")){
47                 return MOUSEBUTTON2;
48         }
49         return SDLK_LAST;
50 }
51
52 char    KeyToSingleChar(unsigned short which)
53 {
54         static int i;
55
56         if(which==SDLK_a){
57                 return 'a';
58         }
59         if(which==SDLK_b){
60                 return 'b';
61         }
62         if(which==SDLK_c){
63                 return 'c';
64         }
65         if(which==SDLK_d){
66                 return 'd';
67         }
68         if(which==SDLK_e){
69                 return 'e';
70         }
71         if(which==SDLK_f){
72                 return 'f';
73         }
74         if(which==SDLK_g){
75                 return 'g';
76         }
77         if(which==SDLK_h){
78                 return 'h';
79         }
80         if(which==SDLK_i){
81                 return 'i';
82         }
83         if(which==SDLK_j){
84                 return 'j';
85         }
86         if(which==SDLK_k){
87                 return 'k';
88         }
89         if(which==SDLK_m){
90                 return 'm';
91         }
92         if(which==SDLK_n){
93                 return 'n';
94         }
95         if(which==SDLK_o){
96                 return 'o';
97         }
98         if(which==SDLK_p){
99                 return 'p';
100         }
101         if(which==SDLK_q){
102                 return 'q';
103         }
104         if(which==SDLK_s){
105                 return 's';
106         }
107         if(which==SDLK_u){
108                 return 'u';
109         }
110         if(which==SDLK_v){
111                 return 'v';
112         }
113         if(which==SDLK_x){
114                 return 'x';
115         }
116         if(which==SDLK_z){
117                 return 'z';
118         }
119         if(which==SDLK_KP1){
120                 return '1';
121         }
122         if(which==SDLK_KP2){
123                 return '2';
124         }
125         if(which==SDLK_KP3){
126                 return '3';
127         }
128         if(which==SDLK_KP4){
129                 return '4';
130         }
131         if(which==SDLK_KP5){
132                 return '5';
133         }
134         if(which==SDLK_KP6){
135                 return '6';
136         }
137         if(which==SDLK_KP7){
138                 return '7';
139         }
140         if(which==SDLK_KP8){
141                 return '8';
142         }
143         if(which==SDLK_KP9){
144                 return '9';
145         }
146         if(which==SDLK_KP0){
147                 return '0';
148         }
149         if(which==SDLK_1){
150                 return '1';
151         }
152         if(which==SDLK_2){
153                 return '2';
154         }
155         if(which==SDLK_3){
156                 return '3';
157         }
158         if(which==SDLK_4){
159                 return '4';
160         }
161         if(which==SDLK_5){
162                 return '5';
163         }
164         if(which==SDLK_6){
165                 return '6';
166         }
167         if(which==SDLK_7){
168                 return '7';
169         }
170         if(which==SDLK_8){
171                 return '8';
172         }
173         if(which==SDLK_9){
174                 return '9';
175         }
176         if(which==SDLK_0){
177                 return '0';
178         }
179         if(which==SDLK_SPACE){
180                 return ' ';
181         }
182         return '\0';
183 }
184
185 char    Shift(char which)
186 {
187         static int i;
188
189         if(which=='a'){
190                 return 'A';
191         }
192         if(which=='b'){
193                 return 'B';
194         }
195         if(which=='c'){
196                 return 'C';
197         }
198         if(which=='d'){
199                 return 'D';
200         }
201         if(which=='e'){
202                 return 'E';
203         }
204         if(which=='f'){
205                 return 'F';
206         }
207         if(which=='g'){
208                 return 'G';
209         }
210         if(which=='h'){
211                 return 'H';
212         }
213         if(which=='e'){
214                 return 'E';
215         }
216         if(which=='f'){
217                 return 'F';
218         }
219         if(which=='g'){
220                 return 'G';
221         }
222         if(which=='h'){
223                 return 'H';
224         }
225         if(which=='i'){
226                 return 'I';
227         }
228         if(which=='j'){
229                 return 'J';
230         }
231         if(which=='k'){
232                 return 'K';
233         }
234         if(which=='l'){
235                 return 'L';
236         }
237         if(which=='m'){
238                 return 'M';
239         }
240         if(which=='n'){
241                 return 'N';
242         }
243         if(which=='o'){
244                 return 'O';
245         }
246         if(which=='p'){
247                 return 'P';
248         }
249         if(which=='q'){
250                 return 'Q';
251         }
252         if(which=='r'){
253                 return 'R';
254         }
255         if(which=='s'){
256                 return 'S';
257         }
258         if(which=='t'){
259                 return 'T';
260         }
261         if(which=='u'){
262                 return 'U';
263         }
264         if(which=='v'){
265                 return 'V';
266         }
267         if(which=='w'){
268                 return 'W';
269         }
270         if(which=='x'){
271                 return 'X';
272         }
273         if(which=='y'){
274                 return 'Y';
275         }
276         if(which=='z'){
277                 return 'Z';
278         }
279         if(which=='1'){
280                 return '!';
281         }
282         if(which=='2'){
283                 return '@';
284         }
285         if(which=='3'){
286                 return '#';
287         }
288         if(which=='4'){
289                 return '$';
290         }
291         if(which=='5'){
292                 return '%';
293         }
294         if(which=='6'){
295                 return '^';
296         }
297         if(which=='7'){
298                 return '&';
299         }
300         if(which=='8'){
301                 return '*';
302         }
303         if(which=='9'){
304                 return '(';
305         }
306         if(which=='0'){
307                 return ')';
308         }
309         if(which=='-'){
310                 return '_';
311         }
312         if(which=='='){
313                 return '+';
314         }
315         if(which=='['){
316                 return '{';
317         }
318         if(which==']'){
319                 return '}';
320         }
321         if(which=='\\'){
322                 return '|';
323         }
324         if(which=='.'){
325                 return '>';
326         }
327         if(which==','){
328                 return '<';
329         }
330         if(which=='/'){
331                 return '?';
332         }
333         if(which==';'){
334                 return ':';
335         }
336         if(which=='\''){
337                 return '\"';
338         }
339         return which;
340 }