icculus quake2 doxygen  1.0 dev
keys.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 #include "client.h"
21 
22 /*
23 
24 key up events are sent even if in console mode
25 
26 */
27 
28 
29 #define MAXCMDLINE 256
32 int shift_down=false;
34 
35 int edit_line=0;
37 
40 qboolean consolekeys[K_LAST]; // if true, can't be rebound while in console
41 qboolean menubound[K_LAST]; // if true, can't be rebound while in menu
42 int keyshift[K_LAST]; // key to map to if shift held down in console
43 int key_repeats[K_LAST]; // if > 1, it is autorepeating
45 
46 typedef struct
47 {
48  char *name;
49  int keynum;
50 } keyname_t;
51 
53 {
54  {"TAB", K_TAB},
55  {"ENTER", K_ENTER},
56  {"ESCAPE", K_ESCAPE},
57  {"SPACE", K_SPACE},
58  {"BACKSPACE", K_BACKSPACE},
59  {"UPARROW", K_UPARROW},
60  {"DOWNARROW", K_DOWNARROW},
61  {"LEFTARROW", K_LEFTARROW},
62  {"RIGHTARROW", K_RIGHTARROW},
63 
64  {"ALT", K_ALT},
65  {"CTRL", K_CTRL},
66  {"SHIFT", K_SHIFT},
67 
68  {"F1", K_F1},
69  {"F2", K_F2},
70  {"F3", K_F3},
71  {"F4", K_F4},
72  {"F5", K_F5},
73  {"F6", K_F6},
74  {"F7", K_F7},
75  {"F8", K_F8},
76  {"F9", K_F9},
77  {"F10", K_F10},
78  {"F11", K_F11},
79  {"F12", K_F12},
80 
81  {"INS", K_INS},
82  {"DEL", K_DEL},
83  {"PGDN", K_PGDN},
84  {"PGUP", K_PGUP},
85  {"HOME", K_HOME},
86  {"END", K_END},
87 
88  {"MOUSE1", K_MOUSE1},
89  {"MOUSE2", K_MOUSE2},
90  {"MOUSE3", K_MOUSE3},
91  {"MOUSE4", K_MOUSE4},
92  {"MOUSE5", K_MOUSE5},
93 
94 
95  {"JOY1", K_JOY1},
96  {"JOY2", K_JOY2},
97  {"JOY3", K_JOY3},
98  {"JOY4", K_JOY4},
99 
100  {"AUX1", K_AUX1},
101  {"AUX2", K_AUX2},
102  {"AUX3", K_AUX3},
103  {"AUX4", K_AUX4},
104  {"AUX5", K_AUX5},
105  {"AUX6", K_AUX6},
106  {"AUX7", K_AUX7},
107  {"AUX8", K_AUX8},
108  {"AUX9", K_AUX9},
109  {"AUX10", K_AUX10},
110  {"AUX11", K_AUX11},
111  {"AUX12", K_AUX12},
112  {"AUX13", K_AUX13},
113  {"AUX14", K_AUX14},
114  {"AUX15", K_AUX15},
115  {"AUX16", K_AUX16},
116  {"AUX17", K_AUX17},
117  {"AUX18", K_AUX18},
118  {"AUX19", K_AUX19},
119  {"AUX20", K_AUX20},
120  {"AUX21", K_AUX21},
121  {"AUX22", K_AUX22},
122  {"AUX23", K_AUX23},
123  {"AUX24", K_AUX24},
124  {"AUX25", K_AUX25},
125  {"AUX26", K_AUX26},
126  {"AUX27", K_AUX27},
127  {"AUX28", K_AUX28},
128  {"AUX29", K_AUX29},
129  {"AUX30", K_AUX30},
130  {"AUX31", K_AUX31},
131  {"AUX32", K_AUX32},
132 
133  {"KP_HOME", K_KP_HOME },
134  {"KP_UPARROW", K_KP_UPARROW },
135  {"KP_PGUP", K_KP_PGUP },
136  {"KP_LEFTARROW", K_KP_LEFTARROW },
137  {"KP_5", K_KP_5 },
138  {"KP_RIGHTARROW", K_KP_RIGHTARROW },
139  {"KP_END", K_KP_END },
140  {"KP_DOWNARROW", K_KP_DOWNARROW },
141  {"KP_PGDN", K_KP_PGDN },
142  {"KP_ENTER", K_KP_ENTER },
143  {"KP_INS", K_KP_INS },
144  {"KP_DEL", K_KP_DEL },
145  {"KP_SLASH", K_KP_SLASH },
146  {"KP_MINUS", K_KP_MINUS },
147  {"KP_PLUS", K_KP_PLUS },
148 
149  {"MWHEELUP", K_MWHEELUP },
150  {"MWHEELDOWN", K_MWHEELDOWN },
151 
152  {"PAUSE", K_PAUSE},
153 
154  {"SEMICOLON", ';'}, // because a raw semicolon seperates commands
155 
156  {NULL,0}
157 };
158 
159 /*
160 ==============================================================================
161 
162  LINE TYPING INTO THE CONSOLE
163 
164 ==============================================================================
165 */
166 
167 void CompleteCommand (void)
168 {
169  char *cmd, *s;
170 
171  s = key_lines[edit_line]+1;
172  if (*s == '\\' || *s == '/')
173  s++;
174 
175  cmd = Cmd_CompleteCommand (s);
176  if (!cmd)
177  cmd = Cvar_CompleteVariable (s);
178  if (cmd)
179  {
180  key_lines[edit_line][1] = '/';
181  strcpy (key_lines[edit_line]+2, cmd);
182  key_linepos = strlen(cmd)+2;
184  key_linepos++;
186  return;
187  }
188 }
189 
190 /*
191 ====================
192 Key_Console
193 
194 Interactive line editing and console scrollback
195 ====================
196 */
197 void Key_Console (int key)
198 {
199 
200  switch ( key )
201  {
202  case K_KP_SLASH:
203  key = '/';
204  break;
205  case K_KP_MINUS:
206  key = '-';
207  break;
208  case K_KP_PLUS:
209  key = '+';
210  break;
211  case K_KP_HOME:
212  key = '7';
213  break;
214  case K_KP_UPARROW:
215  key = '8';
216  break;
217  case K_KP_PGUP:
218  key = '9';
219  break;
220  case K_KP_LEFTARROW:
221  key = '4';
222  break;
223  case K_KP_5:
224  key = '5';
225  break;
226  case K_KP_RIGHTARROW:
227  key = '6';
228  break;
229  case K_KP_END:
230  key = '1';
231  break;
232  case K_KP_DOWNARROW:
233  key = '2';
234  break;
235  case K_KP_PGDN:
236  key = '3';
237  break;
238  case K_KP_INS:
239  key = '0';
240  break;
241  case K_KP_DEL:
242  key = '.';
243  break;
244  default:
245  break;
246  }
247 
248  if ( ( toupper( key ) == 'V' && keydown[K_CTRL] ) ||
249  ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keydown[K_SHIFT] ) )
250  {
251  char *cbd;
252 
253  if ( ( cbd = Sys_GetClipboardData() ) != 0 )
254  {
255  int i;
256 
257  strtok( cbd, "\n\r\b" );
258 
259  i = strlen( cbd );
260  if ( i + key_linepos >= MAXCMDLINE)
262 
263  if ( i > 0 )
264  {
265  cbd[i]=0;
266  strcat( key_lines[edit_line], cbd );
267  key_linepos += i;
268  }
269  free( cbd );
270  }
271 
272  return;
273  }
274 
275  if ( key == 'l' )
276  {
277  if ( keydown[K_CTRL] )
278  {
279  Cbuf_AddText ("clear\n");
280  return;
281  }
282  }
283 
284  if ( key == K_ENTER || key == K_KP_ENTER )
285  { // backslash text are commands, else chat
286  if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/')
287  Cbuf_AddText (key_lines[edit_line]+2); // skip the >
288  else
289  Cbuf_AddText (key_lines[edit_line]+1); // valid command
290 
291  Cbuf_AddText ("\n");
292  Com_Printf ("%s\n",key_lines[edit_line]);
293  edit_line = (edit_line + 1) & 31;
295  key_lines[edit_line][0] = ']';
296  key_linepos = 1;
297  if (cls.state == ca_disconnected)
298  SCR_UpdateScreen (); // force an update, because the command
299  // may take some time
300  return;
301  }
302 
303  if (key == K_TAB)
304  { // command completion
305  CompleteCommand ();
306  return;
307  }
308 
309  if ( ( key == K_BACKSPACE ) || ( key == K_LEFTARROW ) || ( key == K_KP_LEFTARROW ) || ( ( key == 'h' ) && ( keydown[K_CTRL] ) ) )
310  {
311  if (key_linepos > 1)
312  key_linepos--;
313  return;
314  }
315 
316  if ( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ||
317  ( ( key == 'p' ) && keydown[K_CTRL] ) )
318  {
319  do
320  {
321  history_line = (history_line - 1) & 31;
322  } while (history_line != edit_line
323  && !key_lines[history_line][1]);
324  if (history_line == edit_line)
325  history_line = (edit_line+1)&31;
327  key_linepos = strlen(key_lines[edit_line]);
328  return;
329  }
330 
331  if ( ( key == K_DOWNARROW ) || ( key == K_KP_DOWNARROW ) ||
332  ( ( key == 'n' ) && keydown[K_CTRL] ) )
333  {
334  if (history_line == edit_line) return;
335  do
336  {
337  history_line = (history_line + 1) & 31;
338  }
339  while (history_line != edit_line
340  && !key_lines[history_line][1]);
341  if (history_line == edit_line)
342  {
343  key_lines[edit_line][0] = ']';
344  key_linepos = 1;
345  }
346  else
347  {
349  key_linepos = strlen(key_lines[edit_line]);
350  }
351  return;
352  }
353 
354  if (key == K_PGUP || key == K_KP_PGUP )
355  {
356  con.display -= 2;
357  return;
358  }
359 
360  if (key == K_PGDN || key == K_KP_PGDN )
361  {
362  con.display += 2;
363  if (con.display > con.current)
365  return;
366  }
367 
368  if (key == K_HOME || key == K_KP_HOME )
369  {
370  con.display = con.current - con.totallines + 10;
371  return;
372  }
373 
374  if (key == K_END || key == K_KP_END )
375  {
377  return;
378  }
379 
380  if (key < 32 || key > 127)
381  return; // non printable
382 
383  if (key_linepos < MAXCMDLINE-1)
384  {
386  key_linepos++;
388  }
389 
390 }
391 
392 //============================================================================
393 
397 
398 void Key_Message (int key)
399 {
400 
401  if ( key == K_ENTER || key == K_KP_ENTER )
402  {
403  if (chat_team)
404  Cbuf_AddText ("say_team \"");
405  else
406  Cbuf_AddText ("say \"");
408  Cbuf_AddText("\"\n");
409 
411  chat_bufferlen = 0;
412  chat_buffer[0] = 0;
413  return;
414  }
415 
416  if (key == K_ESCAPE)
417  {
419  chat_bufferlen = 0;
420  chat_buffer[0] = 0;
421  return;
422  }
423 
424  if (key < 32 || key > 127)
425  return; // non printable
426 
427  if (key == K_BACKSPACE)
428  {
429  if (chat_bufferlen)
430  {
431  chat_bufferlen--;
433  }
434  return;
435  }
436 
437  if (chat_bufferlen == sizeof(chat_buffer)-1)
438  return; // all full
439 
440  chat_buffer[chat_bufferlen++] = key;
442 }
443 
444 //============================================================================
445 
446 
447 /*
448 ===================
449 Key_StringToKeynum
450 
451 Returns a key number to be used to index keybindings[] by looking at
452 the given string. Single ascii characters return themselves, while
453 the K_* names are matched up.
454 ===================
455 */
456 int Key_StringToKeynum (char *str)
457 {
458  keyname_t *kn;
459 
460  if (!str || !str[0])
461  return -1;
462  if (!str[1])
463  return str[0];
464 
465  for (kn=keynames ; kn->name ; kn++)
466  {
467  if (!Q_strcasecmp(str,kn->name))
468  return kn->keynum;
469  }
470  return -1;
471 }
472 
473 /*
474 ===================
475 Key_KeynumToString
476 
477 Returns a string (either a single ascii char, or a K_* name) for the
478 given keynum.
479 FIXME: handle quote special (general escape sequence?)
480 ===================
481 */
482 char *Key_KeynumToString (int keynum)
483 {
484  keyname_t *kn;
485  static char tinystr[2];
486 
487  if (keynum == -1)
488  return "<KEY NOT FOUND>";
489  if (keynum > 32 && keynum < 127)
490  { // printable ascii
491  tinystr[0] = keynum;
492  tinystr[1] = 0;
493  return tinystr;
494  }
495 
496  for (kn=keynames ; kn->name ; kn++)
497  if (keynum == kn->keynum)
498  return kn->name;
499 
500  return "<UNKNOWN KEYNUM>";
501 }
502 
503 
504 /*
505 ===================
506 Key_SetBinding
507 ===================
508 */
509 void Key_SetBinding (int keynum, char *binding)
510 {
511  char *new;
512  int l;
513 
514  if (keynum == -1)
515  return;
516 
517 // free old bindings
518  if (keybindings[keynum])
519  {
520  Z_Free (keybindings[keynum]);
521  keybindings[keynum] = NULL;
522  }
523 
524 // allocate memory for new binding
525  l = strlen (binding);
526  new = Z_Malloc (l+1);
527  strcpy (new, binding);
528  new[l] = 0;
529  keybindings[keynum] = new;
530 }
531 
532 /*
533 ===================
534 Key_Unbind_f
535 ===================
536 */
537 void Key_Unbind_f (void)
538 {
539  int b;
540 
541  if (Cmd_Argc() != 2)
542  {
543  Com_Printf ("unbind <key> : remove commands from a key\n");
544  return;
545  }
546 
547  b = Key_StringToKeynum (Cmd_Argv(1));
548  if (b==-1)
549  {
550  Com_Printf ("\"%s\" isn't a valid key\n", Cmd_Argv(1));
551  return;
552  }
553 
554  Key_SetBinding (b, "");
555 }
556 
557 void Key_Unbindall_f (void)
558 {
559  int i;
560 
561  for (i=0 ; i<K_LAST ; i++)
562  if (keybindings[i])
563  Key_SetBinding (i, "");
564 }
565 
566 
567 /*
568 ===================
569 Key_Bind_f
570 ===================
571 */
572 void Key_Bind_f (void)
573 {
574  int i, c, b;
575  char cmd[1024];
576 
577  c = Cmd_Argc();
578 
579  if (c < 2)
580  {
581  Com_Printf ("bind <key> [command] : attach a command to a key\n");
582  return;
583  }
584  b = Key_StringToKeynum (Cmd_Argv(1));
585  if (b==-1)
586  {
587  Com_Printf ("\"%s\" isn't a valid key\n", Cmd_Argv(1));
588  return;
589  }
590 
591  if (c == 2)
592  {
593  if (keybindings[b])
594  Com_Printf ("\"%s\" = \"%s\"\n", Cmd_Argv(1), keybindings[b] );
595  else
596  Com_Printf ("\"%s\" is not bound\n", Cmd_Argv(1) );
597  return;
598  }
599 
600 // copy the rest of the command line
601  cmd[0] = 0; // start out with a null string
602  for (i=2 ; i< c ; i++)
603  {
604  strcat (cmd, Cmd_Argv(i));
605  if (i != (c-1))
606  strcat (cmd, " ");
607  }
608 
609  Key_SetBinding (b, cmd);
610 }
611 
612 /*
613 ============
614 Key_WriteBindings
615 
616 Writes lines containing "bind key value"
617 ============
618 */
619 void Key_WriteBindings (FILE *f)
620 {
621  int i;
622 
623  for (i=0 ; i<K_LAST ; i++)
624  if (keybindings[i] && keybindings[i][0])
625  fprintf (f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
626 }
627 
628 
629 /*
630 ============
631 Key_Bindlist_f
632 
633 ============
634 */
635 void Key_Bindlist_f (void)
636 {
637  int i;
638 
639  for (i=0 ; i<K_LAST ; i++)
640  if (keybindings[i] && keybindings[i][0])
641  Com_Printf ("%s \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
642 }
643 
644 
645 /*
646 ===================
647 Key_Init
648 ===================
649 */
650 void Key_Init (void)
651 {
652  int i;
653 
654  for (i=0 ; i<32 ; i++)
655  {
656  key_lines[i][0] = ']';
657  key_lines[i][1] = 0;
658  }
659  key_linepos = 1;
660 
661 //
662 // init ascii characters in console mode
663 //
664  for (i=32 ; i<128 ; i++)
665  consolekeys[i] = true;
666  consolekeys[K_ENTER] = true;
667  consolekeys[K_KP_ENTER] = true;
668  consolekeys[K_TAB] = true;
669  consolekeys[K_LEFTARROW] = true;
670  consolekeys[K_KP_LEFTARROW] = true;
671  consolekeys[K_RIGHTARROW] = true;
673  consolekeys[K_UPARROW] = true;
674  consolekeys[K_KP_UPARROW] = true;
675  consolekeys[K_DOWNARROW] = true;
676  consolekeys[K_KP_DOWNARROW] = true;
677  consolekeys[K_BACKSPACE] = true;
678  consolekeys[K_HOME] = true;
679  consolekeys[K_KP_HOME] = true;
680  consolekeys[K_END] = true;
681  consolekeys[K_KP_END] = true;
682  consolekeys[K_PGUP] = true;
683  consolekeys[K_KP_PGUP] = true;
684  consolekeys[K_PGDN] = true;
685  consolekeys[K_KP_PGDN] = true;
686  consolekeys[K_SHIFT] = true;
687  consolekeys[K_INS] = true;
688  consolekeys[K_KP_INS] = true;
689  consolekeys[K_KP_DEL] = true;
690  consolekeys[K_KP_SLASH] = true;
691  consolekeys[K_KP_PLUS] = true;
692  consolekeys[K_KP_MINUS] = true;
693  consolekeys[K_KP_5] = true;
694 
695  consolekeys['`'] = false;
696  consolekeys['~'] = false;
697 
698  for (i=0 ; i<K_LAST ; i++)
699  keyshift[i] = i;
700  for (i='a' ; i<='z' ; i++)
701  keyshift[i] = i - 'a' + 'A';
702  keyshift['1'] = '!';
703  keyshift['2'] = '@';
704  keyshift['3'] = '#';
705  keyshift['4'] = '$';
706  keyshift['5'] = '%';
707  keyshift['6'] = '^';
708  keyshift['7'] = '&';
709  keyshift['8'] = '*';
710  keyshift['9'] = '(';
711  keyshift['0'] = ')';
712  keyshift['-'] = '_';
713  keyshift['='] = '+';
714  keyshift[','] = '<';
715  keyshift['.'] = '>';
716  keyshift['/'] = '?';
717  keyshift[';'] = ':';
718  keyshift['\''] = '"';
719  keyshift['['] = '{';
720  keyshift[']'] = '}';
721  keyshift['`'] = '~';
722  keyshift['\\'] = '|';
723 
724  menubound[K_ESCAPE] = true;
725  for (i=0 ; i<12 ; i++)
726  menubound[K_F1+i] = true;
727 
728 //
729 // register our functions
730 //
731  Cmd_AddCommand ("bind",Key_Bind_f);
732  Cmd_AddCommand ("unbind",Key_Unbind_f);
733  Cmd_AddCommand ("unbindall",Key_Unbindall_f);
734  Cmd_AddCommand ("bindlist",Key_Bindlist_f);
735 }
736 
737 /*
738 ===================
739 Key_Event
740 
741 Called by the system between frames for both key up and key down events
742 Should NOT be called during an interrupt!
743 ===================
744 */
745 void Key_Event (int key, qboolean down, unsigned time)
746 {
747  char *kb;
748  char cmd[1024];
749 
750  // hack for modal presses
751  if (key_waiting == -1)
752  {
753  if (down)
754  key_waiting = key;
755  return;
756  }
757 
758  // update auto-repeat status
759  if (down)
760  {
761  key_repeats[key]++;
762  if (key != K_BACKSPACE
763  && key != K_PAUSE
764  && key != K_PGUP
765  && key != K_KP_PGUP
766  && key != K_PGDN
767  && key != K_KP_PGDN
768  && key_repeats[key] > 1)
769  return; // ignore most autorepeats
770 
771  if (key >= 200 && !keybindings[key])
772  Com_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) );
773  }
774  else
775  {
776  key_repeats[key] = 0;
777  }
778 
779  if (key == K_SHIFT)
780  shift_down = down;
781 
782  // console key is hardcoded, so the user can never unbind it
783  if (key == '`' || key == '~')
784  {
785  if (!down)
786  return;
788  return;
789  }
790 
791  // any key during the attract mode will bring up the menu
792  if (cl.attractloop && cls.key_dest != key_menu &&
793  !(key >= K_F1 && key <= K_F12))
794  key = K_ESCAPE;
795 
796  // menu key is hardcoded, so the user can never unbind it
797  if (key == K_ESCAPE)
798  {
799  if (!down)
800  return;
801 
803  { // put away help computer / inventory
804  Cbuf_AddText ("cmd putaway\n");
805  return;
806  }
807  switch (cls.key_dest)
808  {
809  case key_message:
810  Key_Message (key);
811  break;
812  case key_menu:
813  M_Keydown (key);
814  break;
815  case key_game:
816  case key_console:
817  M_Menu_Main_f ();
818  break;
819  default:
820  Com_Error (ERR_FATAL, "Bad cls.key_dest");
821  }
822  return;
823  }
824 
825  // track if any key is down for BUTTON_ANY
826  keydown[key] = down;
827  if (down)
828  {
829  if (key_repeats[key] == 1)
830  anykeydown++;
831  }
832  else
833  {
834  anykeydown--;
835  if (anykeydown < 0)
836  anykeydown = 0;
837  }
838 
839 //
840 // key up events only generate commands if the game key binding is
841 // a button command (leading + sign). These will occur even in console mode,
842 // to keep the character from continuing an action started before a console
843 // switch. Button commands include the kenum as a parameter, so multiple
844 // downs can be matched with ups
845 //
846  if (!down)
847  {
848  kb = keybindings[key];
849  if (kb && kb[0] == '+')
850  {
851  Com_sprintf (cmd, sizeof(cmd), "-%s %i %i\n", kb+1, key, time);
852  Cbuf_AddText (cmd);
853  }
854  if (keyshift[key] != key)
855  {
856  kb = keybindings[keyshift[key]];
857  if (kb && kb[0] == '+')
858  {
859  Com_sprintf (cmd, sizeof(cmd), "-%s %i %i\n", kb+1, key, time);
860  Cbuf_AddText (cmd);
861  }
862  }
863  return;
864  }
865 
866 //
867 // if not a consolekey, send to the interpreter no matter what mode is
868 //
869  if ( (cls.key_dest == key_menu && menubound[key])
870  || (cls.key_dest == key_console && !consolekeys[key])
871  || (cls.key_dest == key_game && ( cls.state == ca_active || !consolekeys[key] ) ) )
872  {
873  kb = keybindings[key];
874  if (kb)
875  {
876  if (kb[0] == '+')
877  { // button commands add keynum and time as a parm
878  Com_sprintf (cmd, sizeof(cmd), "%s %i %i\n", kb, key, time);
879  Cbuf_AddText (cmd);
880  }
881  else
882  {
883  Cbuf_AddText (kb);
884  Cbuf_AddText ("\n");
885  }
886  }
887  return;
888  }
889 
890  if (!down)
891  return; // other systems only care about key down events
892 
893  if (shift_down)
894  key = keyshift[key];
895 
896  switch (cls.key_dest)
897  {
898  case key_message:
899  Key_Message (key);
900  break;
901  case key_menu:
902  M_Keydown (key);
903  break;
904 
905  case key_game:
906  case key_console:
907  Key_Console (key);
908  break;
909  default:
910  Com_Error (ERR_FATAL, "Bad cls.key_dest");
911  }
912 }
913 
914 /*
915 ===================
916 Key_ClearStates
917 ===================
918 */
919 void Key_ClearStates (void)
920 {
921  int i;
922 
923  anykeydown = false;
924 
925  for (i=0 ; i<K_LAST ; i++)
926  {
927  if ( keydown[i] || key_repeats[i] )
928  Key_Event( i, false, 0 );
929  keydown[i] = 0;
930  key_repeats[i] = 0;
931  }
932 }
933 
934 
935 /*
936 ===================
937 Key_GetKey
938 ===================
939 */
940 int Key_GetKey (void)
941 {
942  key_waiting = -1;
943 
944  while (key_waiting == -1)
946 
947  return key_waiting;
948 }
949 
K_KP_PLUS
@ K_KP_PLUS
Definition: keys.h:74
K_AUX3
@ K_AUX3
Definition: keys.h:99
keyname_t::keynum
int keynum
Definition: keys.c:49
K_END
@ K_END
Definition: keys.h:58
keydown
qboolean keydown[K_LAST]
Definition: keys.c:44
K_DOWNARROW
@ K_DOWNARROW
Definition: keys.h:34
K_AUX31
@ K_AUX31
Definition: keys.h:127
K_KP_UPARROW
@ K_KP_UPARROW
Definition: keys.h:61
client_state_t::attractloop
qboolean attractloop
Definition: client.h:173
K_MOUSE4
@ K_MOUSE4
Definition: keys.h:82
Key_WriteBindings
void Key_WriteBindings(FILE *f)
Definition: keys.c:619
chat_buffer
char chat_buffer[MAXCMDLINE]
Definition: keys.c:395
Key_SetBinding
void Key_SetBinding(int keynum, char *binding)
Definition: keys.c:509
ca_disconnected
@ ca_disconnected
Definition: client.h:206
Key_Event
void Key_Event(int key, qboolean down, unsigned time)
Definition: keys.c:745
K_KP_PGDN
@ K_KP_PGDN
Definition: keys.h:68
Key_StringToKeynum
int Key_StringToKeynum(char *str)
Definition: keys.c:456
K_MOUSE5
@ K_MOUSE5
Definition: keys.h:83
M_Menu_Main_f
void M_Menu_Main_f(void)
Definition: menu.c:494
K_AUX26
@ K_AUX26
Definition: keys.h:122
K_AUX28
@ K_AUX28
Definition: keys.h:124
K_AUX13
@ K_AUX13
Definition: keys.h:109
keyshift
int keyshift[K_LAST]
Definition: keys.c:42
qboolean
qboolean
Definition: q_shared.h:56
i
int i
Definition: q_shared.c:305
keybindings
char * keybindings[K_LAST]
Definition: keys.c:39
anykeydown
int anykeydown
Definition: keys.c:33
K_AUX18
@ K_AUX18
Definition: keys.h:114
K_AUX4
@ K_AUX4
Definition: keys.h:100
K_KP_LEFTARROW
@ K_KP_LEFTARROW
Definition: keys.h:63
K_AUX23
@ K_AUX23
Definition: keys.h:119
K_F12
@ K_F12
Definition: keys.h:52
ca_active
@ ca_active
Definition: client.h:209
K_AUX2
@ K_AUX2
Definition: keys.h:98
Con_ToggleConsole_f
void Con_ToggleConsole_f(void)
Definition: console.c:75
K_F7
@ K_F7
Definition: keys.h:47
K_AUX8
@ K_AUX8
Definition: keys.h:104
K_AUX12
@ K_AUX12
Definition: keys.h:108
K_AUX11
@ K_AUX11
Definition: keys.h:107
K_MWHEELDOWN
@ K_MWHEELDOWN
Definition: keys.h:130
Key_Init
void Key_Init(void)
Definition: keys.c:650
chat_bufferlen
int chat_bufferlen
Definition: keys.c:396
key_waiting
int key_waiting
Definition: keys.c:38
K_HOME
@ K_HOME
Definition: keys.h:57
K_AUX17
@ K_AUX17
Definition: keys.h:113
K_KP_HOME
@ K_KP_HOME
Definition: keys.h:60
K_ENTER
@ K_ENTER
Definition: keys.h:26
key_menu
@ key_menu
Definition: client.h:220
K_JOY3
@ K_JOY3
Definition: keys.h:90
K_AUX29
@ K_AUX29
Definition: keys.h:125
K_KP_INS
@ K_KP_INS
Definition: keys.h:70
K_F8
@ K_F8
Definition: keys.h:48
Cmd_Argv
char * Cmd_Argv(int arg)
Definition: cmd.c:517
Cmd_Argc
int Cmd_Argc(void)
Definition: cmd.c:507
K_LEFTARROW
@ K_LEFTARROW
Definition: keys.h:35
K_KP_MINUS
@ K_KP_MINUS
Definition: keys.h:73
K_AUX6
@ K_AUX6
Definition: keys.h:102
keyname_t
Definition: keys.c:46
K_F6
@ K_F6
Definition: keys.h:46
SCR_UpdateScreen
void SCR_UpdateScreen(void)
Definition: cl_scrn.c:1285
K_AUX27
@ K_AUX27
Definition: keys.h:123
K_AUX20
@ K_AUX20
Definition: keys.h:116
K_ESCAPE
@ K_ESCAPE
Definition: keys.h:27
Cmd_CompleteCommand
char * Cmd_CompleteCommand(char *partial)
Definition: cmd.c:772
K_AUX21
@ K_AUX21
Definition: keys.h:117
MAXCMDLINE
#define MAXCMDLINE
Definition: keys.c:29
K_F2
@ K_F2
Definition: keys.h:42
key_repeats
int key_repeats[K_LAST]
Definition: keys.c:43
console_t::current
int current
Definition: console.h:33
K_PGUP
@ K_PGUP
Definition: keys.h:56
consolekeys
qboolean consolekeys[K_LAST]
Definition: keys.c:40
K_JOY1
@ K_JOY1
Definition: keys.h:88
K_AUX30
@ K_AUX30
Definition: keys.h:126
shift_down
int shift_down
Definition: keys.c:32
K_F10
@ K_F10
Definition: keys.h:50
Sys_SendKeyEvents
void Sys_SendKeyEvents(void)
Definition: sys_win.c:376
keyname_t::name
char * name
Definition: keys.c:48
K_KP_RIGHTARROW
@ K_KP_RIGHTARROW
Definition: keys.h:65
Cmd_AddCommand
void Cmd_AddCommand(char *cmd_name, xcommand_t function)
Definition: cmd.c:691
Key_Bindlist_f
void Key_Bindlist_f(void)
Definition: keys.c:635
K_PGDN
@ K_PGDN
Definition: keys.h:55
key_game
@ key_game
Definition: client.h:220
K_AUX5
@ K_AUX5
Definition: keys.h:101
Cbuf_AddText
void Cbuf_AddText(char *text)
Definition: cmd.c:90
K_INS
@ K_INS
Definition: keys.h:53
K_JOY4
@ K_JOY4
Definition: keys.h:91
Cvar_CompleteVariable
char * Cvar_CompleteVariable(char *partial)
Definition: cvar.c:95
Key_Unbind_f
void Key_Unbind_f(void)
Definition: keys.c:537
K_F9
@ K_F9
Definition: keys.h:49
con
console_t con
Definition: console.c:24
key_console
@ key_console
Definition: client.h:220
NULL
#define NULL
Definition: q_shared.h:60
client_state_t::frame
frame_t frame
Definition: client.h:136
K_CTRL
@ K_CTRL
Definition: keys.h:39
K_KP_END
@ K_KP_END
Definition: keys.h:66
Com_Error
void Com_Error(int code, char *fmt,...)
Definition: common.c:203
Key_KeynumToString
char * Key_KeynumToString(int keynum)
Definition: keys.c:482
history_line
int history_line
Definition: keys.c:36
Z_Malloc
void * Z_Malloc(int size)
Definition: common.c:1223
K_MOUSE3
@ K_MOUSE3
Definition: keys.h:81
K_AUX1
@ K_AUX1
Definition: keys.h:97
menubound
qboolean menubound[K_LAST]
Definition: keys.c:41
K_F3
@ K_F3
Definition: keys.h:43
chat_team
qboolean chat_team
Definition: keys.c:394
K_KP_ENTER
@ K_KP_ENTER
Definition: keys.h:69
Key_Message
void Key_Message(int key)
Definition: keys.c:398
edit_line
int edit_line
Definition: keys.c:35
console_t::totallines
int totallines
Definition: console.h:40
ERR_FATAL
#define ERR_FATAL
Definition: qcommon.h:735
key_linepos
int key_linepos
Definition: keys.c:31
K_AUX19
@ K_AUX19
Definition: keys.h:115
K_KP_DEL
@ K_KP_DEL
Definition: keys.h:71
K_MOUSE2
@ K_MOUSE2
Definition: keys.h:80
frame_t::playerstate
player_state_t playerstate
Definition: client.h:70
K_JOY2
@ K_JOY2
Definition: keys.h:89
Key_Unbindall_f
void Key_Unbindall_f(void)
Definition: keys.c:557
Z_Free
void Z_Free(void *ptr)
Definition: common.c:1141
client_static_t::state
connstate_t state
Definition: client.h:224
K_F4
@ K_F4
Definition: keys.h:44
K_AUX22
@ K_AUX22
Definition: keys.h:118
K_KP_SLASH
@ K_KP_SLASH
Definition: keys.h:72
K_TAB
@ K_TAB
Definition: keys.h:25
K_UPARROW
@ K_UPARROW
Definition: keys.h:33
M_Keydown
void M_Keydown(int key)
Definition: menu.c:4077
K_AUX7
@ K_AUX7
Definition: keys.h:103
K_AUX10
@ K_AUX10
Definition: keys.h:106
keynames
keyname_t keynames[]
Definition: keys.c:52
K_SHIFT
@ K_SHIFT
Definition: keys.h:40
K_SPACE
@ K_SPACE
Definition: keys.h:28
K_AUX32
@ K_AUX32
Definition: keys.h:128
console_t::display
int display
Definition: console.h:35
Key_Bind_f
void Key_Bind_f(void)
Definition: keys.c:572
Key_GetKey
int Key_GetKey(void)
Definition: keys.c:940
K_KP_5
@ K_KP_5
Definition: keys.h:64
K_KP_PGUP
@ K_KP_PGUP
Definition: keys.h:62
K_LAST
@ K_LAST
Definition: keys.h:135
key_lines
char key_lines[32][MAXCMDLINE]
Definition: keys.c:30
client_static_t::key_dest
keydest_t key_dest
Definition: client.h:225
K_PAUSE
@ K_PAUSE
Definition: keys.h:133
K_ALT
@ K_ALT
Definition: keys.h:38
K_AUX25
@ K_AUX25
Definition: keys.h:121
Com_Printf
void Com_Printf(char *fmt,...)
Definition: common.c:102
K_AUX9
@ K_AUX9
Definition: keys.h:105
K_F11
@ K_F11
Definition: keys.h:51
STAT_LAYOUTS
#define STAT_LAYOUTS
Definition: q_shared.h:1038
Q_strcasecmp
int Q_strcasecmp(char *s1, char *s2)
Definition: q_shared.c:1229
K_RIGHTARROW
@ K_RIGHTARROW
Definition: keys.h:36
K_AUX14
@ K_AUX14
Definition: keys.h:110
K_DEL
@ K_DEL
Definition: keys.h:54
K_AUX24
@ K_AUX24
Definition: keys.h:120
Key_Console
void Key_Console(int key)
Definition: keys.c:197
cls
client_static_t cls
Definition: cl_main.c:105
Key_ClearStates
void Key_ClearStates(void)
Definition: keys.c:919
K_MOUSE1
@ K_MOUSE1
Definition: keys.h:79
K_AUX15
@ K_AUX15
Definition: keys.h:111
key_message
@ key_message
Definition: client.h:220
K_F5
@ K_F5
Definition: keys.h:45
K_MWHEELUP
@ K_MWHEELUP
Definition: keys.h:131
cl
client_state_t cl
Definition: cl_main.c:106
Sys_GetClipboardData
char * Sys_GetClipboardData(void)
Definition: sys_win.c:401
K_BACKSPACE
@ K_BACKSPACE
Definition: keys.h:32
K_KP_DOWNARROW
@ K_KP_DOWNARROW
Definition: keys.h:67
K_F1
@ K_F1
Definition: keys.h:41
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236
client.h
K_AUX16
@ K_AUX16
Definition: keys.h:112
player_state_t::stats
short stats[MAX_STATS]
Definition: q_shared.h:1220
CompleteCommand
void CompleteCommand(void)
Definition: keys.c:167