6 Copyright (C) 1996-1997 Id Software, Inc.
7 Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se]
8 Copyright (C) 1999,2000 contributors of the QuakeForge project
9 Please see the file "AUTHORS" for a list of contributors
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 See the GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to:
25 Free Software Foundation, Inc.
26 59 Temple Place - Suite 330
27 Boston, MA 02111-1307, USA
47 #include <vgakeyboard.h>
51 static int UseKeyboard = 1;
52 static int UseMouse = 1;
53 static int in_svgalib_inited = 0;
55 static unsigned char scantokey[128];
56 static int mouse_buttons;
57 static int mouse_buttonstate;
58 static int mouse_oldbuttonstate;
59 static float mouse_x, mouse_y;
60 static float old_mouse_x, old_mouse_y;
61 static int mx, my, uimx, uimy;
63 static void IN_init_kb(void);
64 static void IN_init_mouse(void);
66 static void keyhandler(int scancode, int state)
71 Key_Event(scantokey[sc], state == KEY_EVENTPRESS);
75 static void mousehandler(int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
77 mouse_buttonstate = buttonstate;
83 Key_Event(K_MWHEELUP, 1);
84 Key_Event(K_MWHEELUP, 0);
86 Key_Event(K_MWHEELDOWN, 1);
87 Key_Event(K_MWHEELDOWN, 0);
94 if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
95 if (COM_CheckParm("-nomouse")) UseMouse = 0;
103 in_svgalib_inited = 1;
106 static void IN_init_kb(void)
110 for (i=0 ; i<128 ; i++) {
114 scantokey[ 1] = K_ESCAPE;
123 scantokey[ 10] = '9';
124 scantokey[ 11] = '0';
125 scantokey[ 12] = '-';
126 scantokey[ 13] = '=';
127 scantokey[ 14] = K_BACKSPACE;
128 scantokey[ 15] = K_TAB;
129 scantokey[ 16] = 'q';
130 scantokey[ 17] = 'w';
131 scantokey[ 18] = 'e';
132 scantokey[ 19] = 'r';
133 scantokey[ 20] = 't';
134 scantokey[ 21] = 'y';
135 scantokey[ 22] = 'u';
136 scantokey[ 23] = 'i';
137 scantokey[ 24] = 'o';
138 scantokey[ 25] = 'p';
139 scantokey[ 26] = '[';
140 scantokey[ 27] = ']';
141 scantokey[ 28] = K_ENTER;
142 scantokey[ 29] = K_CTRL; /*left */
143 scantokey[ 30] = 'a';
144 scantokey[ 31] = 's';
145 scantokey[ 32] = 'd';
146 scantokey[ 33] = 'f';
147 scantokey[ 34] = 'g';
148 scantokey[ 35] = 'h';
149 scantokey[ 36] = 'j';
150 scantokey[ 37] = 'k';
151 scantokey[ 38] = 'l';
152 scantokey[ 39] = ';';
153 scantokey[ 40] = '\'';
154 scantokey[ 41] = '`';
155 scantokey[ 42] = K_SHIFT; /*left */
156 scantokey[ 43] = '\\';
157 scantokey[ 44] = 'z';
158 scantokey[ 45] = 'x';
159 scantokey[ 46] = 'c';
160 scantokey[ 47] = 'v';
161 scantokey[ 48] = 'b';
162 scantokey[ 49] = 'n';
163 scantokey[ 50] = 'm';
164 scantokey[ 51] = ',';
165 scantokey[ 52] = '.';
166 scantokey[ 53] = '/';
167 scantokey[ 54] = K_SHIFT; /*right */
168 scantokey[ 55] = KP_MULTIPLY;
169 scantokey[ 56] = K_ALT; /*left */
170 scantokey[ 57] = ' ';
171 scantokey[ 58] = K_CAPSLOCK;
172 scantokey[ 59] = K_F1;
173 scantokey[ 60] = K_F2;
174 scantokey[ 61] = K_F3;
175 scantokey[ 62] = K_F4;
176 scantokey[ 63] = K_F5;
177 scantokey[ 64] = K_F6;
178 scantokey[ 65] = K_F7;
179 scantokey[ 66] = K_F8;
180 scantokey[ 67] = K_F9;
181 scantokey[ 68] = K_F10;
182 scantokey[ 69] = KP_NUMLCK;
183 scantokey[ 70] = K_SCRLCK;
184 scantokey[ 71] = KP_HOME;
185 scantokey[ 72] = KP_UPARROW;
186 scantokey[ 73] = KP_PGUP;
187 scantokey[ 74] = KP_MINUS;
188 scantokey[ 75] = KP_LEFTARROW;
189 scantokey[ 76] = KP_5;
190 scantokey[ 77] = KP_RIGHTARROW;
191 scantokey[ 79] = KP_END;
192 scantokey[ 78] = KP_PLUS;
193 scantokey[ 80] = KP_DOWNARROW;
194 scantokey[ 81] = KP_PGDN;
195 scantokey[ 82] = KP_INS;
196 scantokey[ 83] = KP_DEL;
197 /* 84 to 86 not used */
198 scantokey[ 87] = K_F11;
199 scantokey[ 88] = K_F12;
200 /* 89 to 95 not used */
201 scantokey[ 96] = KP_ENTER; /* keypad enter */
202 scantokey[ 97] = K_CTRL; /* right */
203 scantokey[ 98] = KP_DIVIDE;
204 scantokey[ 99] = K_PRNTSCR; /* print screen */
205 scantokey[100] = K_ALT; /* right */
207 scantokey[101] = K_PAUSE; /* break */
208 scantokey[102] = K_HOME;
209 scantokey[103] = K_UPARROW;
210 scantokey[104] = K_PGUP;
211 scantokey[105] = K_LEFTARROW;
212 scantokey[106] = K_RIGHTARROW;
213 scantokey[107] = K_END;
214 scantokey[108] = K_DOWNARROW;
215 scantokey[109] = K_PGDN;
216 scantokey[110] = K_INS;
217 scantokey[111] = K_DEL;
218 scantokey[119] = K_PAUSE;
220 if (keyboard_init()) {
221 Sys_Error("keyboard_init() failed");
223 keyboard_seteventhandler(keyhandler);
226 static void IN_init_mouse(void)
230 int mouserate = MOUSE_DEFAULTSAMPLERATE;
234 mtype = vga_getmousetype();
236 mousedev = "/dev/mouse";
237 if (getenv("MOUSEDEV")) mousedev = getenv("MOUSEDEV");
238 if (COM_CheckParm("-mdev")) {
239 mousedev = com_argv[COM_CheckParm("-mdev")+1];
242 if (getenv("MOUSERATE")) mouserate = atoi(getenv("MOUSERATE"));
243 if (COM_CheckParm("-mrate")) {
244 mouserate = atoi(com_argv[COM_CheckParm("-mrate")+1]);
247 if (mouse_init(mousedev, mtype, mouserate)) {
248 Con_Printf("No mouse found\n");
251 mouse_seteventhandler((void*)mousehandler);
255 void IN_Shutdown(void)
257 Con_Printf("IN_Shutdown\n");
263 in_svgalib_inited = 0;
267 void Sys_SendKeyEvents(void)
269 if (!in_svgalib_inited) return;
272 while ((keyboard_update()));
277 void IN_Commands(void)
281 /* Poll mouse values */
282 while (mouse_update())
285 /* Perform button actions */
286 if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
287 !(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
288 Key_Event (K_MOUSE1, true);
289 else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
290 (mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
291 Key_Event (K_MOUSE1, false);
293 if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
294 !(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
295 Key_Event (K_MOUSE2, true);
296 else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
297 (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
298 Key_Event (K_MOUSE2, false);
300 if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
301 !(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
302 Key_Event (K_MOUSE3, true);
303 else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
304 (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
305 Key_Event (K_MOUSE3, false);
307 mouse_oldbuttonstate = mouse_buttonstate;
312 void IN_Move(usercmd_t *cmd)
317 /* Poll mouse values */
318 while (mouse_update())
321 if (key_dest != key_game)
322 ui_mouseupdaterelative(uimx, uimy);
324 IN_Mouse(cmd, mx, my);
331 void IN_HandlePause (qboolean pause)