#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];
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;
}
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:
- MR_Keydown (key);
+ MR_Keydown (key, 0);
break;
case key_game:
MR_ToggleMenu_f ();
//if (!down)
// return;
- // FIXME: this does not support non-QWERTY keyboards
- if (shift_down)
- key = keyshift[key];
-
- Key_Console (key);
+ 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;
}
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:
- MR_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");
extern int key_consoleactive;
extern keydest_t key_dest;
-void Key_Event (int key, qboolean down);
+void Key_Event (int key, char ascii, qboolean down);
void Key_Init (void);
void Key_WriteBindings (qfile_t *f);
void Key_SetBinding (int keynum, char *binding);
void M_GameOptions_Draw (void);
void M_ServerList_Draw (void);
-void M_Main_Key (int key);
- void M_SinglePlayer_Key (int key);
- void M_Load_Key (int key);
- void M_Save_Key (int key);
- void M_MultiPlayer_Key (int key);
- void M_Setup_Key (int key);
- void M_Options_Key (int key);
- void M_Options_Effects_Key (int key);
- void M_Options_ColorControl_Key (int key);
- void M_Keys_Key (int key);
- void M_Video_Key (int key);
- void M_Help_Key (int key);
- void M_Quit_Key (int key);
-void M_LanConfig_Key (int key);
-void M_GameOptions_Key (int key);
-void M_ServerList_Key (int key);
+void M_Main_Key (int key, char ascii);
+ void M_SinglePlayer_Key (int key, char ascii);
+ void M_Load_Key (int key, char ascii);
+ void M_Save_Key (int key, char ascii);
+ void M_MultiPlayer_Key (int key, char ascii);
+ void M_Setup_Key (int key, char ascii);
+ void M_Options_Key (int key, char ascii);
+ void M_Options_Effects_Key (int key, char ascii);
+ void M_Options_ColorControl_Key (int key, char ascii);
+ void M_Keys_Key (int key, char ascii);
+ void M_Video_Key (int key, char ascii);
+ void M_Help_Key (int key, char ascii);
+ void M_Quit_Key (int key, char ascii);
+void M_LanConfig_Key (int key, char ascii);
+void M_GameOptions_Key (int key, char ascii);
+void M_ServerList_Key (int key, char ascii);
qboolean m_entersound; // play after drawing a frame, so caching
// won't disrupt the sound
m_entersound = true;
}
-void M_Demo_Key (int k)
+void M_Demo_Key (int k, char ascii)
{
switch (k)
{
}
-void M_Main_Key (int key)
+void M_Main_Key (int key, char ascii)
{
switch (key)
{
}
-void M_SinglePlayer_Key (int key)
+void M_SinglePlayer_Key (int key, char ascii)
{
if (gamemode == GAME_TRANSFUSION || gamemode == GAME_NEXUIZ || gamemode == GAME_GOODVSBAD2 || gamemode == GAME_BATTLEMECH)
{
}
-void M_Load_Key (int k)
+void M_Load_Key (int k, char ascii)
{
switch (k)
{
}
-void M_Save_Key (int k)
+void M_Save_Key (int k, char ascii)
{
switch (k)
{
}
-void M_MultiPlayer_Key (int key)
+void M_MultiPlayer_Key (int key, char ascii)
{
switch (key)
{
}
-void M_Setup_Key (int k)
+void M_Setup_Key (int k, char ascii)
{
int l;
break;
default:
- if (k < 32 || k > 127)
+ if (ascii < 32 || ascii > 126)
break;
if (setup_cursor == 0)
{
if (l < 15)
{
setup_myname[l+1] = 0;
- setup_myname[l] = k;
+ setup_myname[l] = ascii;
}
}
}
}
-void M_Options_Key (int k)
+void M_Options_Key (int k, char ascii)
{
switch (k)
{
}
-void M_Options_Effects_Key (int k)
+void M_Options_Effects_Key (int k, char ascii)
{
switch (k)
{
}
-void M_Options_ColorControl_Key (int k)
+void M_Options_ColorControl_Key (int k, char ascii)
{
switch (k)
{
}
-void M_Keys_Key (int k)
+void M_Keys_Key (int k, char ascii)
{
char cmd[80];
int keys[NUMKEYS];
}
-void M_Video_Key (int key)
+void M_Video_Key (int key, char ascii)
{
switch (key)
{
}
-void M_Help_Key (int key)
+void M_Help_Key (int key, char ascii)
{
switch (key)
{
}
-void M_Quit_Key (int key)
+void M_Quit_Key (int key, char ascii)
{
switch (key)
{
}
-void M_LanConfig_Key (int key)
+void M_LanConfig_Key (int key, char ascii)
{
int l;
break;
default:
- if (key < 32 || key > 127)
+ if (ascii < 32 || ascii > 126)
break;
if (lanConfig_cursor == 2)
if (l < 21)
{
lanConfig_joinname[l+1] = 0;
- lanConfig_joinname[l] = key;
+ lanConfig_joinname[l] = ascii;
}
}
- if (key < '0' || key > '9')
+ if (ascii < '0' || ascii > '9')
break;
if (lanConfig_cursor == 0)
{
if (l < 5)
{
lanConfig_portname[l+1] = 0;
- lanConfig_portname[l] = key;
+ lanConfig_portname[l] = ascii;
}
}
}
}
}
-void M_GameOptions_Key (int key)
+void M_GameOptions_Key (int key, char ascii)
{
gamelevels_t *g;
int l;
break;
default:
- if (key < 32 || key > 127)
+ if (ascii < 32 || ascii > 126)
break;
if (gameoptions_cursor == 8)
{
if (l < 37)
{
memcpy(hostnamebuf, hostname.string, l);
- hostnamebuf[l] = key;
+ hostnamebuf[l] = ascii;
hostnamebuf[l+1] = 0;
Cvar_Set("hostname", hostnamebuf);
}
}
-void M_ServerList_Key(int k)
+void M_ServerList_Key(int k, char ascii)
{
switch (k)
{
//=============================================================================
/* Menu Subsystem */
-void M_Keydown(int key);
+void M_Keydown(int key, char ascii);
void M_Draw(void);
void M_ToggleMenu_f(void);
void M_Shutdown(void);
}
-void M_Keydown (int key)
+void M_Keydown (int key, char ascii)
{
switch (m_state)
{
return;
case m_main:
- M_Main_Key (key);
+ M_Main_Key (key, ascii);
return;
case m_demo:
- M_Demo_Key (key);
+ M_Demo_Key (key, ascii);
return;
case m_singleplayer:
- M_SinglePlayer_Key (key);
+ M_SinglePlayer_Key (key, ascii);
return;
case m_load:
- M_Load_Key (key);
+ M_Load_Key (key, ascii);
return;
case m_save:
- M_Save_Key (key);
+ M_Save_Key (key, ascii);
return;
case m_multiplayer:
- M_MultiPlayer_Key (key);
+ M_MultiPlayer_Key (key, ascii);
return;
case m_setup:
- M_Setup_Key (key);
+ M_Setup_Key (key, ascii);
return;
case m_options:
- M_Options_Key (key);
+ M_Options_Key (key, ascii);
return;
case m_options_effects:
- M_Options_Effects_Key (key);
+ M_Options_Effects_Key (key, ascii);
return;
case m_options_colorcontrol:
- M_Options_ColorControl_Key (key);
+ M_Options_ColorControl_Key (key, ascii);
return;
case m_keys:
- M_Keys_Key (key);
+ M_Keys_Key (key, ascii);
return;
case m_video:
- M_Video_Key (key);
+ M_Video_Key (key, ascii);
return;
case m_help:
- M_Help_Key (key);
+ M_Help_Key (key, ascii);
return;
case m_quit:
- M_Quit_Key (key);
+ M_Quit_Key (key, ascii);
return;
case m_lanconfig:
- M_LanConfig_Key (key);
+ M_LanConfig_Key (key, ascii);
return;
case m_gameoptions:
- M_GameOptions_Key (key);
+ M_GameOptions_Key (key, ascii);
return;
case m_slist:
- M_ServerList_Key (key);
+ M_ServerList_Key (key, ascii);
return;
}
}
MR_SetRouting (TRUE);
}
-void MP_Keydown (int key)
+void MP_Keydown (int key, char ascii)
{
PRVM_Begin;
PRVM_SetProg(PRVM_MENUPROG);
// pass key
prog->globals[OFS_PARM0] = (float) key;
+ prog->globals[OFS_PARM1] = (float) ascii;
PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key) required\n");
PRVM_End;
//
void MR_Init (void);
void MR_Restart (void);
-void (*MR_Keydown) (int key);
+void (*MR_Keydown) (int key, char ascii);
void (*MR_Draw) (void);
void (*MR_ToggleMenu_f) (void);
void (*MR_Shutdown) (void);
/*-----------------------------------------------------------------------*/
-static int XLateKey(XKeyEvent *ev)
+static int XLateKey(XKeyEvent *ev, char *ascii)
{
int key = 0;
char buf[64];
keysym = XLookupKeysym (ev, 0);
XLookupString(ev, buf, sizeof buf, &shifted, 0);
+ *ascii = buf[0];
switch(keysym)
{
case XK_KP_Subtract: key = K_KP_MINUS; break;
case XK_KP_Divide: key = K_KP_SLASH; break;
-#if 0
- case 0x021: key = '1';break;/* [!] */
- case 0x040: key = '2';break;/* [@] */
- case 0x023: key = '3';break;/* [#] */
- case 0x024: key = '4';break;/* [$] */
- case 0x025: key = '5';break;/* [%] */
- case 0x05e: key = '6';break;/* [^] */
- case 0x026: key = '7';break;/* [&] */
- case 0x02a: key = '8';break;/* [*] */
- case 0x028: key = '9';;break;/* [(] */
- case 0x029: key = '0';break;/* [)] */
- case 0x05f: key = '-';break;/* [_] */
- case 0x02b: key = '=';break;/* [+] */
- case 0x07c: key = '\'';break;/* [|] */
- case 0x07d: key = '[';break;/* [}] */
- case 0x07b: key = ']';break;/* [{] */
- case 0x022: key = '\'';break;/* ["] */
- case 0x03a: key = ';';break;/* [:] */
- case 0x03f: key = '/';break;/* [?] */
- case 0x03e: key = '.';break;/* [>] */
- case 0x03c: key = ',';break;/* [<] */
-#endif
-
default:
- key = buf[0];
- if (key >= 'A' && key <= 'Z')
- key = key - 'A' + 'a';
break;
}
static void HandleEvents(void)
{
XEvent event;
+ int key;
+ char ascii;
qboolean dowarp = false;
if (!vidx11_display)
{
case KeyPress:
// key pressed
- Key_Event(XLateKey(&event.xkey), true);
+ key = XLateKey (&event.xkey, &ascii);
+ Key_Event(key, ascii, true);
break;
case KeyRelease:
// key released
- Key_Event(XLateKey(&event.xkey), false);
+ key = XLateKey (&event.xkey, &ascii);
+ Key_Event(key, ascii, false);
break;
case MotionNotify:
switch(event.xbutton.button)
{
case 1:
- Key_Event(K_MOUSE1, true);
+ Key_Event(K_MOUSE1, 0, true);
break;
case 2:
- Key_Event(K_MOUSE3, true);
+ Key_Event(K_MOUSE3, 0, true);
break;
case 3:
- Key_Event(K_MOUSE2, true);
+ Key_Event(K_MOUSE2, 0, true);
break;
case 4:
- Key_Event(K_MWHEELUP, true);
+ Key_Event(K_MWHEELUP, 0, true);
break;
case 5:
- Key_Event(K_MWHEELDOWN, true);
+ Key_Event(K_MWHEELDOWN, 0, true);
break;
case 6:
- Key_Event(K_MOUSE4, true);
+ Key_Event(K_MOUSE4, 0, true);
break;
case 7:
- Key_Event(K_MOUSE5, true);
+ Key_Event(K_MOUSE5, 0, true);
break;
case 8:
- Key_Event(K_MOUSE6, true);
+ Key_Event(K_MOUSE6, 0, true);
break;
case 9:
- Key_Event(K_MOUSE7, true);
+ Key_Event(K_MOUSE7, 0, true);
break;
case 10:
- Key_Event(K_MOUSE8, true);
+ Key_Event(K_MOUSE8, 0, true);
break;
case 11:
- Key_Event(K_MOUSE9, true);
+ Key_Event(K_MOUSE9, 0, true);
break;
case 12:
- Key_Event(K_MOUSE10, true);
+ Key_Event(K_MOUSE10, 0, true);
break;
default:
Con_Printf("HandleEvents: ButtonPress gave value %d, 1-12 expected\n", event.xbutton.button);
switch(event.xbutton.button)
{
case 1:
- Key_Event(K_MOUSE1, false);
+ Key_Event(K_MOUSE1, 0, false);
break;
case 2:
- Key_Event(K_MOUSE3, false);
+ Key_Event(K_MOUSE3, 0, false);
break;
case 3:
- Key_Event(K_MOUSE2, false);
+ Key_Event(K_MOUSE2, 0, false);
break;
case 4:
- Key_Event(K_MWHEELUP, false);
+ Key_Event(K_MWHEELUP, 0, false);
break;
case 5:
- Key_Event(K_MWHEELDOWN, false);
+ Key_Event(K_MWHEELDOWN, 0, false);
break;
case 6:
- Key_Event(K_MOUSE4, false);
+ Key_Event(K_MOUSE4, 0, false);
break;
case 7:
- Key_Event(K_MOUSE5, false);
+ Key_Event(K_MOUSE5, 0, false);
break;
case 8:
- Key_Event(K_MOUSE6, false);
+ Key_Event(K_MOUSE6, 0, false);
break;
case 9:
- Key_Event(K_MOUSE7, false);
+ Key_Event(K_MOUSE7, 0, false);
break;
case 10:
- Key_Event(K_MOUSE8, false);
+ Key_Event(K_MOUSE8, 0, false);
break;
case 11:
- Key_Event(K_MOUSE9, false);
+ Key_Event(K_MOUSE9, 0, false);
break;
case 12:
- Key_Event(K_MOUSE10, false);
+ Key_Event(K_MOUSE10, 0, false);
break;
default:
Con_Printf("HandleEvents: ButtonRelease gave value %d, 1-12 expected\n", event.xbutton.button);
// send an up event for each key, to make sure the server clears them all
for (i=0 ; i<256 ; i++)
{
- Key_Event (i, false);
+ Key_Event (i, 0, false);
}
Key_ClearStates ();
// Event.
case WM_MOUSEWHEEL:
if ((short) HIWORD(wParam) > 0) {
- Key_Event(K_MWHEELUP, true);
- Key_Event(K_MWHEELUP, false);
+ Key_Event(K_MWHEELUP, 0, true);
+ Key_Event(K_MWHEELUP, 0, false);
} else {
- Key_Event(K_MWHEELDOWN, true);
- Key_Event(K_MWHEELDOWN, false);
+ Key_Event(K_MWHEELDOWN, 0, true);
+ Key_Event(K_MWHEELDOWN, 0, false);
}
break;
if ( (mstate & (1<<i)) &&
!(mouse_oldbuttonstate & (1<<i)) )
{
- Key_Event (K_MOUSE1 + i, true);
+ Key_Event (K_MOUSE1 + i, 0, true);
}
if ( !(mstate & (1<<i)) &&
(mouse_oldbuttonstate & (1<<i)) )
{
- Key_Event (K_MOUSE1 + i, false);
+ Key_Event (K_MOUSE1 + i, 0, false);
}
}
if ( (mstate_di & (1<<i)) &&
!(mouse_oldbuttonstate & (1<<i)) )
{
- Key_Event (K_MOUSE1 + i, true);
+ Key_Event (K_MOUSE1 + i, 0, true);
}
if ( !(mstate_di & (1<<i)) &&
(mouse_oldbuttonstate & (1<<i)) )
{
- Key_Event (K_MOUSE1 + i, false);
+ Key_Event (K_MOUSE1 + i, 0, false);
}
}
if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
{
key_index = (i < 4) ? K_JOY1 : K_AUX1;
- Key_Event (key_index + i, true);
+ Key_Event (key_index + i, 0, true);
}
if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
{
key_index = (i < 4) ? K_JOY1 : K_AUX1;
- Key_Event (key_index + i, false);
+ Key_Event (key_index + i, 0, false);
}
}
joy_oldbuttonstate = buttonstate;
{
if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
{
- Key_Event (K_AUX29 + i, true);
+ Key_Event (K_AUX29 + i, 0, true);
}
if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
{
- Key_Event (K_AUX29 + i, false);
+ Key_Event (K_AUX29 + i, 0, false);
}
}
joy_oldpovstate = povstate;