]> git.jsancho.org Git - lugaru.git/blob - Source/WinInput.cpp
Merged changes for 'CMakeLists.txt'
[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
25 #ifdef WIN32
26 #include "String.h"
27 #else
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #endif
32
33 extern bool keyboardfrozen;
34 extern bool buttons[3];
35 /********************> IsKeyDown() <*****/
36 Boolean IsKeyDown( unsigned char *keyMap, unsigned short theKey )
37 {
38         if(keyboardfrozen)return 0;
39         if(theKey< 0x80 /*1000*/){
40                 static long     keyMapIndex;
41                 static Boolean  isKeyDown;
42                 static short    bitToCheck;
43
44                 // Calculate the key map index
45                 keyMapIndex = keyMap[theKey/8];
46
47                 // Calculate the individual bit to check
48                 bitToCheck = theKey%8;
49
50                 // Check the status of the key
51                 isKeyDown = ( keyMapIndex >> bitToCheck ) & 0x01;
52
53                 // Return the status of the key
54                 return isKeyDown;
55         }
56         else if(theKey==MAC_MOUSEBUTTON1)
57                 return buttons[0];
58         else if(theKey==MAC_MOUSEBUTTON2)
59                 return buttons[1];
60
61         return 0;
62 }
63
64 #if defined(_WIN32)
65 unsigned short  CharToKey(char* which)
66 {
67         // alphabetic keys
68         if(!stricmp(which,"a")){
69                 return MAC_A_KEY;
70         }
71         if(!stricmp(which,"b")){
72                 return MAC_B_KEY;
73         }
74         if(!stricmp(which,"c")){
75                 return MAC_C_KEY;
76         }
77         if(!stricmp(which,"d")){
78                 return MAC_D_KEY;
79         }
80         if(!stricmp(which,"e")){
81                 return MAC_E_KEY;
82         }
83         if(!stricmp(which,"f")){
84                 return MAC_F_KEY;
85         }
86         if(!stricmp(which,"g")){
87                 return MAC_G_KEY;
88         }
89         if(!stricmp(which,"h")){
90                 return MAC_H_KEY;
91         }
92         if(!stricmp(which,"i")){
93                 return MAC_I_KEY;
94         }
95         if(!stricmp(which,"j")){
96                 return MAC_J_KEY;
97         }
98         if(!stricmp(which,"k")){
99                 return MAC_K_KEY;
100         }
101         if(!stricmp(which,"l")){
102                 return MAC_L_KEY;
103         }
104         if(!stricmp(which,"m")){
105                 return MAC_M_KEY;
106         }
107         if(!stricmp(which,"n")){
108                 return MAC_N_KEY;
109         }
110         if(!stricmp(which,"o")){
111                 return MAC_O_KEY;
112         }
113         if(!stricmp(which,"p")){
114                 return MAC_P_KEY;
115         }
116         if(!stricmp(which,"q")){
117                 return MAC_Q_KEY;
118         }
119         if(!stricmp(which,"r")){
120                 return MAC_R_KEY;
121         }
122         if(!stricmp(which,"s")){
123                 return MAC_S_KEY;
124         }
125         if(!stricmp(which,"t")){
126                 return MAC_T_KEY;
127         }
128         if(!stricmp(which,"u")){
129                 return MAC_U_KEY;
130         }
131         if(!stricmp(which,"v")){
132                 return MAC_V_KEY;
133         }
134         if(!stricmp(which,"w")){
135                 return MAC_W_KEY;
136         }
137         if(!stricmp(which,"x")){
138                 return MAC_X_KEY;
139         }
140         if(!stricmp(which,"y")){
141                 return MAC_Y_KEY;
142         }
143         if(!stricmp(which,"z")){
144                 return MAC_Z_KEY;
145         }
146
147         // keypad keys
148         if(!stricmp(which,"KP0")){
149                 return MAC_NUMPAD_0_KEY;
150         }
151         if(!stricmp(which,"KP1")){
152                 return MAC_NUMPAD_1_KEY;
153         }
154         if(!stricmp(which,"KP2")){
155                 return MAC_NUMPAD_2_KEY;
156         }
157         if(!stricmp(which,"KP3")){
158                 return MAC_NUMPAD_3_KEY;
159         }
160         if(!stricmp(which,"KP4")){
161                 return MAC_NUMPAD_4_KEY;
162         }
163         if(!stricmp(which,"KP5")){
164                 return MAC_NUMPAD_5_KEY;
165         }
166         if(!stricmp(which,"KP6")){
167                 return MAC_NUMPAD_6_KEY;
168         }
169         if(!stricmp(which,"KP7")){
170                 return MAC_NUMPAD_7_KEY;
171         }
172         if(!stricmp(which,"KP8")){
173                 return MAC_NUMPAD_8_KEY;
174         }
175         if(!stricmp(which,"KP9")){
176                 return MAC_NUMPAD_9_KEY;
177         }
178
179         // enter
180         if(!stricmp(which,"enter")){
181                 return MAC_ENTER_KEY;
182         }
183
184         // number keys
185         if(!stricmp(which,"0")){
186                 return MAC_0_KEY;
187         }
188         if(!stricmp(which,"1")){
189                 return MAC_1_KEY;
190         }
191         if(!stricmp(which,"2")){
192                 return MAC_2_KEY;
193         }
194         if(!stricmp(which,"3")){
195                 return MAC_3_KEY;
196         }
197         if(!stricmp(which,"4")){
198                 return MAC_4_KEY;
199         }
200         if(!stricmp(which,"5")){
201                 return MAC_5_KEY;
202         }
203         if(!stricmp(which,"6")){
204                 return MAC_6_KEY;
205         }
206         if(!stricmp(which,"7")){
207                 return MAC_7_KEY;
208         }
209         if(!stricmp(which,"8")){
210                 return MAC_8_KEY;
211         }
212         if(!stricmp(which,"9")){
213                 return MAC_9_KEY;
214         }
215
216         // function keys
217         if(!stricmp(which,"F1")){
218                 return MAC_F1_KEY;
219         }
220         if(!stricmp(which,"F2")){
221                 return MAC_F2_KEY;
222         }
223         if(!stricmp(which,"F3")){
224                 return MAC_F3_KEY;
225         }
226         if(!stricmp(which,"F4")){
227                 return MAC_F4_KEY;
228         }
229         if(!stricmp(which,"F5")){
230                 return MAC_F5_KEY;
231         }
232         if(!stricmp(which,"F6")){
233                 return MAC_F6_KEY;
234         }
235         if(!stricmp(which,"F7")){
236                 return MAC_F7_KEY;
237         }
238         if(!stricmp(which,"F8")){
239                 return MAC_F8_KEY;
240         }
241         if(!stricmp(which,"F9")){
242                 return MAC_F9_KEY;
243         }
244         if(!stricmp(which,"F10")){
245                 return MAC_F10_KEY;
246         }
247         if(!stricmp(which,"F11")){
248                 return MAC_F11_KEY;
249         }
250         if(!stricmp(which,"F12")){
251                 return MAC_F12_KEY;
252         }
253
254         // escape
255         if(!stricmp(which,"escape")){
256                 return MAC_ESCAPE_KEY;
257         }
258         if(!stricmp(which,"backspace")){
259                 return MAC_DELETE_KEY;
260         }
261         if(!stricmp(which,"tab")){
262                 return MAC_TAB_KEY;
263         }
264         if(!stricmp(which,"`")){
265                 return MAC_TILDE_KEY;
266         }
267         if(!stricmp(which,"caps_lock")){
268                 return MAC_CAPS_LOCK_KEY;
269         }
270 //      if(which==){
271 //              return "";
272 //      }
273         if(!stricmp(which,"command")){
274                 return MAC_COMMAND_KEY;
275         }
276         if(!stricmp(which,"option")){
277                 return MAC_OPTION_KEY;
278         }
279         if(!stricmp(which,"delete")){
280                 return MAC_DEL_KEY;
281         }
282         if(!stricmp(which,"insert")){
283                 return MAC_INSERT_KEY;
284         }
285         if(!stricmp(which,"home")){
286                 return MAC_HOME_KEY;
287         }
288         if(!stricmp(which,"end")){
289                 return MAC_END_KEY;
290         }
291         if(!stricmp(which,"page_up")){
292                 return MAC_PAGE_UP_KEY;
293         }
294         if(!stricmp(which,"page_down")){
295                 return MAC_PAGE_DOWN_KEY;
296         }
297         if(!stricmp(which,"clear")){
298                 return MAC_NUMPAD_CLEAR_KEY;
299         }
300
301         if(!stricmp(which,"control")){
302                 return MAC_CONTROL_KEY;
303         }
304         if(!stricmp(which,"return")){
305                 return MAC_RETURN_KEY;
306         }
307         if(!stricmp(which,"space")){
308                 return MAC_SPACE_KEY;
309         }
310         if(!stricmp(which,"shift")){
311                 return MAC_SHIFT_KEY;
312         }
313         if(!stricmp(which,"uparrow")){
314                 return MAC_ARROW_UP_KEY;
315         }
316         if(!stricmp(which,"downarrow")){
317                 return MAC_ARROW_DOWN_KEY;
318         }
319         if(!stricmp(which,"leftarrow")){
320                 return MAC_ARROW_LEFT_KEY;
321         }
322         if(!stricmp(which,"rightarrow")){
323                 return MAC_ARROW_RIGHT_KEY;
324         }
325         if(!stricmp(which,"mouse1")){
326                 return MAC_MOUSEBUTTON1;
327         }
328         if(!stricmp(which,"mouse2")){
329                 return MAC_MOUSEBUTTON2;
330         }
331         if(!stricmp(which,"+")){
332                 return MAC_NUMPAD_PLUS_KEY;
333         }
334         if(!stricmp(which,"*")){
335                 return MAC_NUMPAD_ASTERISK_KEY;
336         }
337         if(!stricmp(which,"/")){
338                 return MAC_SLASH_KEY;
339         }
340         if(!stricmp(which,"\\")){
341                 return MAC_BACKSLASH_KEY;
342         }
343         if(!stricmp(which,"[")){
344                 return MAC_LEFTBRACKET_KEY;
345         }
346         if(!stricmp(which,"]")){
347                 return MAC_RIGHTBRACKET_KEY;
348         }
349         if(!stricmp(which,".")){
350                 return MAC_PERIOD_KEY;
351         }
352         if(!stricmp(which,",")){
353                 return MAC_COMMA_KEY;
354         }
355         if(!stricmp(which,"\"")){
356                 return MAC_APOSTROPHE_KEY;
357         }
358         if(!stricmp(which,";")){
359                 return MAC_SEMICOLON_KEY;
360         }
361         return UNKNOWN_KEY;
362 }
363 #else
364 unsigned short  CharToKey(char* which)
365 {
366         // alphabetic keys
367         if(!strcasecmp(which,"a")){
368                 return MAC_A_KEY;
369         }
370         if(!strcasecmp(which,"b")){
371                 return MAC_B_KEY;
372         }
373         if(!strcasecmp(which,"c")){
374                 return MAC_C_KEY;
375         }
376         if(!strcasecmp(which,"d")){
377                 return MAC_D_KEY;
378         }
379         if(!strcasecmp(which,"e")){
380                 return MAC_E_KEY;
381         }
382         if(!strcasecmp(which,"f")){
383                 return MAC_F_KEY;
384         }
385         if(!strcasecmp(which,"g")){
386                 return MAC_G_KEY;
387         }
388         if(!strcasecmp(which,"h")){
389                 return MAC_H_KEY;
390         }
391         if(!strcasecmp(which,"i")){
392                 return MAC_I_KEY;
393         }
394         if(!strcasecmp(which,"j")){
395                 return MAC_J_KEY;
396         }
397         if(!strcasecmp(which,"k")){
398                 return MAC_K_KEY;
399         }
400         if(!strcasecmp(which,"l")){
401                 return MAC_L_KEY;
402         }
403         if(!strcasecmp(which,"m")){
404                 return MAC_M_KEY;
405         }
406         if(!strcasecmp(which,"n")){
407                 return MAC_N_KEY;
408         }
409         if(!strcasecmp(which,"o")){
410                 return MAC_O_KEY;
411         }
412         if(!strcasecmp(which,"p")){
413                 return MAC_P_KEY;
414         }
415         if(!strcasecmp(which,"q")){
416                 return MAC_Q_KEY;
417         }
418         if(!strcasecmp(which,"r")){
419                 return MAC_R_KEY;
420         }
421         if(!strcasecmp(which,"s")){
422                 return MAC_S_KEY;
423         }
424         if(!strcasecmp(which,"t")){
425                 return MAC_T_KEY;
426         }
427         if(!strcasecmp(which,"u")){
428                 return MAC_U_KEY;
429         }
430         if(!strcasecmp(which,"v")){
431                 return MAC_V_KEY;
432         }
433         if(!strcasecmp(which,"w")){
434                 return MAC_W_KEY;
435         }
436         if(!strcasecmp(which,"x")){
437                 return MAC_X_KEY;
438         }
439         if(!strcasecmp(which,"y")){
440                 return MAC_Y_KEY;
441         }
442         if(!strcasecmp(which,"z")){
443                 return MAC_Z_KEY;
444         }
445
446         // keypad keys
447         if(!strcasecmp(which,"KP0")){
448                 return MAC_NUMPAD_0_KEY;
449         }
450         if(!strcasecmp(which,"KP1")){
451                 return MAC_NUMPAD_1_KEY;
452         }
453         if(!strcasecmp(which,"KP2")){
454                 return MAC_NUMPAD_2_KEY;
455         }
456         if(!strcasecmp(which,"KP3")){
457                 return MAC_NUMPAD_3_KEY;
458         }
459         if(!strcasecmp(which,"KP4")){
460                 return MAC_NUMPAD_4_KEY;
461         }
462         if(!strcasecmp(which,"KP5")){
463                 return MAC_NUMPAD_5_KEY;
464         }
465         if(!strcasecmp(which,"KP6")){
466                 return MAC_NUMPAD_6_KEY;
467         }
468         if(!strcasecmp(which,"KP7")){
469                 return MAC_NUMPAD_7_KEY;
470         }
471         if(!strcasecmp(which,"KP8")){
472                 return MAC_NUMPAD_8_KEY;
473         }
474         if(!strcasecmp(which,"KP9")){
475                 return MAC_NUMPAD_9_KEY;
476         }
477
478         // enter
479         if(!strcasecmp(which,"enter")){
480                 return MAC_ENTER_KEY;
481         }
482
483         // number keys
484         if(!strcasecmp(which,"0")){
485                 return MAC_0_KEY;
486         }
487         if(!strcasecmp(which,"1")){
488                 return MAC_1_KEY;
489         }
490         if(!strcasecmp(which,"2")){
491                 return MAC_2_KEY;
492         }
493         if(!strcasecmp(which,"3")){
494                 return MAC_3_KEY;
495         }
496         if(!strcasecmp(which,"4")){
497                 return MAC_4_KEY;
498         }
499         if(!strcasecmp(which,"5")){
500                 return MAC_5_KEY;
501         }
502         if(!strcasecmp(which,"6")){
503                 return MAC_6_KEY;
504         }
505         if(!strcasecmp(which,"7")){
506                 return MAC_7_KEY;
507         }
508         if(!strcasecmp(which,"8")){
509                 return MAC_8_KEY;
510         }
511         if(!strcasecmp(which,"9")){
512                 return MAC_9_KEY;
513         }
514
515         // function keys
516         if(!strcasecmp(which,"F1")){
517                 return MAC_F1_KEY;
518         }
519         if(!strcasecmp(which,"F2")){
520                 return MAC_F2_KEY;
521         }
522         if(!strcasecmp(which,"F3")){
523                 return MAC_F3_KEY;
524         }
525         if(!strcasecmp(which,"F4")){
526                 return MAC_F4_KEY;
527         }
528         if(!strcasecmp(which,"F5")){
529                 return MAC_F5_KEY;
530         }
531         if(!strcasecmp(which,"F6")){
532                 return MAC_F6_KEY;
533         }
534         if(!strcasecmp(which,"F7")){
535                 return MAC_F7_KEY;
536         }
537         if(!strcasecmp(which,"F8")){
538                 return MAC_F8_KEY;
539         }
540         if(!strcasecmp(which,"F9")){
541                 return MAC_F9_KEY;
542         }
543         if(!strcasecmp(which,"F10")){
544                 return MAC_F10_KEY;
545         }
546         if(!strcasecmp(which,"F11")){
547                 return MAC_F11_KEY;
548         }
549         if(!strcasecmp(which,"F12")){
550                 return MAC_F12_KEY;
551         }
552
553         // escape
554         if(!strcasecmp(which,"escape")){
555                 return MAC_ESCAPE_KEY;
556         }
557         if(!strcasecmp(which,"backspace")){
558                 return MAC_DELETE_KEY;
559         }
560         if(!strcasecmp(which,"tab")){
561                 return MAC_TAB_KEY;
562         }
563         if(!strcasecmp(which,"`")){
564                 return MAC_TILDE_KEY;
565         }
566         if(!strcasecmp(which,"caps_lock")){
567                 return MAC_CAPS_LOCK_KEY;
568         }
569 //      if(which==){
570 //              return "";
571 //      }
572         if(!strcasecmp(which,"command")){
573                 return MAC_COMMAND_KEY;
574         }
575         if(!strcasecmp(which,"option")){
576                 return MAC_OPTION_KEY;
577         }
578         if(!strcasecmp(which,"delete")){
579                 return MAC_DEL_KEY;
580         }
581         if(!strcasecmp(which,"insert")){
582                 return MAC_INSERT_KEY;
583         }
584         if(!strcasecmp(which,"home")){
585                 return MAC_HOME_KEY;
586         }
587         if(!strcasecmp(which,"end")){
588                 return MAC_END_KEY;
589         }
590         if(!strcasecmp(which,"page_up")){
591                 return MAC_PAGE_UP_KEY;
592         }
593         if(!strcasecmp(which,"page_down")){
594                 return MAC_PAGE_DOWN_KEY;
595         }
596         if(!strcasecmp(which,"clear")){
597                 return MAC_NUMPAD_CLEAR_KEY;
598         }
599
600         if(!strcasecmp(which,"control")){
601                 return MAC_CONTROL_KEY;
602         }
603         if(!strcasecmp(which,"return")){
604                 return MAC_RETURN_KEY;
605         }
606         if(!strcasecmp(which,"space")){
607                 return MAC_SPACE_KEY;
608         }
609         if(!strcasecmp(which,"shift")){
610                 return MAC_SHIFT_KEY;
611         }
612         if(!strcasecmp(which,"uparrow")){
613                 return MAC_ARROW_UP_KEY;
614         }
615         if(!strcasecmp(which,"downarrow")){
616                 return MAC_ARROW_DOWN_KEY;
617         }
618         if(!strcasecmp(which,"leftarrow")){
619                 return MAC_ARROW_LEFT_KEY;
620         }
621         if(!strcasecmp(which,"rightarrow")){
622                 return MAC_ARROW_RIGHT_KEY;
623         }
624         if(!strcasecmp(which,"mouse1")){
625                 return MAC_MOUSEBUTTON1;
626         }
627         if(!strcasecmp(which,"mouse2")){
628                 return MAC_MOUSEBUTTON2;
629         }
630         if(!strcasecmp(which,"+")){
631                 return MAC_NUMPAD_PLUS_KEY;
632         }
633         if(!strcasecmp(which,"*")){
634                 return MAC_NUMPAD_ASTERISK_KEY;
635         }
636         if(!strcasecmp(which,"/")){
637                 return MAC_SLASH_KEY;
638         }
639         if(!strcasecmp(which,"\\")){
640                 return MAC_BACKSLASH_KEY;
641         }
642         if(!strcasecmp(which,"[")){
643                 return MAC_LEFTBRACKET_KEY;
644         }
645         if(!strcasecmp(which,"]")){
646                 return MAC_RIGHTBRACKET_KEY;
647         }
648         if(!strcasecmp(which,".")){
649                 return MAC_PERIOD_KEY;
650         }
651         if(!strcasecmp(which,",")){
652                 return MAC_COMMA_KEY;
653         }
654         if(!strcasecmp(which,"\"")){
655                 return MAC_APOSTROPHE_KEY;
656         }
657         if(!strcasecmp(which,";")){
658                 return MAC_SEMICOLON_KEY;
659         }
660         return UNKNOWN_KEY;
661 }
662 #endif
663
664 char*   KeyToChar(unsigned short which)
665 {
666         static int i;
667
668         // alphabetic keys
669         if(which==MAC_A_KEY){
670                 return "a";
671         }
672         if(which==MAC_B_KEY){
673                 return "b";
674         }
675         if(which==MAC_C_KEY){
676                 return "c";
677         }
678         if(which==MAC_D_KEY){
679                 return "d";
680         }
681         if(which==MAC_E_KEY){
682                 return "e";
683         }
684         if(which==MAC_F_KEY){
685                 return "f";
686         }
687         if(which==MAC_G_KEY){
688                 return "g";
689         }
690         if(which==MAC_H_KEY){
691                 return "h";
692         }
693         if(which==MAC_I_KEY){
694                 return "i";
695         }
696         if(which==MAC_J_KEY){
697                 return "j";
698         }
699         if(which==MAC_K_KEY){
700                 return "k";
701         }
702         if(which==MAC_L_KEY){
703                 return "l";
704         }
705         if(which==MAC_M_KEY){
706                 return "m";
707         }
708         if(which==MAC_N_KEY){
709                 return "n";
710         }
711         if(which==MAC_O_KEY){
712                 return "o";
713         }
714         if(which==MAC_P_KEY){
715                 return "p";
716         }
717         if(which==MAC_Q_KEY){
718                 return "q";
719         }
720         if(which==MAC_R_KEY){
721                 return "r";
722         }
723         if(which==MAC_S_KEY){
724                 return "s";
725         }
726         if(which==MAC_T_KEY){
727                 return "t";
728         }
729         if(which==MAC_U_KEY){
730                 return "u";
731         }
732         if(which==MAC_V_KEY){
733                 return "v";
734         }
735         if(which==MAC_W_KEY){
736                 return "w";
737         }
738         if(which==MAC_X_KEY){
739                 return "x";
740         }
741         if(which==MAC_Y_KEY){
742                 return "y";
743         }
744         if(which==MAC_Z_KEY){
745                 return "z";
746         }
747
748         // keypad keys
749         if(which==MAC_NUMPAD_1_KEY){
750                 return "KP1";
751         }
752         if(which==MAC_NUMPAD_2_KEY){
753                 return "KP2";
754         }
755         if(which==MAC_NUMPAD_3_KEY){
756                 return "KP3";
757         }
758         if(which==MAC_NUMPAD_4_KEY){
759                 return "KP4";
760         }
761         if(which==MAC_NUMPAD_5_KEY){
762                 return "KP5";
763         }
764         if(which==MAC_NUMPAD_6_KEY){
765                 return "KP6";
766         }
767         if(which==MAC_NUMPAD_7_KEY){
768                 return "KP7";
769         }
770         if(which==MAC_NUMPAD_8_KEY){
771                 return "KP8";
772         }
773         if(which==MAC_NUMPAD_9_KEY){
774                 return "KP9";
775         }
776         if(which==MAC_NUMPAD_0_KEY){
777                 return "KP0";
778         }
779
780         // enter
781         if(which==MAC_ENTER_KEY){
782                 return "enter";
783         }
784
785         // number keys
786         if(which==MAC_1_KEY){
787                 return "1";
788         }
789         if(which==MAC_2_KEY){
790                 return "2";
791         }
792         if(which==MAC_3_KEY){
793                 return "3";
794         }
795         if(which==MAC_4_KEY){
796                 return "4";
797         }
798         if(which==MAC_5_KEY){
799                 return "5";
800         }
801         if(which==MAC_6_KEY){
802                 return "6";
803         }
804         if(which==MAC_7_KEY){
805                 return "7";
806         }
807         if(which==MAC_8_KEY){
808                 return "8";
809         }
810         if(which==MAC_9_KEY){
811                 return "9";
812         }
813         if(which==MAC_0_KEY){
814                 return "0";
815         }
816
817         // function keys
818         if(which==MAC_F1_KEY){
819                 return "F1";
820         }
821         if(which==MAC_F2_KEY){
822                 return "F2";
823         }
824         if(which==MAC_F3_KEY){
825                 return "F3";
826         }
827         if(which==MAC_F4_KEY){
828                 return "F4";
829         }
830         if(which==MAC_F5_KEY){
831                 return "F5";
832         }
833         if(which==MAC_F6_KEY){
834                 return "F6";
835         }
836         if(which==MAC_F7_KEY){
837                 return "F7";
838         }
839         if(which==MAC_F8_KEY){
840                 return "F8";
841         }
842         if(which==MAC_F9_KEY){
843                 return "F9";
844         }
845         if(which==MAC_F10_KEY){
846                 return "F10";
847         }
848         if(which==MAC_F11_KEY){
849                 return "F11";
850         }
851         if(which==MAC_F12_KEY){
852                 return "F12";
853         }
854
855         // escape
856         if(which==MAC_ESCAPE_KEY){
857                 return "escape";
858         }
859         if(which==MAC_DELETE_KEY){
860                 return "backspace";
861         }
862         if(which==MAC_TAB_KEY){
863                 return "tab";
864         }
865         if(which==MAC_TILDE_KEY){
866                 return "`";
867         }
868         if(which==MAC_CAPS_LOCK_KEY){
869                 return "caps_lock";
870         }
871         if(which==MAC_COMMAND_KEY){
872                 return "command";
873         }
874         if(which==MAC_OPTION_KEY){
875                 return "option";
876         }
877         if(which==MAC_DEL_KEY){
878                 return "delete";
879         }
880         if(which==MAC_INSERT_KEY){
881                 return "insert";
882         }
883         if(which==MAC_HOME_KEY){
884                 return "home";
885         }
886         if(which==MAC_END_KEY){
887                 return "end";
888         }
889         if(which==MAC_PAGE_UP_KEY){
890                 return "page_up";
891         }
892         if(which==MAC_PAGE_DOWN_KEY){
893                 return "page_down";
894         }
895         if(which==MAC_NUMPAD_CLEAR_KEY){
896                 return "clear";
897         }
898         if(which==MAC_CONTROL_KEY){
899                 return "control";
900         }
901         if(which==MAC_SPACE_KEY){
902                 return "space";
903         }
904         if(which==MAC_RETURN_KEY){
905                 return "return";
906         }
907         if(which==MAC_SHIFT_KEY){
908                 return "shift";
909         }
910         if(which==MAC_ARROW_UP_KEY){
911                 return "uparrow";
912         }
913         if(which==MAC_ARROW_DOWN_KEY){
914                 return "downarrow";
915         }
916         if(which==MAC_ARROW_LEFT_KEY){
917                 return "leftarrow";
918         }
919         if(which==MAC_ARROW_RIGHT_KEY){
920                 return "rightarrow";
921         }
922         if(which==MAC_MOUSEBUTTON1){
923                 return "mouse1";
924         }
925         if(which==MAC_MOUSEBUTTON2){
926                 return "mouse2";
927         }
928         if(which==MAC_ARROW_RIGHT_KEY){
929                 return "rightarrow";
930         }
931         if(which==MAC_MINUS_KEY||which==MAC_NUMPAD_MINUS_KEY){
932                 return "-";
933         }
934         if(which==MAC_PLUS_KEY||which==MAC_NUMPAD_EQUALS_KEY){
935                 return "=";
936         }
937         if(which==MAC_NUMPAD_PLUS_KEY){
938                 return "+";
939         }
940         if(which==MAC_NUMPAD_ASTERISK_KEY){
941                 return "*";
942         }
943         if(which==MAC_SLASH_KEY||which==MAC_NUMPAD_SLASH_KEY){
944                 return "/";
945         }
946         if(which==MAC_BACKSLASH_KEY){
947                 return "\\";
948         }
949         if(which==MAC_LEFTBRACKET_KEY){
950                 return "[";
951         }
952         if(which==MAC_RIGHTBRACKET_KEY){
953                 return "]";
954         }
955         if(which==MAC_PERIOD_KEY||which==MAC_NUMPAD_PERIOD_KEY){
956                 return ".";
957         }
958         if(which==MAC_COMMA_KEY){
959                 return ",";
960         }
961         if(which==MAC_APOSTROPHE_KEY){
962                 return "\"";
963         }
964         if(which==MAC_SEMICOLON_KEY){
965                 return ";";
966         }
967         return "unknown";
968 }
969
970 char    KeyToSingleChar(unsigned short which)
971 {
972         static int i;
973
974         if(which==MAC_A_KEY){
975                 return 'a';
976         }
977         if(which==MAC_B_KEY){
978                 return 'b';
979         }
980         if(which==MAC_C_KEY){
981                 return 'c';
982         }
983         if(which==MAC_D_KEY){
984                 return 'd';
985         }
986         if(which==MAC_E_KEY){
987                 return 'e';
988         }
989         if(which==MAC_F_KEY){
990                 return 'f';
991         }
992         if(which==MAC_G_KEY){
993                 return 'g';
994         }
995         if(which==MAC_H_KEY){
996                 return 'h';
997         }
998         if(which==MAC_I_KEY){
999                 return 'i';
1000         }
1001         if(which==MAC_J_KEY){
1002                 return 'j';
1003         }
1004         if(which==MAC_K_KEY){
1005                 return 'k';
1006         }
1007         if(which==MAC_L_KEY){
1008                 return 'l';
1009         }
1010         if(which==MAC_M_KEY){
1011                 return 'm';
1012         }
1013         if(which==MAC_N_KEY){
1014                 return 'n';
1015         }
1016         if(which==MAC_O_KEY){
1017                 return 'o';
1018         }
1019         if(which==MAC_P_KEY){
1020                 return 'p';
1021         }
1022         if(which==MAC_Q_KEY){
1023                 return 'q';
1024         }
1025         if(which==MAC_R_KEY){
1026                 return 'r';
1027         }
1028         if(which==MAC_S_KEY){
1029                 return 's';
1030         }
1031         if(which==MAC_T_KEY){
1032                 return 't';
1033         }
1034         if(which==MAC_U_KEY){
1035                 return 'u';
1036         }
1037         if(which==MAC_V_KEY){
1038                 return 'v';
1039         }
1040         if(which==MAC_W_KEY){
1041                 return 'w';
1042         }
1043         if(which==MAC_X_KEY){
1044                 return 'x';
1045         }
1046         if(which==MAC_Y_KEY){
1047                 return 'y';
1048         }
1049         if(which==MAC_Z_KEY){
1050                 return 'z';
1051         }
1052         if(which==MAC_NUMPAD_1_KEY){
1053                 return '1';
1054         }
1055         if(which==MAC_NUMPAD_2_KEY){
1056                 return '2';
1057         }
1058         if(which==MAC_NUMPAD_3_KEY){
1059                 return '3';
1060         }
1061         if(which==MAC_NUMPAD_4_KEY){
1062                 return '4';
1063         }
1064         if(which==MAC_NUMPAD_5_KEY){
1065                 return '5';
1066         }
1067         if(which==MAC_NUMPAD_6_KEY){
1068                 return '6';
1069         }
1070         if(which==MAC_NUMPAD_7_KEY){
1071                 return '7';
1072         }
1073         if(which==MAC_NUMPAD_8_KEY){
1074                 return '8';
1075         }
1076         if(which==MAC_NUMPAD_9_KEY){
1077                 return '9';
1078         }
1079         if(which==MAC_NUMPAD_0_KEY){
1080                 return '0';
1081         }
1082         if(which==MAC_1_KEY){
1083                 return '1';
1084         }
1085         if(which==MAC_2_KEY){
1086                 return '2';
1087         }
1088         if(which==MAC_3_KEY){
1089                 return '3';
1090         }
1091         if(which==MAC_4_KEY){
1092                 return '4';
1093         }
1094         if(which==MAC_5_KEY){
1095                 return '5';
1096         }
1097         if(which==MAC_6_KEY){
1098                 return '6';
1099         }
1100         if(which==MAC_7_KEY){
1101                 return '7';
1102         }
1103         if(which==MAC_8_KEY){
1104                 return '8';
1105         }
1106         if(which==MAC_9_KEY){
1107                 return '9';
1108         }
1109         if(which==MAC_0_KEY){
1110                 return '0';
1111         }
1112         if(which==MAC_SPACE_KEY){
1113                 return ' ';
1114         }
1115         if(which==MAC_MINUS_KEY||which==MAC_NUMPAD_MINUS_KEY){
1116                 return '-';
1117         }
1118         if(which==MAC_PLUS_KEY||which==MAC_NUMPAD_EQUALS_KEY){
1119                 return '=';
1120         }
1121         if(which==MAC_NUMPAD_PLUS_KEY){
1122                 return '+';
1123         }
1124         if(which==MAC_NUMPAD_ASTERISK_KEY){
1125                 return '*';
1126         }
1127         if(which==MAC_SLASH_KEY||which==MAC_NUMPAD_SLASH_KEY){
1128                 return '/';
1129         }
1130         if(which==MAC_BACKSLASH_KEY){
1131                 return '\\';
1132         }
1133         if(which==MAC_LEFTBRACKET_KEY){
1134                 return '[';
1135         }
1136         if(which==MAC_RIGHTBRACKET_KEY){
1137                 return ']';
1138         }
1139         if(which==MAC_PERIOD_KEY||which==MAC_NUMPAD_PERIOD_KEY){
1140                 return '.';
1141         }
1142         if(which==MAC_COMMA_KEY){
1143                 return ',';
1144         }
1145         if(which==MAC_APOSTROPHE_KEY){
1146                 return '\'';
1147         }
1148         if(which==MAC_SEMICOLON_KEY){
1149                 return ';';
1150         }
1151         return '\0';
1152 }
1153
1154 char    Shift(char which)
1155 {
1156         static int i;
1157
1158         if(which=='a'){
1159                 return 'A';
1160         }
1161         if(which=='b'){
1162                 return 'B';
1163         }
1164         if(which=='c'){
1165                 return 'C';
1166         }
1167         if(which=='d'){
1168                 return 'D';
1169         }
1170         if(which=='e'){
1171                 return 'E';
1172         }
1173         if(which=='f'){
1174                 return 'F';
1175         }
1176         if(which=='g'){
1177                 return 'G';
1178         }
1179         if(which=='h'){
1180                 return 'H';
1181         }
1182         if(which=='e'){
1183                 return 'E';
1184         }
1185         if(which=='f'){
1186                 return 'F';
1187         }
1188         if(which=='g'){
1189                 return 'G';
1190         }
1191         if(which=='h'){
1192                 return 'H';
1193         }
1194         if(which=='i'){
1195                 return 'I';
1196         }
1197         if(which=='j'){
1198                 return 'J';
1199         }
1200         if(which=='k'){
1201                 return 'K';
1202         }
1203         if(which=='l'){
1204                 return 'L';
1205         }
1206         if(which=='m'){
1207                 return 'M';
1208         }
1209         if(which=='n'){
1210                 return 'N';
1211         }
1212         if(which=='o'){
1213                 return 'O';
1214         }
1215         if(which=='p'){
1216                 return 'P';
1217         }
1218         if(which=='q'){
1219                 return 'Q';
1220         }
1221         if(which=='r'){
1222                 return 'R';
1223         }
1224         if(which=='s'){
1225                 return 'S';
1226         }
1227         if(which=='t'){
1228                 return 'T';
1229         }
1230         if(which=='u'){
1231                 return 'U';
1232         }
1233         if(which=='v'){
1234                 return 'V';
1235         }
1236         if(which=='w'){
1237                 return 'W';
1238         }
1239         if(which=='x'){
1240                 return 'X';
1241         }
1242         if(which=='y'){
1243                 return 'Y';
1244         }
1245         if(which=='z'){
1246                 return 'Z';
1247         }
1248         if(which=='1'){
1249                 return '!';
1250         }
1251         if(which=='2'){
1252                 return '@';
1253         }
1254         if(which=='3'){
1255                 return '#';
1256         }
1257         if(which=='4'){
1258                 return '$';
1259         }
1260         if(which=='5'){
1261                 return '%';
1262         }
1263         if(which=='6'){
1264                 return '^';
1265         }
1266         if(which=='7'){
1267                 return '&';
1268         }
1269         if(which=='8'){
1270                 return '*';
1271         }
1272         if(which=='9'){
1273                 return '(';
1274         }
1275         if(which=='0'){
1276                 return ')';
1277         }
1278         if(which=='-'){
1279                 return '_';
1280         }
1281         if(which=='='){
1282                 return '+';
1283         }
1284         if(which=='['){
1285                 return '{';
1286         }
1287         if(which==']'){
1288                 return '}';
1289         }
1290         if(which=='\\'){
1291                 return '|';
1292         }
1293         if(which=='.'){
1294                 return '>';
1295         }
1296         if(which==','){
1297                 return '<';
1298         }
1299         if(which=='/'){
1300                 return '?';
1301         }
1302         if(which==';'){
1303                 return ':';
1304         }
1305         if(which=='\''){
1306                 return '\"';
1307         }
1308         return which;
1309 }
1310
1311 bool    Compare(char *thestring, char *tocompare, int start, int end)
1312 {
1313         static int i;
1314         for(i=start;i<=end;i++){
1315                 if(thestring[i]!=tocompare[i-start]&&thestring[i]!=tocompare[i-start]+'A'-'a')return 0;
1316         }
1317         return 1;
1318 }