Source/ThunderBeast/QuakeToonProto1/client/keys.c
void Key_Event (int key, qboolean down, unsigned time)
{
	char	*kb;
	char	cmd[1024];

	// hack for modal presses
	if (key_waiting == -1)
	{
		if (down)
			key_waiting = key;
		return;
	}

	// update auto-repeat status
	if (down)
	{
		key_repeats[key]++;
		if (key != K_BACKSPACE 
			&& key != K_PAUSE 
			&& key != K_PGUP 
			&& key != K_KP_PGUP 
			&& key != K_PGDN
			&& key != K_KP_PGDN
			&& key_repeats[key] > 1)
			return;	// ignore most autorepeats
			
		if (key >= 200 && !keybindings[key])
			Com_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) );
	}
	else
	{
		key_repeats[key] = 0;
	}

	if (key == K_SHIFT)
		shift_down = down;

	// console key is hardcoded, so the user can never unbind it
	if (key == '`' || key == '~')
	{
		if (!down)
			return;
		Con_ToggleConsole_f ();
		return;
	}

	// any key during the attract mode will bring up the menu
	if (cl.attractloop && cls.key_dest != key_menu &&
		!(key >= K_F1 && key <= K_F12))
		key = K_ESCAPE;

	// menu key is hardcoded, so the user can never unbind it
	if (key == K_ESCAPE)
	{
		if (!down)
			return;

		if (cl.frame.playerstate.stats[STAT_LAYOUTS] && cls.key_dest == key_game)
		{	// put away help computer / inventory
			Cbuf_AddText ("cmd putaway\n");
			return;
		}
		switch (cls.key_dest)
		{
		case key_message:
			Key_Message (key);
			break;
		case key_menu:
			M_Keydown (key);
			break;
		case key_game:
		case key_console:
			M_Menu_Main_f ();
			break;
		default:
			Com_Error (ERR_FATAL, "Bad cls.key_dest");
		}
		return;
	}

	// track if any key is down for BUTTON_ANY
	keydown[key] = down;
	if (down)
	{
		if (key_repeats[key] == 1)
			anykeydown++;
	}
	else
	{
		anykeydown--;
		if (anykeydown < 0)
			anykeydown = 0;
	}

//
// 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];
		if (kb && kb[0] == '+')
		{
			Com_sprintf (cmd, sizeof(cmd), "-%s %i %i\n", kb+1, key, time);
			Cbuf_AddText (cmd);
		}
		if (keyshift[key] != key)
		{
			kb = keybindings[keyshift[key]];
			if (kb && kb[0] == '+')
			{
				Com_sprintf (cmd, sizeof(cmd), "-%s %i %i\n", kb+1, key, time);
				Cbuf_AddText (cmd);
			}
		}
		return;
	}

