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)
72 Con_Printf("scancode=%x (%d%s)\n", scancode, sc, scancode&0x80?"+128":"");
74 Key_Event(scantokey[sc], state == KEY_EVENTPRESS);
78 static void mousehandler(int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
80 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);
97 if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
98 if (COM_CheckParm("-nomouse")) UseMouse = 0;
106 in_svgalib_inited = 1;
109 static void IN_init_kb(void)
113 for (i=0 ; i<128 ; i++) {
117 scantokey[ 1] = K_ESCAPE;
126 scantokey[ 10] = '9';
127 scantokey[ 11] = '0';
128 scantokey[ 12] = '-';
129 scantokey[ 13] = '=';
130 scantokey[ 14] = K_BACKSPACE;
131 scantokey[ 15] = K_TAB;
132 scantokey[ 16] = 'q';
133 scantokey[ 17] = 'w';
134 scantokey[ 18] = 'e';
135 scantokey[ 19] = 'r';
136 scantokey[ 20] = 't';
137 scantokey[ 21] = 'y';
138 scantokey[ 22] = 'u';
139 scantokey[ 23] = 'i';
140 scantokey[ 24] = 'o';
141 scantokey[ 25] = 'p';
142 scantokey[ 26] = '[';
143 scantokey[ 27] = ']';
144 scantokey[ 28] = K_ENTER;
145 scantokey[ 29] = K_CTRL; /*left */
146 scantokey[ 30] = 'a';
147 scantokey[ 31] = 's';
148 scantokey[ 32] = 'd';
149 scantokey[ 33] = 'f';
150 scantokey[ 34] = 'g';
151 scantokey[ 35] = 'h';
152 scantokey[ 36] = 'j';
153 scantokey[ 37] = 'k';
154 scantokey[ 38] = 'l';
155 scantokey[ 39] = ';';
156 scantokey[ 40] = '\'';
157 scantokey[ 41] = '`';
158 scantokey[ 42] = K_SHIFT; /*left */
159 scantokey[ 43] = '\\';
160 scantokey[ 44] = 'z';
161 scantokey[ 45] = 'x';
162 scantokey[ 46] = 'c';
163 scantokey[ 47] = 'v';
164 scantokey[ 48] = 'b';
165 scantokey[ 49] = 'n';
166 scantokey[ 50] = 'm';
167 scantokey[ 51] = ',';
168 scantokey[ 52] = '.';
169 scantokey[ 53] = '/';
170 scantokey[ 54] = K_SHIFT; /*right */
171 scantokey[ 55] = KP_MULTIPLY;
172 scantokey[ 56] = K_ALT; /*left */
173 scantokey[ 57] = ' ';
174 scantokey[ 58] = K_CAPSLOCK;
175 scantokey[ 59] = K_F1;
176 scantokey[ 60] = K_F2;
177 scantokey[ 61] = K_F3;
178 scantokey[ 62] = K_F4;
179 scantokey[ 63] = K_F5;
180 scantokey[ 64] = K_F6;
181 scantokey[ 65] = K_F7;
182 scantokey[ 66] = K_F8;
183 scantokey[ 67] = K_F9;
184 scantokey[ 68] = K_F10;
185 scantokey[ 69] = KP_NUMLCK;
186 scantokey[ 70] = K_SCRLCK;
187 scantokey[ 71] = KP_HOME;
188 scantokey[ 72] = KP_UPARROW;
189 scantokey[ 73] = KP_PGUP;
190 scantokey[ 74] = KP_MINUS;
191 scantokey[ 75] = KP_LEFTARROW;
192 scantokey[ 76] = KP_5;
193 scantokey[ 77] = KP_RIGHTARROW;
194 scantokey[ 79] = KP_END;
195 scantokey[ 78] = KP_PLUS;
196 scantokey[ 80] = KP_DOWNARROW;
197 scantokey[ 81] = KP_PGDN;
198 scantokey[ 82] = KP_INS;
199 scantokey[ 83] = KP_DEL;
200 /* 84 to 86 not used */
201 scantokey[ 87] = K_F11;
202 scantokey[ 88] = K_F12;
203 /* 89 to 95 not used */
204 scantokey[ 96] = KP_ENTER; /* keypad enter */
205 scantokey[ 97] = K_CTRL; /* right */
206 scantokey[ 98] = KP_DIVIDE;
207 scantokey[ 99] = K_PRNTSCR; /* print screen */
208 scantokey[100] = K_ALT; /* right */
210 scantokey[101] = K_PAUSE; /* break */
211 scantokey[102] = K_HOME;
212 scantokey[103] = K_UPARROW;
213 scantokey[104] = K_PGUP;
214 scantokey[105] = K_LEFTARROW;
215 scantokey[106] = K_RIGHTARROW;
216 scantokey[107] = K_END;
217 scantokey[108] = K_DOWNARROW;
218 scantokey[109] = K_PGDN;
219 scantokey[110] = K_INS;
220 scantokey[111] = K_DEL;
221 scantokey[119] = K_PAUSE;
223 if (keyboard_init()) {
224 Sys_Error("keyboard_init() failed");
226 keyboard_seteventhandler(keyhandler);
229 static void IN_init_mouse(void)
233 int mouserate = MOUSE_DEFAULTSAMPLERATE;
237 mtype = vga_getmousetype();
239 mousedev = "/dev/mouse";
240 if (getenv("MOUSEDEV")) mousedev = getenv("MOUSEDEV");
241 if (COM_CheckParm("-mdev")) {
242 mousedev = com_argv[COM_CheckParm("-mdev")+1];
245 if (getenv("MOUSERATE")) mouserate = atoi(getenv("MOUSERATE"));
246 if (COM_CheckParm("-mrate")) {
247 mouserate = atoi(com_argv[COM_CheckParm("-mrate")+1]);
251 printf("Mouse: dev=%s,type=%s,speed=%d\n",
252 mousedev, mice[mtype].name, mouserate);
254 if (mouse_init(mousedev, mtype, mouserate)) {
255 Con_Printf("No mouse found\n");
258 mouse_seteventhandler((void*)mousehandler);
262 void IN_Shutdown(void)
264 Con_Printf("IN_Shutdown\n");
270 in_svgalib_inited = 0;
274 void Sys_SendKeyEvents(void)
276 if (!in_svgalib_inited) return;
279 while ((keyboard_update()));
284 void IN_Commands(void)
288 /* Poll mouse values */
289 while (mouse_update())
292 /* Perform button actions */
293 if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
294 !(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
295 Key_Event (K_MOUSE1, true);
296 else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
297 (mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
298 Key_Event (K_MOUSE1, false);
300 if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
301 !(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
302 Key_Event (K_MOUSE2, true);
303 else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
304 (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
305 Key_Event (K_MOUSE2, false);
307 if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
308 !(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
309 Key_Event (K_MOUSE3, true);
310 else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
311 (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
312 Key_Event (K_MOUSE3, false);
314 mouse_oldbuttonstate = mouse_buttonstate;
319 void IN_Move(usercmd_t *cmd)
324 /* Poll mouse values */
325 while (mouse_update())
328 if (key_dest != key_game)
329 ui_mouseupdaterelative(uimx, uimy);
331 IN_Mouse(cmd, mx, my);
338 void IN_HandlePause (qboolean pause)