]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - keys.c
added c_nodes, c_leafs, and c_faces increments in q3bsp rendering to make r_speeds...
[xonotic/darkplaces.git] / keys.c
diff --git a/keys.c b/keys.c
index 9b018bde264c4df41b8c317c9075ef748116ca8d..fab2478bd327e31b0ca903046968f002d341175e 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */
 #include "quakedef.h"
+#include <ctype.h>
 
 /*
 
@@ -29,7 +30,6 @@ key up events are sent even if in console mode
 #define MAXCMDLINE 256
 char key_lines[32][MAXCMDLINE];
 int key_linepos;
-int shift_down = false;
 int key_insert;        // insert key toggle (for editing)
 
 int edit_line = 0;
@@ -41,7 +41,6 @@ keydest_t key_dest;
 char *keybindings[256];
 qboolean consolekeys[256];     // if true, can't be rebound while in console
 qboolean menubound[256];       // if true, can't be rebound while in menu
-int keyshift[256];             // key to map to if shift held down in console
 int key_repeats[256];  // if > 1, it is autorepeating
 qboolean keydown[256];
 
@@ -90,6 +89,17 @@ keyname_t keynames[] =
        {"MOUSE1", K_MOUSE1},
        {"MOUSE2", K_MOUSE2},
        {"MOUSE3", K_MOUSE3},
+       // LordHavoc: thanks to backslash for this MOUSE4 and MOUSE5 code
+       /* backslash :: imouse explorer buttons */
+       {"MOUSE4", K_MOUSE4},
+       {"MOUSE5", K_MOUSE5},
+       /* :: backslash */
+       // LordHavoc: added more for completeness
+       {"MOUSE6", K_MOUSE6},
+       {"MOUSE7", K_MOUSE7},
+       {"MOUSE8", K_MOUSE8},
+       {"MOUSE9", K_MOUSE9},
+       {"MOUSE10", K_MOUSE10},
 
        {"JOY1", K_JOY1},
        {"JOY2", K_JOY2},
@@ -171,7 +181,7 @@ Key_Console
 Interactive line editing and console scrollback
 ====================
 */
-void Key_Console (int key)
+void Key_Console (int key, char ascii)
 {
        // LordHavoc: copied most of this from Q2 to improve keyboard handling
        switch (key)
@@ -405,7 +415,7 @@ void Key_Console (int key)
        }
 
        // non printable
-       if (key < 32 || key > 127)
+       if (ascii < 32 || ascii > 126)
                return;
 
        if (key_linepos < MAXCMDLINE-1)
@@ -426,7 +436,7 @@ void Key_Console (int key)
 
                // only null terminate if at the end
                i = key_lines[edit_line][key_linepos];
-               key_lines[edit_line][key_linepos] = key;
+               key_lines[edit_line][key_linepos] = ascii;
                key_linepos++;
 
                if (!i)
@@ -441,7 +451,7 @@ qboolean chat_team = false;
 char chat_buffer[256];
 int chat_bufferlen = 0;
 
-void Key_Message (int key)
+void Key_Message (int key, char ascii)
 {
        if (key == K_ENTER || key == K_KP_ENTER)
        {
@@ -466,10 +476,6 @@ void Key_Message (int key)
                return;
        }
 
-       // non printable
-       if (key < 32 || key > 127)
-               return;
-
        if (key == K_BACKSPACE)
        {
                if (chat_bufferlen)
@@ -480,10 +486,14 @@ void Key_Message (int key)
                return;
        }
 
+       // non printable
+       if (ascii < 32 || ascii > 126)
+               return;
+
        if (chat_bufferlen == sizeof(chat_buffer) - 1)
                return; // all full
 
-       chat_buffer[chat_bufferlen++] = key;
+       chat_buffer[chat_bufferlen++] = ascii;
        chat_buffer[chat_bufferlen] = 0;
 }
 
@@ -506,10 +516,10 @@ int Key_StringToKeynum (const char *str)
        if (!str || !str[0])
                return -1;
        if (!str[1])
-               return str[0];
+               return tolower(str[0]);
 
        for (kn=keynames ; kn->name ; kn++)
-               if (!Q_strcasecmp(str,kn->name))
+               if (!strcasecmp(str,kn->name))
                        return kn->keynum;
        return -1;
 }
@@ -661,13 +671,13 @@ Key_WriteBindings
 Writes lines containing "bind key value"
 ============
 */
-void Key_WriteBindings (QFile *f)
+void Key_WriteBindings (qfile_t *f)
 {
        int i;
 
        for (i = 0;i < 256;i++)
                if (keybindings[i] && *keybindings[i])
-                       Qprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
+                       FS_Printf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
 }
 
 
