added d2demo.mn2
[btb/d2x.git] / unused / ui / keypress.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: keypress.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
17 #pragma on (unreferenced)
18
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <string.h>
22
23 #include "fix.h"
24 #include "types.h"
25 #include "gr.h"
26 #include "ui.h"
27 #include "key.h"
28
29 char * KeyDesc[256] = {         \
30 "","{Esc}","{1}","{2}","{3}","{4}","{5}","{6}","{7}","{8}","{9}","{0}","{-}",           \
31 "{=}","{Backspace}","{Tab}","{Q}","{W}","{E}","{R}","{T}","{Y}","{U}","{I}","{O}",      \
32 "{P}","{[}","{]}","{Enter}","{LeftCtrl}","{A}","{S}","{D}","{F}",        \
33 "{G}","{H}","{J}","{K}","{L}","{;}","{'}","{`}",        \
34 "{RightShift}","{\\}","{Z}","{X}","{C}","{V}","{B}","{N}","{M}","{,}",      \
35 "{.}","{/}","{LeftShift}","{Pad*}","{LeftAlt}","{Spacebar}",      \
36 "{CapsLock}","{F1}","{F2}","{F3}","{F4}","{F5}","{F6}","{F7}","{F8}","{F9}",        \
37 "{F10}","{NumLock}","{ScrollLock}","{Pad7}","{Pad8}","{Pad9}","{Pad-}",   \
38 "{Pad4}","{Pad5}","{Pad6}","{Pad+}","{Pad1}","{Pad2}","{Pad3}","{Pad0}", \
39 "{Pad.}","","","","{F11}","{F12}","","","","","","","","","",         \
40 "","","","","","","","","","","","","","","","","","","","",     \
41 "","","","","","","","","","","","","","","","","","","","",     \
42 "","","","","","","","","","","","","","","","","","",           \
43 "{PadEnter}","{RightCtrl}","","","","","","","","","","","","","", \
44 "","","","","","","","","","","{Pad/}","","","{RightAlt}","",      \
45 "","","","","","","","","","","","","","{Home}","{Up}","{PageUp}",     \
46 "","{Left}","","{Right}","","{End}","{Down}","{PageDown}","{Insert}",       \
47 "{Delete}","","","","","","","","","","","","","","","","","",     \
48 "","","","","","","","","","","","","","","","","","","","",     \
49 "","","","","","","" };
50
51
52
53
54 void GetKeyDescription( char * text, int keypress )
55 {
56         char Ctrl[10];
57         char Alt[10];
58         char Shift[10];
59
60         if (keypress & KEY_CTRLED)
61                 strcpy( Ctrl, "{Ctrl}");
62         else
63                 strcpy( Ctrl, "");
64
65         if (keypress & KEY_ALTED)
66                 strcpy( Alt, "{Alt}");
67         else
68                 strcpy( Alt, "");
69
70         if (keypress & KEY_SHIFTED)
71                 strcpy( Shift, "{Shift}");
72         else
73                 strcpy( Shift, "");
74
75         sprintf( text, "%s%s%s%s", Ctrl, Alt, Shift, KeyDesc[keypress & 255 ]  );
76 }
77
78
79 int DecodeKeyText( char * text )
80 {
81         int i, code = 0;
82
83         if (strstr(text, "{Ctrl}") )
84                 code |= KEY_CTRLED;
85         if (strstr(text, "{Alt}") )
86                 code |= KEY_ALTED;
87         if (strstr(text, "{Shift}") )
88                 code |= KEY_SHIFTED;
89
90         for (i=0; i<256; i++ )
91         {
92                 if ( strlen(KeyDesc[i])>0 && strstr(text, KeyDesc[i]) )
93                 {
94                         code |= i;
95                         return code;
96                 }
97         }
98         return -1;
99 }
100
101
102
103
104 int GetKeyCode(char * text)
105 {
106         UI_WINDOW * wnd;
107         UI_GADGET_BUTTON * DoneButton;
108         char temp_text[100];
109
110         text = text;
111
112         wnd = ui_open_window( 200, 200, 400, 200, WIN_DIALOG );
113
114         DoneButton = ui_add_gadget_button( wnd, 170, 165, 60, 25, "Ok", NULL );
115
116         ui_gadget_calc_keys(wnd);
117
118         //key_flush();
119
120         wnd->keyboard_focus_gadget = (UI_GADGET *)DoneButton;
121
122         while(1)
123         {
124                 ui_mega_process();
125                 ui_window_do_gadgets(wnd);
126
127                 if (last_keypress > 0)
128                 {
129                         GetKeyDescription( temp_text, last_keypress );
130                         ui_wprintf_at( wnd, 10, 100, "%s     ", temp_text  );
131                 }
132
133                 if (DoneButton->pressed)
134                         break;
135         }
136
137         ui_close_window(wnd);
138
139         return 0;
140 }
141