*/
#include "quakedef.h"
+#include <ctype.h>
/*
#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;
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];
{"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},
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)
}
// non printable
- if (key < 32 || key > 127)
+ if (ascii < 32 || ascii > 126)
return;
if (key_linepos < MAXCMDLINE-1)
// 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)
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)
{
return;
}
- // non printable
- if (key < 32 || key > 127)
- return;
-
if (key == K_BACKSPACE)
{
if (chat_bufferlen)
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;
}
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;
}
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]);
}
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;
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];
else
key_repeats[key] = 0;
- if (key == K_SHIFT)
- shift_down = down;
-
//
// handle escape specialy, so the user can never unbind it
//
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;
}
}
}
- 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
{
//
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;
}
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");
}
}
}