* keys.h: renamed KP_* key macros to K_KP_*.

* key.c (Key_ClearStates): Instead of clearing all key's down state
  and repeat count, run KeyEvent(k,false) keys in down state, which
  will already clear those states for them. This also helps getting
  rid of several actions bound to keypad keys. Minor cleanups.
* gl_vidsdl.c (ClearAllStates): Removed code triggering every key
  with a release event, because we just changed Key_ClearStates() to
  do that for the necessary keys.
* in_sdl.c: Minor cleanups. Made K_KP_5 to send '5' when not in game
  mode, regardless of the numlock status. Moved prev_gamekey to top
  level and call SDL_EnableUNICODE() correctly.

git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@686 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2012-06-25 11:20:38 +00:00
parent 798b777233
commit e39b2ca3c8
4 changed files with 121 additions and 164 deletions

View File

@ -824,14 +824,6 @@ ClearAllStates
*/
static void ClearAllStates (void)
{
int i;
// 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_ClearStates ();
IN_ClearStates ();
}

View File

@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h"
#include "SDL.h"
static qboolean prev_gamekey;
#ifdef __APPLE__
/* Mouse acceleration needs to be disabled on OS X */
#define MACOS_X_ACCELERATION_HACK
@ -204,7 +206,8 @@ void IN_Deactivate (qboolean free_cursor)
void IN_Init (void)
{
SDL_EnableUNICODE (0); /* frame updates will change this as key_dest changes */
prev_gamekey = (key_dest == key_game || m_keys_bind_grab);
SDL_EnableUNICODE (!prev_gamekey);
if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)
Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n");
@ -299,15 +302,13 @@ void IN_SendKeyEvents (void)
int sym, state;
int modstate;
qboolean gamekey;
static qboolean prev_gamekey;
gamekey = (key_dest == key_game || m_keys_bind_grab);
if (gamekey != prev_gamekey)
{
SDL_EnableUNICODE(!gamekey);
Key_ClearStates();
prev_gamekey = gamekey;
Key_ClearStates();
SDL_EnableUNICODE(!gamekey);
}
while (SDL_PollEvent(&event))
@ -318,15 +319,8 @@ void IN_SendKeyEvents (void)
if (event.active.state & (SDL_APPINPUTFOCUS|SDL_APPACTIVE))
{
if (event.active.gain)
{
/* Sys_Printf("FOCUS GAIN\n");*/
S_UnblockSound();
}
else
{
/* Sys_Printf("FOCUS LOSS\n");*/
S_BlockSound();
}
else S_BlockSound();
}
break;
@ -337,13 +331,13 @@ void IN_SendKeyEvents (void)
VID_Toggle();
break;
}
else if ((event.key.keysym.sym == SDLK_ESCAPE) &&
if ((event.key.keysym.sym == SDLK_ESCAPE) &&
(event.key.keysym.mod & KMOD_SHIFT))
{
Con_ToggleConsole_f();
break;
}
/* fallthrough */
case SDL_KEYUP:
sym = event.key.keysym.sym;
state = event.key.state;
@ -473,87 +467,87 @@ void IN_SendKeyEvents (void)
break;
case SDLK_NUMLOCK:
if (gamekey)
sym = KP_NUMLOCK;
sym = K_KP_NUMLOCK;
else sym = 0;
break;
case SDLK_KP0:
if (gamekey)
sym = KP_INS;
sym = K_KP_INS;
else sym = (modstate & KMOD_NUM) ? SDLK_0 : K_INS;
break;
case SDLK_KP1:
if (gamekey)
sym = KP_END;
sym = K_KP_END;
else sym = (modstate & KMOD_NUM) ? SDLK_1 : K_END;
break;
case SDLK_KP2:
if (gamekey)
sym = KP_DOWNARROW;
sym = K_KP_DOWNARROW;
else sym = (modstate & KMOD_NUM) ? SDLK_2 : K_DOWNARROW;
break;
case SDLK_KP3:
if (gamekey)
sym = KP_PGDN;
sym = K_KP_PGDN;
else sym = (modstate & KMOD_NUM) ? SDLK_3 : K_PGDN;
break;
case SDLK_KP4:
if (gamekey)
sym = KP_LEFTARROW;
sym = K_KP_LEFTARROW;
else sym = (modstate & KMOD_NUM) ? SDLK_4 : K_LEFTARROW;
break;
case SDLK_KP5:
if (gamekey)
sym = KP_5;
else sym = (modstate & KMOD_NUM) ? SDLK_5 : 0;
sym = K_KP_5;
else sym = SDLK_5;
break;
case SDLK_KP6:
if (gamekey)
sym = KP_RIGHTARROW;
sym = K_KP_RIGHTARROW;
else sym = (modstate & KMOD_NUM) ? SDLK_6 : K_RIGHTARROW;
break;
case SDLK_KP7:
if (gamekey)
sym = KP_HOME;
sym = K_KP_HOME;
else sym = (modstate & KMOD_NUM) ? SDLK_7 : K_HOME;
break;
case SDLK_KP8:
if (gamekey)
sym = KP_UPARROW;
sym = K_KP_UPARROW;
else sym = (modstate & KMOD_NUM) ? SDLK_8 : K_UPARROW;
break;
case SDLK_KP9:
if (gamekey)
sym = KP_PGUP;
sym = K_KP_PGUP;
else sym = (modstate & KMOD_NUM) ? SDLK_9 : K_PGUP;
break;
case SDLK_KP_PERIOD:
if (gamekey)
sym = KP_DEL;
sym = K_KP_DEL;
else sym = (modstate & KMOD_NUM) ? SDLK_PERIOD : K_DEL;
break;
case SDLK_KP_DIVIDE:
if (gamekey)
sym = KP_SLASH;
sym = K_KP_SLASH;
else sym = SDLK_SLASH;
break;
case SDLK_KP_MULTIPLY:
if (gamekey)
sym = KP_STAR;
sym = K_KP_STAR;
else sym = SDLK_ASTERISK;
break;
case SDLK_KP_MINUS:
if (gamekey)
sym = KP_MINUS;
sym = K_KP_MINUS;
else sym = SDLK_MINUS;
break;
case SDLK_KP_PLUS:
if (gamekey)
sym = KP_PLUS;
sym = K_KP_PLUS;
else sym = SDLK_PLUS;
break;
case SDLK_KP_ENTER:
if (gamekey)
sym = KP_ENTER;
sym = K_KP_ENTER;
else sym = SDLK_RETURN;
break;
case SDLK_KP_EQUALS:

View File

@ -19,13 +19,10 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "quakedef.h"
/*
key up events are sent even if in console mode
*/
/* key up events are sent even if in console mode */
#define HISTORY_FILE_NAME "history.txt"
#define CMDLINES 32
@ -76,25 +73,23 @@ keyname_t keynames[] =
{"CTRL", K_CTRL},
{"SHIFT", K_SHIFT},
//johnfitz -- keypad
{"KP_NUMLOCK", KP_NUMLOCK},
{"KP_SLASH", KP_SLASH },
{"KP_STAR", KP_STAR },
{"KP_MINUS", KP_MINUS },
{"KP_HOME", KP_HOME },
{"KP_UPARROW", KP_UPARROW },
{"KP_PGUP", KP_PGUP },
{"KP_PLUS", KP_PLUS },
{"KP_LEFTARROW", KP_LEFTARROW },
{"KP_5", KP_5 },
{"KP_RIGHTARROW", KP_RIGHTARROW },
{"KP_END", KP_END },
{"KP_DOWNARROW", KP_DOWNARROW },
{"KP_PGDN", KP_PGDN },
{"KP_ENTER", KP_ENTER },
{"KP_INS", KP_INS },
{"KP_DEL", KP_DEL },
//johnfitz
// {"KP_NUMLOCK", K_KP_NUMLOCK},
{"KP_SLASH", K_KP_SLASH},
{"KP_STAR", K_KP_STAR},
{"KP_MINUS", K_KP_MINUS},
{"KP_HOME", K_KP_HOME},
{"KP_UPARROW", K_KP_UPARROW},
{"KP_PGUP", K_KP_PGUP},
{"KP_PLUS", K_KP_PLUS},
{"KP_LEFTARROW", K_KP_LEFTARROW},
{"KP_5", K_KP_5},
{"KP_RIGHTARROW", K_KP_RIGHTARROW},
{"KP_END", K_KP_END},
{"KP_DOWNARROW", K_KP_DOWNARROW},
{"KP_PGDN", K_KP_PGDN},
{"KP_ENTER", K_KP_ENTER},
{"KP_INS", K_KP_INS},
{"KP_DEL", K_KP_DEL},
{"F1", K_F1},
{"F2", K_F2},
@ -187,9 +182,9 @@ Interactive line editing and console scrollback
*/
void Key_Console (int key)
{
static char current[MAXCMDLINE] = "";
extern int con_vislines;
extern char key_tabpartial[MAXCMDLINE];
static char current[MAXCMDLINE]="";
switch (key)
{
@ -249,8 +244,10 @@ void Key_Console (int key)
{
line = con_text + (i % con_totallines) * con_linewidth;
for (x = 0; x < con_linewidth; x++)
{
if (line[x] != ' ')
break;
}
if (x != con_linewidth)
break;
}
@ -313,9 +310,8 @@ void Key_Console (int key)
// Needs rewriting as we have persistent history
// if (history_line == 0) return;
if (history_line == edit_line) {
if (history_line == edit_line)
Q_strcpy(current,key_lines[edit_line]);
};
key_tabpartial[0] = 0;
history_line = (history_line - 1) & 31;
@ -509,8 +505,8 @@ FIXME: handle quote special (general escape sequence?)
*/
const char *Key_KeynumToString (int keynum)
{
keyname_t *kn;
static char tinystr[2];
keyname_t *kn;
if (keynum == -1)
return "<KEY NOT FOUND>";
@ -522,8 +518,10 @@ const char *Key_KeynumToString (int keynum)
}
for (kn = keynames; kn->name; kn++)
{
if (keynum == kn->keynum)
return kn->name;
}
return "<UNKNOWN KEYNUM>";
}
@ -536,9 +534,6 @@ Key_SetBinding
*/
void Key_SetBinding (int keynum, const char *binding)
{
char *new_binding;
int l;
if (keynum == -1)
return;
@ -550,11 +545,7 @@ void Key_SetBinding (int keynum, const char *binding)
}
// allocate memory for new binding
l = Q_strlen (binding);
new_binding = (char *) Z_Malloc (l+1);
Q_strcpy (new_binding, binding);
new_binding[l] = 0;
keybindings[keynum] = new_binding;
keybindings[keynum] = Z_Strdup(binding);
}
/*
@ -587,9 +578,11 @@ void Key_Unbindall_f (void)
int i;
for (i = 0; i < 256; i++)
{
if (keybindings[i])
Key_SetBinding (i, "");
}
}
/*
============
@ -602,12 +595,13 @@ void Key_Bindlist_f (void)
count = 0;
for (i = 0; i < 256; i++)
if (keybindings[i])
if (*keybindings[i])
{
if (keybindings[i] && *keybindings[i])
{
Con_SafePrintf (" %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
count++;
}
}
Con_SafePrintf ("%i bindings\n", count);
}
@ -645,7 +639,7 @@ void Key_Bind_f (void)
}
// copy the rest of the command line
cmd[0] = 0; // start out with a null string
cmd[0] = 0;
for (i = 2; i < c; i++)
{
q_strlcat (cmd, Cmd_Argv(i), sizeof(cmd));
@ -668,10 +662,11 @@ void Key_WriteBindings (FILE *f)
int i;
for (i = 0; i < 256; i++)
if (keybindings[i])
if (*keybindings[i])
{
if (keybindings[i] && *keybindings[i])
fprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
}
}
void History_Init (void)
@ -858,9 +853,7 @@ void Key_Event (int key, qboolean down)
key_lastpress = key;
key_count++;
if (key_count <= 0)
{
return; // just catching keys for Con_NotifyBox
}
// update auto-repeat status
if (down)
@ -881,13 +874,10 @@ void Key_Event (int key, qboolean down)
}
autorep0:
if (key == K_SHIFT)
shift_down = down;
//
// handle escape specialy, so the user can never unbind it
//
if (key == K_ESCAPE)
{
if (!down)
@ -910,20 +900,11 @@ autorep0:
return;
}
// johnfitz -- alt-enter to toggle fullscreen. FIXME -- this does NOT work
// But this hack (from sf.net/uhexen2) for SDLFitz works for me. S.A
// *** moved to main.c so that it works properly ***
// if (!down && (key == K_ENTER) && keydown[K_ALT])
// VID_Toggle();
// johnfitz
//
// key up events only generate commands if the game key binding is
// a button command (leading + sign). These will occur even in console mode,
// to keep the character from continuing an action started before a console
// switch. Button commands include the kenum as a parameter, so multiple
// downs can be matched with ups
//
if (!down)
{
kb = keybindings[key];
@ -944,21 +925,17 @@ autorep0:
return;
}
//
// during demo playback, most keys bring up the main menu
//
if (cls.demoplayback && down && consolekeys[key] && key_dest == key_game && key != K_TAB)
{
M_ToggleMenu_f ();
return;
}
//
// if not a consolekey, send to the interpreter no matter what mode is
//
if ( (key_dest == key_menu && menubound[key])
|| (key_dest == key_console && !consolekeys[key])
|| (key_dest == key_game && ( !con_forcedup || !consolekeys[key] ) ) )
if ((key_dest == key_menu && menubound[key]) ||
(key_dest == key_console && !consolekeys[key]) ||
(key_dest == key_game && (!con_forcedup || !consolekeys[key])))
{
kb = keybindings[key];
if (kb)
@ -981,9 +958,7 @@ autorep0:
return; // other systems only care about key down events
if (shift_down)
{
key = keyshift[key];
}
switch (key_dest)
{
@ -1015,8 +990,8 @@ void Key_ClearStates (void)
for (i = 0; i < 256; i++)
{
keydown[i] = false;
key_repeats[i] = 0;
if (keydown[i])
Key_Event (i, false);
}
}

View File

@ -60,25 +60,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define K_HOME 151
#define K_END 152
//johnfitz -- keypad
#define KP_NUMLOCK 153
#define KP_SLASH 154
#define KP_STAR 155
#define KP_MINUS 156
#define KP_HOME 157
#define KP_UPARROW 158
#define KP_PGUP 159
#define KP_PLUS 160
#define KP_LEFTARROW 161
#define KP_5 162
#define KP_RIGHTARROW 163
#define KP_END 164
#define KP_DOWNARROW 165
#define KP_PGDN 166
#define KP_ENTER 167
#define KP_INS 168
#define KP_DEL 169
//johnfitz
#define K_KP_NUMLOCK 153
#define K_KP_SLASH 154
#define K_KP_STAR 155
#define K_KP_MINUS 156
#define K_KP_HOME 157
#define K_KP_UPARROW 158
#define K_KP_PGUP 159
#define K_KP_PLUS 160
#define K_KP_LEFTARROW 161
#define K_KP_5 162
#define K_KP_RIGHTARROW 163
#define K_KP_END 164
#define K_KP_DOWNARROW 165
#define K_KP_PGDN 166
#define K_KP_ENTER 167
#define K_KP_INS 168
#define K_KP_DEL 169
#define K_PAUSE 255
@ -96,11 +94,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define K_JOY2 204
#define K_JOY3 205
#define K_JOY4 206
//
// aux keys are for multi-buttoned joysticks to generate so they can use
// the normal binding process
//
// aux29-32: reserved for the HAT (POV) switch motion
#define K_AUX1 207
#define K_AUX2 208
#define K_AUX3 209