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