//
// if not a consolekey, send to the interpreter no matter what mode is
//
	if ( (cls.key_dest == key_menu && menubound[key])
	|| (cls.key_dest == key_console && !consolekeys[key])
	|| (cls.key_dest == key_game && ( cls.state == ca_active || !consolekeys[key] ) ) )
	{
		kb = keybindings[key];
		if (kb)
		{
			if (kb[0] == '+')
			{	// button commands add keynum and time as a parm
				Com_sprintf (cmd, sizeof(cmd), "%s %i %i\n", kb, key, time);
				Cbuf_AddText (cmd);
			}
			else
			{
				Cbuf_AddText (kb);
				Cbuf_AddText ("\n");
			}
		}
		return;
	}

	if (!down)
		return;		// other systems only care about key down events

	if (shift_down)
		key = keyshift[key];

	switch (cls.key_dest)
	{
	case key_message:
		Key_Message (key);
		break;
	case key_menu:
		M_Keydown (key);
		break;

	case key_game:
	case key_console:
		Key_Console (key);
		break;
	default:
		Com_Error (ERR_FATAL, "Bad cls.key_dest");
	}
}
/*
===================
Key_Event

Called by the system between frames for both key up and key down events
Should NOT be called during an interrupt!
===================
*/
Key_Event
Called by the system between frames for both key up and key down events
Should NOT be called during an interrupt!
Key_Event 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, unsigned time)
{
	char	*kb;
	char	cmd[1024];
	if (key_waiting == -1)
	{
		if (down)
			key_waiting = key;
		return;
	}
	if (down)
	{
		key_repeats[key]++;
		if (key != K_BACKSPACE 
			&& key != K_PAUSE 
			&& key != K_PGUP 
			&& key != K_KP_PGUP 
			&& key != K_PGDN
			&& key != K_KP_PGDN
			&& key_repeats[key] > 1)
			return;	
		if (key >= 200 && !keybindings[key])
			Com_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) );
	}
	else
	{
		key_repeats[key] = 0;
	}
	if (key == K_SHIFT)
		shift_down = down;
	if (key == '`' || key == '~')
	{
		if (!down)
			return;
		Con_ToggleConsole_f ();
		return;
	}
	if (cl.attractloop && cls.key_dest != key_menu &&
		!(key >= K_F1 && key <= K_F12))
		key = K_ESCAPE;
	if (key == K_ESCAPE)
	{
		if (!down)
			return;
		if (cl.frame.playerstate.stats[STAT_LAYOUTS] && cls.key_dest == key_game)
		{	
			Cbuf_AddText ("cmd putaway\n");
			return;
		}
		switch (cls.key_dest)
		{
		case key_message:
			Key_Message (key);
			break;
		case key_menu:
			M_Keydown (key);
			break;
		case key_game:
		case key_console:
			M_Menu_Main_f ();
			break;
		default:
			Com_Error (ERR_FATAL, "Bad cls.key_dest");
		}
		return;
	}
	keydown[key] = down;
	if (down)
	{
		if (key_repeats[key] == 1)
			anykeydown++;
	}
	else
	{
		anykeydown--;
		if (anykeydown < 0)
			anykeydown = 0;
	}
 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];
		if (kb && kb[0] == '+')
		{
			Com_sprintf (cmd, sizeof(cmd), "-%s %i %i\n", kb+1, key, time);
			Cbuf_AddText (cmd);
		}
		if (keyshift[key] != key)
		{
			kb = keybindings[keyshift[key]];
			if (kb && kb[0] == '+')
			{
				Com_sprintf (cmd, sizeof(cmd), "-%s %i %i\n", kb+1, key, time);
				Cbuf_AddText (cmd);
			}
		}
		return;
	}
 if not a consolekey, send to the interpreter no matter what mode is
	if ( (cls.key_dest == key_menu && menubound[key])
	|| (cls.key_dest == key_console && !consolekeys[key])
	|| (cls.key_dest == key_game && ( cls.state == ca_active || !consolekeys[key] ) ) )
	{
		kb = keybindings[key];
		if (kb)
		{
			if (kb[0] == '+')
			{	 button commands add keynum and time as a parm
				Com_sprintf (cmd, sizeof(cmd), "%s %i %i\n", kb, key, time);
				Cbuf_AddText (cmd);
			}
			else
			{
				Cbuf_AddText (kb);
				Cbuf_AddText ("\n");
			}
		}
		return;
	}
	if (!down)
		return;		 other systems only care about key down events
	if (shift_down)
		key = keyshift[key];
	switch (cls.key_dest)
	{
	case key_message:
		Key_Message (key);
		break;
	case key_menu:
		M_Keydown (key);
		break;
	case key_game:
	case key_console:
		Key_Console (key);
		break;
	default:
		Com_Error (ERR_FATAL, "Bad cls.key_dest");
	}
}
void Key_Event ( int key , qboolean down , unsigned time ) { char * kb ; char cmd [ 1024 ] ; if ( key_waiting == -1 ) { if ( down ) key_waiting = key ; return ; } if ( down ) { key_repeats [ key ] ++ ; if ( key != K_BACKSPACE && key != K_PAUSE && key != K_PGUP && key != K_KP_PGUP && key != K_PGDN && key != K_KP_PGDN && key_repeats [ key ] > 1 ) return ; if ( key >= 200 && ! keybindings [ key ] ) Com_Printf ( " \n " , Key_KeynumToString ( key ) ) ; } else { key_repeats [ key ] = 0 ; } if ( key == K_SHIFT ) shift_down = down ; if ( key == ' ' || key == ' ' ) { if ( ! down ) return ; Con_ToggleConsole_f ( ) ; return ; } if ( cl . attractloop && cls . key_dest != key_menu && ! ( key >= K_F1 && key <= K_F12 ) ) key = K_ESCAPE ; if ( key == K_ESCAPE ) { if ( ! down ) return ; if ( cl . frame . playerstate . stats [ STAT_LAYOUTS ] && cls . key_dest == key_game ) { Cbuf_AddText ( " \n " ) ; return ; } switch ( cls . key_dest ) { case key_message : Key_Message ( key ) ; break ; case key_menu : M_Keydown ( key ) ; break ; case key_game : case key_console : M_Menu_Main_f ( ) ; break ; default : Com_Error ( ERR_FATAL , " " ) ; } return ; } keydown [ key ] = down ; if ( down ) { if ( key_repeats [ key ] == 1 ) anykeydown ++ ; } else { anykeydown -- ; if ( anykeydown < 0 ) anykeydown = 0 ; } if ( ! down ) { kb = keybindings [ key ] ; if ( kb && kb [ 0 ] == ' ' ) { Com_sprintf ( cmd , sizeof ( cmd ) , " \n " , kb + 1 , key , time ) ; Cbuf_AddText ( cmd ) ; } if ( keyshift [ key ] != key ) { kb = keybindings [ keyshift [ key ] ] ; if ( kb && kb [ 0 ] == ' ' ) { Com_sprintf ( cmd , sizeof ( cmd ) , " \n " , kb + 1 , key , time ) ; Cbuf_AddText ( cmd ) ; } } return ; } if ( ( cls . key_dest == key_menu && menubound [ key ] ) || ( cls . key_dest == key_console && ! consolekeys [ key ] ) || ( cls . key_dest == key_game && ( cls . state == ca_active || ! consolekeys [ key ] ) ) ) { kb = keybindings [ key ] ; if ( kb ) { if ( kb [ 0 ] == ' ' ) { Com_sprintf ( cmd , sizeof ( cmd ) , " \n " , kb , key , time ) ; Cbuf_AddText ( cmd ) ; } else { Cbuf_AddText ( kb ) ; Cbuf_AddText ( " \n " ) ; } } return ; } if ( ! down ) return ; if ( shift_down ) key = keyshift [ key ] ; switch ( cls . key_dest ) { case key_message : Key_Message ( key ) ; break ; case key_menu : M_Keydown ( key ) ; break ; case key_game : case key_console : Key_Console ( key ) ; break ; default : Com_Error ( ERR_FATAL , " " ) ; } }
Key_Event
Called by the system between frames for both key up and key down events
Should NOT be called during an interrupt!
Key_Event Called by the system between frames for both key up and key down events Should NOT be called during an interrupt!
// hack for modal presses // update auto-repeat status // ignore most autorepeats // console key is hardcoded, so the user can never unbind it // any key during the attract mode will bring up the menu // menu key is hardcoded, so the user can never unbind it // put away help computer / inventory // track if any key is down for BUTTON_ANY // // 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 not a consolekey, send to the interpreter no matter what mode is // // button commands add keynum and time as a parm // other systems only care about key down events