X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=keys.c;h=2d6fd69a25f68f04772767279ef426c250c9bc1f;hb=b84125ed0d5fc6922a9ea18b7762b489e377175d;hp=c23c294564b86ee1aa3631dc8e63d41676aace71;hpb=7fc7bebd4d2729c358cecb531cc3443da4eee795;p=xonotic%2Fdarkplaces.git diff --git a/keys.c b/keys.c index c23c2945..2d6fd69a 100644 --- a/keys.c +++ b/keys.c @@ -37,12 +37,14 @@ int key_consoleactive; char *keybindings[MAX_BINDMAPS][MAX_KEYS]; static int key_bmap, key_bmap2; -static qbyte keydown[MAX_KEYS]; // 0 = up, 1 = down, 2 = repeating +static unsigned char keydown[MAX_KEYS]; // 0 = up, 1 = down, 2 = repeating -typedef struct { +typedef struct keyname_s +{ const char *name; int keynum; -} keyname_t; +} +keyname_t; static const keyname_t keynames[] = { {"TAB", K_TAB}, @@ -272,7 +274,7 @@ Key_Console (int key, char ascii) { int i; strtok(cbd, "\n\r\b"); - i = strlen(cbd); + i = (int)strlen(cbd); if (i + key_linepos >= MAX_INPUTLINE) i= MAX_INPUTLINE - key_linepos; if (i > 0) @@ -324,12 +326,29 @@ Key_Console (int key, char ascii) // Advanced Console Editing by Radix radix@planetquake.com // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com + // Enhanced by [515] // left arrow will just move left one without erasing, backspace will - // actually erase charcter + // actually erase character if (key == K_LEFTARROW || key == K_KP_LEFTARROW) { - if (key_linepos > 1) + if (key_linepos < 2) + return; + if(keydown[K_CTRL]) + { + int pos; + char k; + pos = key_linepos-1; + if(pos) + while(--pos) + { + k = key_lines[edit_line][pos]; + if(k == '\"' || k == ';' || k == ' ' || k == '\'') + break; + } + key_linepos = pos + 1; + } + else key_linepos--; return; } @@ -348,7 +367,7 @@ Key_Console (int key, char ascii) // delete char on cursor if (key == K_DEL || key == K_KP_DEL) { - if ((size_t)key_linepos < strlen(key_lines[edit_line])) + if (key_linepos < (int)strlen(key_lines[edit_line])) strcpy(key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1); return; } @@ -358,9 +377,24 @@ Key_Console (int key, char ascii) // otherwise just go right one if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW) { - if ((size_t)key_linepos < strlen(key_lines[edit_line])) + if (key_linepos >= (int)strlen(key_lines[edit_line])) + return; + if(keydown[K_CTRL]) + { + int pos, len; + char k; + len = (int)strlen(key_lines[edit_line]); + pos = key_linepos; + while(++pos < len) + { + k = key_lines[edit_line][pos]; + if(k == '\"' || k == ';' || k == ' ' || k == '\'') + break; + } + key_linepos = pos; + } + else key_linepos++; - return; } @@ -378,7 +412,7 @@ Key_Console (int key, char ascii) { history_line--; strcpy(key_lines[edit_line], key_lines[history_line]); - key_linepos = strlen(key_lines[edit_line]); + key_linepos = (int)strlen(key_lines[edit_line]); } return; } @@ -396,7 +430,7 @@ Key_Console (int key, char ascii) else { strcpy(key_lines[edit_line], key_lines[history_line]); - key_linepos = strlen(key_lines[edit_line]); + key_linepos = (int)strlen(key_lines[edit_line]); } return; } @@ -419,13 +453,19 @@ Key_Console (int key, char ascii) if (key == K_HOME || key == K_KP_HOME) { - con_backscroll = con_totallines - (vid_conheight.integer>>3) - 1; + if (keydown[K_CTRL]) + con_backscroll = con_totallines - (vid_conheight.integer>>3) - 1; + else + key_linepos = 1; return; } if (key == K_END || key == K_KP_END) { - con_backscroll = 0; + if (keydown[K_CTRL]) + con_backscroll = 0; + else + key_linepos = (int)strlen(key_lines[edit_line]); return; } @@ -436,7 +476,7 @@ Key_Console (int key, char ascii) if (key_linepos < MAX_INPUTLINE-1) { int len; - len = strlen(&key_lines[edit_line][key_linepos]); + len = (int)strlen(&key_lines[edit_line][key_linepos]); // check insert mode, or always insert if at end of line if (key_insert || len == 0) { @@ -553,8 +593,8 @@ Key_KeynumToString (int keynum) void Key_SetBinding (int keynum, int bindmap, const char *binding) { - char *new; - int l; + char *newbinding; + size_t l; if (keynum == -1) return; @@ -566,10 +606,10 @@ Key_SetBinding (int keynum, int bindmap, const char *binding) } // allocate memory for new binding l = strlen (binding); - new = Z_Malloc (l + 1); - strcpy (new, binding); - new[l] = 0; - keybindings[bindmap][keynum] = new; + newbinding = (char *)Z_Malloc (l + 1); + strcpy (newbinding, binding); + newbinding[l] = 0; + keybindings[bindmap][keynum] = newbinding; } static void @@ -601,7 +641,7 @@ static void Key_In_Bind_f (void) { int i, c, b, m; - char cmd[1024]; + char cmd[MAX_INPUTLINE]; c = Cmd_Argc (); @@ -703,7 +743,7 @@ static void Key_Bind_f (void) { int i, c, b; - char cmd[1024]; + char cmd[MAX_INPUTLINE]; c = Cmd_Argc (); @@ -771,15 +811,25 @@ Key_Init (void) // // register our functions // - Cmd_AddCommand ("in_bind", Key_In_Bind_f); - Cmd_AddCommand ("in_unbind", Key_In_Unbind_f); - Cmd_AddCommand ("in_bindmap", Key_In_Bindmap_f); + Cmd_AddCommand ("in_bind", Key_In_Bind_f, "binds a command to the specified key in the selected bindmap"); + Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap"); + Cmd_AddCommand ("in_bindmap", Key_In_Bindmap_f, "selects active foreground and background (used only if a key is not bound in the foreground) bindmaps for typing"); - Cmd_AddCommand ("bind", Key_Bind_f); - Cmd_AddCommand ("unbind", Key_Unbind_f); - Cmd_AddCommand ("unbindall", Key_Unbindall_f); + Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0"); + Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0"); + Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)"); +} + +const char *Key_GetBind (int key) +{ + const char *bind; + bind = keybindings[key_bmap][key]; + if (!bind) + bind = keybindings[key_bmap2][key]; + return bind; } +qboolean CL_VM_InputEvent (qboolean pressed, int key); /* =================== @@ -791,12 +841,26 @@ void Key_Event (int key, char ascii, qboolean down) { const char *bind; + qboolean q; // get key binding bind = keybindings[key_bmap][key]; if (!bind) bind = keybindings[key_bmap2][key]; + if(key_dest == key_game) + { + q = CL_VM_InputEvent(!down, key); + if(q) + { + if (down) + keydown[key] = min(keydown[key] + 1, 2); + else + keydown[key] = 0; + return; + } + } + if (!down) { // clear repeat count now that the key is released @@ -839,7 +903,7 @@ Key_Event (int key, char ascii, qboolean down) // key_menu - go to parent menu (or key_game) // key_game - open menu // in all modes shift-escape toggles console - if (key_consoleactive || keydown[K_SHIFT]) + if ((key_consoleactive & KEY_CONSOLEACTIVE_USER) || keydown[K_SHIFT]) { Con_ToggleConsole_f (); return; @@ -859,7 +923,7 @@ Key_Event (int key, char ascii, qboolean down) if(UI_Callback_IsSlotUsed(key_dest - 3)) UI_Callback_KeyDown (key, ascii); else - Sys_Error ("Bad key_dest"); + Con_Printf ("Key_Event: Bad key_dest\n"); } return; } @@ -924,7 +988,7 @@ Key_Event (int key, char ascii, qboolean down) if(UI_Callback_IsSlotUsed(key_dest - 3)) UI_Callback_KeyDown (key, ascii); else - Sys_Error ("Bad key_dest"); + Con_Printf ("Key_Event: Bad key_dest\n"); } }