@@ -736,32 +746,6 @@ void Key_Init (void)
        consolekeys['`'] = false;
        consolekeys['~'] = false;
 
-       for (i = 0;i < 256;i++)
-               keyshift[i] = i;
-       for (i = 'a';i <= 'z';i++)
-               keyshift[i] = i - 'a' + 'A';
-       keyshift['1'] = '!';
-       keyshift['2'] = '@';
-       keyshift['3'] = '#';
-       keyshift['4'] = '$';
-       keyshift['5'] = '%';
-       keyshift['6'] = '^';
-       keyshift['7'] = '&';
-       keyshift['8'] = '*';
-       keyshift['9'] = '(';
-       keyshift['0'] = ')';
-       keyshift['-'] = '_';
-       keyshift['='] = '+';
-       keyshift[','] = '<';
-       keyshift['.'] = '>';
-       keyshift['/'] = '?';
-       keyshift[';'] = ':';
-       keyshift['\''] = '"';
-       keyshift['['] = '{';
-       keyshift[']'] = '}';
-       keyshift['`'] = '~';
-       keyshift['\\'] = '|';
-
        menubound[K_ESCAPE] = true;
        for (i=0 ; i<12 ; i++)
                menubound[K_F1+i] = true;
@@ -783,7 +767,7 @@ Called by the system between frames for both key up and key down events
 Should NOT be called during an interrupt!
 ===================
 */
-void Key_Event (int key, qboolean down)
+void Key_Event (int key, char ascii, qboolean down)
 {
        char    *kb;
        char    cmd[1024];
@@ -809,9 +793,6 @@ void Key_Event (int key, qboolean down)
        else
                key_repeats[key] = 0;
 
-       if (key == K_SHIFT)
-               shift_down = down;
-
 //
 // handle escape specialy, so the user can never unbind it
 //
@@ -822,16 +803,19 @@ void Key_Event (int key, qboolean down)
                switch (key_dest)
                {
                case key_message:
-                       Key_Message (key);
+                       Key_Message (key, 0);
                        break;
                case key_menu:
-                       M_Keydown (key);
+                       MR_Keydown (key, 0);
                        break;
                case key_game:
-                       M_ToggleMenu_f ();
+                       MR_ToggleMenu_f ();
                        break;
                default:
-                       Sys_Error ("Bad key_dest");
+                       if(UI_Callback_IsSlotUsed(key_dest - 3))
+                               UI_Callback_KeyDown (key, ascii);
+                       else
+                               Sys_Error ("Bad key_dest");
                }
                return;
        }
@@ -855,18 +839,13 @@ void Key_Event (int key, qboolean down)
                }
        }
 
-       if (key_consoleactive && consolekeys[key])
-       {
-               // console only wants key down events
-               if (!down)
-                       return;
-
-               // FIXME: this does not support non-QWERTY keyboards
-               if (shift_down)
-                       key = keyshift[key];
-
-               Key_Console (key);
-       }
+       // AK New WTF ?!?
+       // AK Changed so the code does what the comments tell 
+       // 
+       // 1. if console is active or not, always send the up events
+       // console only wants key down events
+       if (key_consoleactive && consolekeys[key] && down)
+               Key_Console (key, ascii);
        else
        {
                //
@@ -884,15 +863,6 @@ void Key_Event (int key, qboolean down)
                                sprintf (cmd, "-%s %i\n", kb+1, key);
                                Cbuf_AddText (cmd);
                        }
-                       if (keyshift[key] != key)
-                       {
-                               kb = keybindings[keyshift[key]];
-                               if (kb && kb[0] == '+')
-                               {
-                                       sprintf (cmd, "-%s %i\n", kb+1, key);
-                                       Cbuf_AddText (cmd);
-                               }
-                       }
                        return;
                }
 
@@ -927,28 +897,24 @@ void Key_Event (int key, qboolean down)
                        return;
                }
 
-               if (!down)
-                       return;         // other systems only care about key down events
-
-               // FIXME: this does not support non-QWERTY keyboards
-               if (shift_down)
-                       key = keyshift[key];
-
                switch (key_dest)
                {
                case key_message:
-                       Key_Message (key);
+                       Key_Message (key, ascii);
                        break;
                case key_menu:
-                       M_Keydown (key);
+                       MR_Keydown (key, ascii);
                        break;
 
                case key_game:
                //case key_console:
-                       Key_Console (key);
+                       Key_Console (key, ascii);
                        break;
                default:
-                       Sys_Error ("Bad key_dest");
+                       if(UI_Callback_IsSlotUsed(key_dest - 3))
+                               UI_Callback_KeyDown (key, ascii);
+                       else
+                               Sys_Error ("Bad key_dest");
                }
        }
 }