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;
63 static void IN_init_kb();
64 static void IN_init_mouse();
66 cvar_t m_filter = {"m_filter","0"};
68 static void keyhandler(int scancode, int state)
74 Con_Printf("scancode=%x (%d%s)\n", scancode, sc, scancode&0x80?"+128":"");
76 Key_Event(scantokey[sc], state == KEY_EVENTPRESS);
80 static void mousehandler(int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
82 mouse_buttonstate = buttonstate;
86 Key_Event(K_MWHEELUP, 1);
87 Key_Event(K_MWHEELUP, 0);
89 Key_Event(K_MWHEELDOWN, 1);
90 Key_Event(K_MWHEELDOWN, 0);
95 void Force_CenterView_f(void)
97 cl.viewangles[PITCH] = 0;
103 if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
104 if (COM_CheckParm("-nomouse")) UseMouse = 0;
111 in_svgalib_inited = 1;
114 static void IN_init_kb()
118 for (i=0 ; i<128 ; i++) {
122 scantokey[ 1] = K_ESCAPE;
131 scantokey[ 10] = '9';
132 scantokey[ 11] = '0';
133 scantokey[ 12] = '-';
134 scantokey[ 13] = '=';
135 scantokey[ 14] = K_BACKSPACE;
136 scantokey[ 15] = K_TAB;
137 scantokey[ 16] = 'q';
138 scantokey[ 17] = 'w';
139 scantokey[ 18] = 'e';
140 scantokey[ 19] = 'r';
141 scantokey[ 20] = 't';
142 scantokey[ 21] = 'y';
143 scantokey[ 22] = 'u';
144 scantokey[ 23] = 'i';
145 scantokey[ 24] = 'o';
146 scantokey[ 25] = 'p';
147 scantokey[ 26] = '[';
148 scantokey[ 27] = ']';
149 scantokey[ 28] = K_ENTER;
150 scantokey[ 29] = K_CTRL; /*left */
151 scantokey[ 30] = 'a';
152 scantokey[ 31] = 's';
153 scantokey[ 32] = 'd';
154 scantokey[ 33] = 'f';
155 scantokey[ 34] = 'g';
156 scantokey[ 35] = 'h';
157 scantokey[ 36] = 'j';
158 scantokey[ 37] = 'k';
159 scantokey[ 38] = 'l';
160 scantokey[ 39] = ';';
161 scantokey[ 40] = '\'';
162 scantokey[ 41] = '`';
163 scantokey[ 42] = K_SHIFT; /*left */
164 scantokey[ 43] = '\\';
165 scantokey[ 44] = 'z';
166 scantokey[ 45] = 'x';
167 scantokey[ 46] = 'c';
168 scantokey[ 47] = 'v';
169 scantokey[ 48] = 'b';
170 scantokey[ 49] = 'n';
171 scantokey[ 50] = 'm';
172 scantokey[ 51] = ',';
173 scantokey[ 52] = '.';
174 scantokey[ 53] = '/';
175 scantokey[ 54] = K_SHIFT; /*right */
176 scantokey[ 55] = KP_MULTIPLY;
177 scantokey[ 56] = K_ALT; /*left */
178 scantokey[ 57] = ' ';
179 scantokey[ 58] = K_CAPSLOCK;
180 scantokey[ 59] = K_F1;
181 scantokey[ 60] = K_F2;
182 scantokey[ 61] = K_F3;
183 scantokey[ 62] = K_F4;
184 scantokey[ 63] = K_F5;
185 scantokey[ 64] = K_F6;
186 scantokey[ 65] = K_F7;
187 scantokey[ 66] = K_F8;
188 scantokey[ 67] = K_F9;
189 scantokey[ 68] = K_F10;
190 scantokey[ 69] = KP_NUMLCK;
191 scantokey[ 70] = K_SCRLCK;
192 scantokey[ 71] = KP_HOME;
193 scantokey[ 72] = KP_UPARROW;
194 scantokey[ 73] = KP_PGUP;
195 scantokey[ 74] = KP_MINUS;
196 scantokey[ 75] = KP_LEFTARROW;
197 scantokey[ 76] = KP_5;
198 scantokey[ 77] = KP_RIGHTARROW;
199 scantokey[ 79] = KP_END;
200 scantokey[ 78] = KP_PLUS;
201 scantokey[ 80] = KP_DOWNARROW;
202 scantokey[ 81] = KP_PGDN;
203 scantokey[ 82] = KP_INS;
204 scantokey[ 83] = KP_DEL;
205 /* 84 to 86 not used */
206 scantokey[ 87] = K_F11;
207 scantokey[ 88] = K_F12;
208 /* 89 to 95 not used */
209 scantokey[ 96] = KP_ENTER; /* keypad enter */
210 scantokey[ 97] = K_CTRL; /* right */
211 scantokey[ 98] = KP_DIVIDE;
212 scantokey[ 99] = K_PRNTSCR; /* print screen */
213 scantokey[100] = K_ALT; /* right */
215 scantokey[101] = K_PAUSE; /* break */
216 scantokey[102] = K_HOME;
217 scantokey[103] = K_UPARROW;
218 scantokey[104] = K_PGUP;
219 scantokey[105] = K_LEFTARROW;
220 scantokey[106] = K_RIGHTARROW;
221 scantokey[107] = K_END;
222 scantokey[108] = K_DOWNARROW;
223 scantokey[109] = K_PGDN;
224 scantokey[110] = K_INS;
225 scantokey[111] = K_DEL;
226 scantokey[119] = K_PAUSE;
228 if (keyboard_init()) {
229 Sys_Error("keyboard_init() failed");
231 keyboard_seteventhandler(keyhandler);
234 static void IN_init_mouse()
238 int mouserate = MOUSE_DEFAULTSAMPLERATE;
240 Cvar_RegisterVariable (&m_filter);
241 Cmd_AddCommand("force_centerview", Force_CenterView_f);
245 mtype = vga_getmousetype();
247 mousedev = "/dev/mouse";
248 if (getenv("MOUSEDEV")) mousedev = getenv("MOUSEDEV");
249 if (COM_CheckParm("-mdev")) {
250 mousedev = com_argv[COM_CheckParm("-mdev")+1];
253 if (getenv("MOUSERATE")) mouserate = atoi(getenv("MOUSERATE"));
254 if (COM_CheckParm("-mrate")) {
255 mouserate = atoi(com_argv[COM_CheckParm("-mrate")+1]);
259 printf("Mouse: dev=%s,type=%s,speed=%d\n",
260 mousedev, mice[mtype].name, mouserate);
262 if (mouse_init(mousedev, mtype, mouserate)) {
263 Con_Printf("No mouse found\n");
266 mouse_seteventhandler((void*)mousehandler);
270 void IN_Shutdown(void)
272 Con_Printf("IN_Shutdown\n");
274 if (UseMouse) mouse_close();
275 if (UseKeyboard) keyboard_close();
276 in_svgalib_inited = 0;
280 void Sys_SendKeyEvents(void)
282 if (!in_svgalib_inited) return;
285 while ((keyboard_update()));
290 void IN_Commands(void)
294 /* Poll mouse values */
295 while (mouse_update())
298 /* Perform button actions */
299 if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
300 !(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
301 Key_Event (K_MOUSE1, true);
302 else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
303 (mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
304 Key_Event (K_MOUSE1, false);
306 if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
307 !(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
308 Key_Event (K_MOUSE2, true);
309 else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
310 (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
311 Key_Event (K_MOUSE2, false);
313 if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
314 !(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
315 Key_Event (K_MOUSE3, true);
316 else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
317 (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
318 Key_Event (K_MOUSE3, false);
320 mouse_oldbuttonstate = mouse_buttonstate;
325 void IN_Move(usercmd_t *cmd)
327 if (!UseMouse) return;
329 /* Poll mouse values */
330 while (mouse_update())
333 if (m_filter.value) {
334 mouse_x = (mx + old_mouse_x) * 0.5;
335 mouse_y = (my + old_mouse_y) * 0.5;
342 /* Clear for next update */
345 mouse_x *= sensitivity.value;
346 mouse_y *= sensitivity.value;
348 /* Add mouse X/Y movement to cmd */
349 if ( (in_strafe.state & 1) ||
350 (lookstrafe.value && (in_mlook.state & 1) )) {
351 cmd->sidemove += m_side.value * mouse_x;
353 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
356 if ((in_mlook.state & 1)) V_StopPitchDrift();
358 if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
359 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
360 if (cl.viewangles[PITCH] > 80) {
361 cl.viewangles[PITCH] = 80;
363 if (cl.viewangles[PITCH] < -70) {
364 cl.viewangles[PITCH] = -70;
367 if ((in_strafe.state & 1) && noclip_anglehack) {
368 cmd->upmove -= m_forward.value * mouse_y;
370 cmd->forwardmove -= m_forward.value * mouse_y;
375 void IN_HandlePause (qboolean pause)