Source/ThunderBeast/QuakeToonProto1/client/keys.c
void Key_Console (int key)
{

	switch ( key )
	{
	case K_KP_SLASH:
		key = '/';
		break;
	case K_KP_MINUS:
		key = '-';
		break;
	case K_KP_PLUS:
		key = '+';
		break;
	case K_KP_HOME:
		key = '7';
		break;
	case K_KP_UPARROW:
		key = '8';
		break;
	case K_KP_PGUP:
		key = '9';
		break;
	case K_KP_LEFTARROW:
		key = '4';
		break;
	case K_KP_5:
		key = '5';
		break;
	case K_KP_RIGHTARROW:
		key = '6';
		break;
	case K_KP_END:
		key = '1';
		break;
	case K_KP_DOWNARROW:
		key = '2';
		break;
	case K_KP_PGDN:
		key = '3';
		break;
	case K_KP_INS:
		key = '0';
		break;
	case K_KP_DEL:
		key = '.';
		break;
	}

	if ( ( toupper( key ) == 'V' && keydown[K_CTRL] ) ||
		 ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keydown[K_SHIFT] ) )
	{
		char *cbd;
		
		if ( ( cbd = Sys_GetClipboardData() ) != 0 )
		{
			int i;

			strtok( cbd, "\n\r\b" );

			i = strlen( cbd );
			if ( i + key_linepos >= MAXCMDLINE)
				i= MAXCMDLINE - key_linepos;

			if ( i > 0 )
			{
				cbd[i]=0;
				strcat( key_lines[edit_line], cbd );
				key_linepos += i;
			}
			free( cbd );
		}

		return;
	}

	if ( key == 'l' ) 
	{
		if ( keydown[K_CTRL] )
		{
			Cbuf_AddText ("clear\n");
			return;
		}
	}

	if ( key == K_ENTER || key == K_KP_ENTER )
	{	// backslash text are commands, else chat
		if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/')
			Cbuf_AddText (key_lines[edit_line]+2);	// skip the >
		else
			Cbuf_AddText (key_lines[edit_line]+1);	// valid command

		Cbuf_AddText ("\n");
		Com_Printf ("%s\n",key_lines[edit_line]);
		edit_line = (edit_line + 1) & 31;
		history_line = edit_line;
		key_lines[edit_line][0] = ']';
		key_linepos = 1;
		if (cls.state == ca_disconnected)
			SCR_UpdateScreen ();	// force an update, because the command
									// may take some time
		return;
	}

	if (key == K_TAB)
	{	// command completion
		CompleteCommand ();
		return;
	}
	
	if ( ( key == K_BACKSPACE ) || ( key == K_LEFTARROW ) || ( key == K_KP_LEFTARROW ) || ( ( key == 'h' ) && ( keydown[K_CTRL] ) ) )
	{
		if (key_linepos > 1)
			key_linepos--;
		return;
	}

	if ( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ||
		 ( ( key == 'p' ) && keydown[K_CTRL] ) )
	{
		do
		{
			history_line = (history_line - 1) & 31;
		} while (history_line != edit_line
				&& !key_lines[history_line][1]);
		if (history_line == edit_line)
			history_line = (edit_line+1)&31;
		strcpy(key_lines[edit_line], key_lines[history_line]);
		key_linepos = strlen(key_lines[edit_line]);
		return;
	}

	if ( ( key == K_DOWNARROW ) || ( key == K_KP_DOWNARROW ) ||
		 ( ( key == 'n' ) && keydown[K_CTRL] ) )
	{
		if (history_line == edit_line) return;
		do
		{
			history_line = (history_line + 1) & 31;
		}
		while (history_line != edit_line
			&& !key_lines[history_line][1]);
		if (history_line == edit_line)
		{
			key_lines[edit_line][0] = ']';
			key_linepos = 1;
		}
		else
		{
			strcpy(key_lines[edit_line], key_lines[history_line]);
			key_linepos = strlen(key_lines[edit_line]);
		}
		return;
	}

	if (key == K_PGUP || key == K_KP_PGUP )
	{
		con.display -= 2;
		return;
	}

	if (key == K_PGDN || key == K_KP_PGDN ) 
	{
		con.display += 2;
		if (con.display > con.current)
			con.display = con.current;
		return;
	}

	if (key == K_HOME || key == K_KP_HOME )
	{
		con.display = con.current - con.totallines + 10;
		return;
	}

	if (key == K_END || key == K_KP_END )
	{
		con.display = con.current;
		return;
	}
	
	if (key < 32 || key > 127)
		return;	// non printable
		
	if (key_linepos < MAXCMDLINE-1)
	{
		key_lines[edit_line][key_linepos] = key;
		key_linepos++;
		key_lines[edit_line][key_linepos] = 0;
	}

}
/*
====================
Key_Console

Interactive line editing and console scrollback
====================
*/
Key_Console
Interactive line editing and console scrollback
Key_Console Interactive line editing and console scrollback
void Key_Console (int key)
{
	switch ( key )
	{
	case K_KP_SLASH:
		key = '/';
		break;
	case K_KP_MINUS:
		key = '-';
		break;
	case K_KP_PLUS:
		key = '+';
		break;
	case K_KP_HOME:
		key = '7';
		break;
	case K_KP_UPARROW:
		key = '8';
		break;
	case K_KP_PGUP:
		key = '9';
		break;
	case K_KP_LEFTARROW:
		key = '4';
		break;
	case K_KP_5:
		key = '5';
		break;
	case K_KP_RIGHTARROW:
		key = '6';
		break;
	case K_KP_END:
		key = '1';
		break;
	case K_KP_DOWNARROW:
		key = '2';
		break;
	case K_KP_PGDN:
		key = '3';
		break;
	case K_KP_INS:
		key = '0';
		break;
	case K_KP_DEL:
		key = '.';
		break;
	}
	if ( ( toupper( key ) == 'V' && keydown[K_CTRL] ) ||
		 ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keydown[K_SHIFT] ) )
	{
		char *cbd;
		if ( ( cbd = Sys_GetClipboardData() ) != 0 )
		{
			int i;
			strtok( cbd, "\n\r\b" );
			i = strlen( cbd );
			if ( i + key_linepos >= MAXCMDLINE)
				i= MAXCMDLINE - key_linepos;
			if ( i > 0 )
			{
				cbd[i]=0;
				strcat( key_lines[edit_line], cbd );
				key_linepos += i;
			}
			free( cbd );
		}
		return;
	}
	if ( key == 'l' ) 
	{
		if ( keydown[K_CTRL] )
		{
			Cbuf_AddText ("clear\n");
			return;
		}
	}
	if ( key == K_ENTER || key == K_KP_ENTER )
	{	
		if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/')
			Cbuf_AddText (key_lines[edit_line]+2);	
		else
			Cbuf_AddText (key_lines[edit_line]+1);	
		Cbuf_AddText ("\n");
		Com_Printf ("%s\n",key_lines[edit_line]);
		edit_line = (edit_line + 1) & 31;
		history_line = edit_line;
		key_lines[edit_line][0] = ']';
		key_linepos = 1;
		if (cls.state == ca_disconnected)
			SCR_UpdateScreen ();	
		return;
	}
	if (key == K_TAB)
	{	
		CompleteCommand ();
		return;
	}
	if ( ( key == K_BACKSPACE ) || ( key == K_LEFTARROW ) || ( key == K_KP_LEFTARROW ) || ( ( key == 'h' ) && ( keydown[K_CTRL] ) ) )
	{
		if (key_linepos > 1)
			key_linepos--;
		return;
	}
	if ( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ||
		 ( ( key == 'p' ) && keydown[K_CTRL] ) )
	{
		do
		{
			history_line = (history_line - 1) & 31;
		} while (history_line != edit_line
				&& !key_lines[history_line][1]);
		if (history_line == edit_line)
			history_line = (edit_line+1)&31;
		strcpy(key_lines[edit_line], key_lines[history_line]);
		key_linepos = strlen(key_lines[edit_line]);
		return;
	}
	if ( ( key == K_DOWNARROW ) || ( key == K_KP_DOWNARROW ) ||
		 ( ( key == 'n' ) && keydown[K_CTRL] ) )
	{
		if (history_line == edit_line) return;
		do
		{
			history_line = (history_line + 1) & 31;
		}
		while (history_line != edit_line
			&& !key_lines[history_line][1]);
		if (history_line == edit_line)
		{
			key_lines[edit_line][0] = ']';
			key_linepos = 1;
		}
		else
		{
			strcpy(key_lines[edit_line], key_lines[history_line]);
			key_linepos = strlen(key_lines[edit_line]);
		}
		return;
	}
	if (key == K_PGUP || key == K_KP_PGUP )
	{
		con.display -= 2;
		return;
	}
	if (key == K_PGDN || key == K_KP_PGDN ) 
	{
		con.display += 2;
		if (con.display > con.current)
			con.display = con.current;
		return;
	}
	if (key == K_HOME || key == K_KP_HOME )
	{
		con.display = con.current - con.totallines + 10;
		return;
	}
	if (key == K_END || key == K_KP_END )
	{
		con.display = con.current;
		return;
	}
	if (key < 32 || key > 127)
		return;	
	if (key_linepos < MAXCMDLINE-1)
	{
		key_lines[edit_line][key_linepos] = key;
		key_linepos++;
		key_lines[edit_line][key_linepos] = 0;
	}
}
void Key_Console ( int key ) { switch ( key ) { case K_KP_SLASH : key = ' ' ; break ; case K_KP_MINUS : key = ' ' ; break ; case K_KP_PLUS : key = ' ' ; break ; case K_KP_HOME : key = ' ' ; break ; case K_KP_UPARROW : key = ' ' ; break ; case K_KP_PGUP : key = ' ' ; break ; case K_KP_LEFTARROW : key = ' ' ; break ; case K_KP_5 : key = ' ' ; break ; case K_KP_RIGHTARROW : key = ' ' ; break ; case K_KP_END : key = ' ' ; break ; case K_KP_DOWNARROW : key = ' ' ; break ; case K_KP_PGDN : key = ' ' ; break ; case K_KP_INS : key = ' ' ; break ; case K_KP_DEL : key = ' ' ; break ; } if ( ( toupper ( key ) == ' ' && keydown [ K_CTRL ] ) || ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keydown [ K_SHIFT ] ) ) { char * cbd ; if ( ( cbd = Sys_GetClipboardData ( ) ) != 0 ) { int i ; strtok ( cbd , " \n \r \b " ) ; i = strlen ( cbd ) ; if ( i + key_linepos >= MAXCMDLINE ) i = MAXCMDLINE - key_linepos ; if ( i > 0 ) { cbd [ i ] = 0 ; strcat ( key_lines [ edit_line ] , cbd ) ; key_linepos += i ; } free ( cbd ) ; } return ; } if ( key == ' ' ) { if ( keydown [ K_CTRL ] ) { Cbuf_AddText ( " \n " ) ; return ; } } if ( key == K_ENTER || key == K_KP_ENTER ) { if ( key_lines [ edit_line ] [ 1 ] == ' \\ ' || key_lines [ edit_line ] [ 1 ] == ' ' ) Cbuf_AddText ( key_lines [ edit_line ] + 2 ) ; else Cbuf_AddText ( key_lines [ edit_line ] + 1 ) ; Cbuf_AddText ( " \n " ) ; Com_Printf ( " \n " , key_lines [ edit_line ] ) ; edit_line = ( edit_line + 1 ) & 31 ; history_line = edit_line ; key_lines [ edit_line ] [ 0 ] = ' ' ; key_linepos = 1 ; if ( cls . state == ca_disconnected ) SCR_UpdateScreen ( ) ; return ; } if ( key == K_TAB ) { CompleteCommand ( ) ; return ; } if ( ( key == K_BACKSPACE ) || ( key == K_LEFTARROW ) || ( key == K_KP_LEFTARROW ) || ( ( key == ' ' ) && ( keydown [ K_CTRL ] ) ) ) { if ( key_linepos > 1 ) key_linepos -- ; return ; } if ( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) || ( ( key == ' ' ) && keydown [ K_CTRL ] ) ) { do { history_line = ( history_line - 1 ) & 31 ; } while ( history_line != edit_line && ! key_lines [ history_line ] [ 1 ] ) ; if ( history_line == edit_line ) history_line = ( edit_line + 1 ) & 31 ; strcpy ( key_lines [ edit_line ] , key_lines [ history_line ] ) ; key_linepos = strlen ( key_lines [ edit_line ] ) ; return ; } if ( ( key == K_DOWNARROW ) || ( key == K_KP_DOWNARROW ) || ( ( key == ' ' ) && keydown [ K_CTRL ] ) ) { if ( history_line == edit_line ) return ; do { history_line = ( history_line + 1 ) & 31 ; } while ( history_line != edit_line && ! key_lines [ history_line ] [ 1 ] ) ; if ( history_line == edit_line ) { key_lines [ edit_line ] [ 0 ] = ' ' ; key_linepos = 1 ; } else { strcpy ( key_lines [ edit_line ] , key_lines [ history_line ] ) ; key_linepos = strlen ( key_lines [ edit_line ] ) ; } return ; } if ( key == K_PGUP || key == K_KP_PGUP ) { con . display -= 2 ; return ; } if ( key == K_PGDN || key == K_KP_PGDN ) { con . display += 2 ; if ( con . display > con . current ) con . display = con . current ; return ; } if ( key == K_HOME || key == K_KP_HOME ) { con . display = con . current - con . totallines + 10 ; return ; } if ( key == K_END || key == K_KP_END ) { con . display = con . current ; return ; } if ( key < 32 || key > 127 ) return ; if ( key_linepos < MAXCMDLINE - 1 ) { key_lines [ edit_line ] [ key_linepos ] = key ; key_linepos ++ ; key_lines [ edit_line ] [ key_linepos ] = 0 ; } }
Key_Console
Interactive line editing and console scrollback
Key_Console Interactive line editing and console scrollback
// backslash text are commands, else chat // skip the > // valid command // force an update, because the command // may take some time // command completion // non printable