/*  Takes keys from the keyboard and inputs them to the console
    If the event was not handled (i.e. WM events or unknown ctrl-shift
    sequences) the function returns the event for further processing. */
SDL_Event *CON_Events(SDL_Event * event)
{
    if (Topmost == NULL)
        return event;
    if (!CON_isVisible(Topmost))
        return event;

    if (event->type == SDL_KEYDOWN) {
        if (event->key.keysym.mod & KMOD_CTRL) {
            /* CTRL pressed */
            /* kps - please modify this to work like in talk.c */
            switch (event->key.keysym.sym) {
            case SDLK_a:
                Cursor_Home(Topmost);
                break;
            case SDLK_b:
                Cursor_Left(Topmost);
                break;
            case SDLK_f:
                Cursor_Right(Topmost);
                break;
            case SDLK_e:
                Cursor_End(Topmost);
                break;
            /*
             * kps - Ctrl-k should really just clear from current
             * cursor position to end of line.
             */
            case SDLK_k:
            case SDLK_u:
                Clear_Command(Topmost);
                break;
            case SDLK_l:
                Clear_History(Topmost);
                CON_UpdateConsole(Topmost);
                break;
            default:
                return event;
            }
#if 0
        } else if (event->key.keysym.mod & KMOD_ALT) {
            /* the console does not handle ALT combinations! */
            return event;
#endif
        } else {
            switch (event->key.keysym.sym) {
            case SDLK_HOME:
                if (event->key.keysym.mod & KMOD_SHIFT) {
                    Topmost->ConsoleScrollBack = Topmost->LineBuffer - 1;
                    CON_UpdateConsole(Topmost);
                } else {
                    Cursor_Home(Topmost);
                }
                break;
            case SDLK_END:
                if (event->key.keysym.mod & KMOD_SHIFT) {
                    Topmost->ConsoleScrollBack = 0;
                    CON_UpdateConsole(Topmost);
                } else {
                    Cursor_End(Topmost);
                }
                break;
            case SDLK_PAGEUP:
                Topmost->ConsoleScrollBack += CON_LINE_SCROLL;
                if (Topmost->ConsoleScrollBack > Topmost->LineBuffer - 1)
                    Topmost->ConsoleScrollBack = Topmost->LineBuffer - 1;

                CON_UpdateConsole(Topmost);
                break;
            case SDLK_PAGEDOWN:
                Topmost->ConsoleScrollBack -= CON_LINE_SCROLL;
                if (Topmost->ConsoleScrollBack < 0)
                    Topmost->ConsoleScrollBack = 0;
                CON_UpdateConsole(Topmost);
                break;
            case SDLK_UP:
                Command_Up(Topmost);
                break;
            case SDLK_DOWN:
                Command_Down(Topmost);
                break;
            case SDLK_LEFT:
                Cursor_Left(Topmost);
                break;
            case SDLK_RIGHT:
                Cursor_Right(Topmost);
                break;
            case SDLK_BACKSPACE:
                Cursor_BSpace(Topmost);
                break;
            case SDLK_DELETE:
                Cursor_Del(Topmost);
                break;
            case SDLK_INSERT:
                Topmost->InsMode = 1 - Topmost->InsMode;
                break;
            case SDLK_TAB:
                CON_TabCompletion(Topmost);
                break;
            case SDLK_RETURN:
                if (strlen(Topmost->Command) > 0) {
                    CON_NewLineCommand(Topmost);

                    /* copy the input into the past commands strings */
                    strcpy(Topmost->CommandLines[0], Topmost->Command);

                    /* display the command including the prompt */
                    CON_Out(Topmost, "%s%s", Topmost->Prompt,
                            Topmost->Command);

                    CON_Execute(Topmost, Topmost->Command);
                    /* printf("Command: %s\n", Topmost->Command); */

                    Clear_Command(Topmost);
                    Topmost->CommandScrollBack = -1;
                }
                else
                    /* deactivate Console if return is pressed on empty line */

                    /* was: CON_Hide(Topmost); */
                    Talk_set_state(false);
                break;
            case SDLK_ESCAPE:
                if (strlen(Topmost->Command) > 0) {
                    CON_NewLineCommand(Topmost);

                    /* copy the input into the past commands strings */
                    strcpy(Topmost->CommandLines[0], Topmost->Command);

                    Clear_Command(Topmost);
                    Topmost->CommandScrollBack = -1;
                }
                /* deactivate Console */

                /*was: CON_Hide(Topmost);*/
                Talk_set_state(false);

                return NULL;
            default:
                if (Topmost->InsMode)
                    Cursor_Add(Topmost, event);
                else {
                    Cursor_Add(Topmost, event);
                    Cursor_Del(Topmost);
                }
            }
        }
        return NULL;
    }
    return event;
}
Beispiel #2
0
/*  Takes keys from the keyboard and inputs them to the console
    If the event was not handled (i.e. WM events or unknown ctrl-shift
    sequences) the function returns the event for further processing. */
SDL_Event* CON_Events(SDL_Event *event) {
    if(Topmost == NULL)
        return event;
    if(!CON_isVisible(Topmost))
        return event;

    if(event->type == SDL_KEYDOWN) {
        if(event->key.keysym.mod & KMOD_CTRL) {
            /* CTRL pressed */
            switch(event->key.keysym.sym) {
            case SDLK_a:
                Cursor_Home(Topmost);
                break;
            case SDLK_e:
                Cursor_End(Topmost);
                break;
            case SDLK_c:
                Clear_Command(Topmost);
                break;
            case SDLK_l:
                Clear_History(Topmost);
                CON_UpdateConsole(Topmost);
                break;
            default:
                return event;
            }
        } else if(event->key.keysym.mod & KMOD_ALT) {
            /* the console does not handle ALT combinations! */
            return event;
        } else {
            /* first of all, check if the console hide key was pressed */
            if(event->key.keysym.sym == Topmost->HideKey) {
                CON_Hide(Topmost);
                return NULL;
            }
            switch (event->key.keysym.sym) {
            case SDLK_HOME:
                if(event->key.keysym.mod & KMOD_SHIFT) {
                    Topmost->ConsoleScrollBack = Topmost->LineBuffer-1;
                    CON_UpdateConsole(Topmost);
                } else {
                    Cursor_Home(Topmost);
                }
                break;
            case SDLK_END:
                if(event->key.keysym.mod & KMOD_SHIFT) {
                    Topmost->ConsoleScrollBack = 0;
                    CON_UpdateConsole(Topmost);
                } else {
                    Cursor_End(Topmost);
                }
                break;
            case SDLK_PAGEUP:
                Topmost->ConsoleScrollBack += CON_LINE_SCROLL;
                if(Topmost->ConsoleScrollBack > Topmost->LineBuffer-1)
                    Topmost->ConsoleScrollBack = Topmost->LineBuffer-1;

                CON_UpdateConsole(Topmost);
                break;
            case SDLK_PAGEDOWN:
                Topmost->ConsoleScrollBack -= CON_LINE_SCROLL;
                if(Topmost->ConsoleScrollBack < 0)
                    Topmost->ConsoleScrollBack = 0;
                CON_UpdateConsole(Topmost);
                break;
            case SDLK_UP:
                Command_Up(Topmost);
                break;
            case SDLK_DOWN:
                Command_Down(Topmost);
                break;
            case SDLK_LEFT:
                Cursor_Left(Topmost);
                break;
            case SDLK_RIGHT:
                Cursor_Right(Topmost);
                break;
            case SDLK_BACKSPACE:
                Cursor_BSpace(Topmost);
                break;
            case SDLK_DELETE:
                Cursor_Del(Topmost);
                break;
            case SDLK_INSERT:
                Topmost->InsMode = 1-Topmost->InsMode;
                break;
            case SDLK_TAB:
                CON_TabCompletion(Topmost);
                break;
            case SDLK_RETURN:
                if(strlen(Topmost->Command) > 0) {
                    CON_NewLineCommand(Topmost);

                    /* copy the input into the past commands strings */
                    strcpy(Topmost->CommandLines[0], Topmost->Command);

                    /* display the command including the prompt */
                    CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command);

                    CON_Execute(Topmost, Topmost->Command);
                    /* printf("Command: %s\n", Topmost->Command); */

                    Clear_Command(Topmost);
                    Topmost->CommandScrollBack = -1;
                }
                break;
            case SDLK_ESCAPE:
                /* deactivate Console */
                CON_Hide(Topmost);
                return NULL;
            default:
                if(Topmost->InsMode)
                    Cursor_Add(Topmost, event);
                else {
                    Cursor_Add(Topmost, event);
                    Cursor_Del(Topmost);
                }
            }
        }
        return NULL;
    }
    return event;
}
Beispiel #3
0
/*  Takes keys from the keyboard and inputs them to the console
    If the event was not handled (i.e. WM events or unknown ctrl-shift 
    sequences) the function returns the event for further processing. */
int CON_Events(int event)
{
	if(Topmost == NULL)
		return event;
	if(!CON_isVisible(Topmost))
		return event;

	if(event & KEY_CTRLED)
	{
		//CTRL pressed
		switch(event & ~KEY_CTRLED)
		{
		case KEY_A:
			Cursor_Home(Topmost);
			break;
		case KEY_E:
			Cursor_End(Topmost);
			break;
		case KEY_C:
			Clear_Command(Topmost);
			break;
		case KEY_L:
			Clear_History(Topmost);
			CON_UpdateConsole(Topmost);
			break;
		default:
			return event;
		}
	}
	else if(event & KEY_ALTED)
	{
		//the console does not handle ALT combinations!
		return event;
	}
	else
	{
		//first of all, check if the console hide key was pressed
		if(event == Topmost->HideKey)
		{
			CON_Hide(Topmost);
			return 0;
		}
		switch (event & 0xff)
		{
		case KEY_LSHIFT:
		case KEY_RSHIFT:
			return event;
		case KEY_HOME:
			if(event & KEY_SHIFTED)
			{
				Topmost->ConsoleScrollBack = Topmost->LineBuffer-1;
				CON_UpdateConsole(Topmost);
			} else {
				Cursor_Home(Topmost);
			}
			break;
		case KEY_END:
			if(event & KEY_SHIFTED)
			{
				Topmost->ConsoleScrollBack = 0;
				CON_UpdateConsole(Topmost);
			} else {
				Cursor_End(Topmost);
			}
			break;
		case KEY_PAGEUP:
			Topmost->ConsoleScrollBack += CON_LINE_SCROLL;
			if(Topmost->ConsoleScrollBack > Topmost->LineBuffer-1)
				Topmost->ConsoleScrollBack = Topmost->LineBuffer-1;

			CON_UpdateConsole(Topmost);
			break;
		case KEY_PAGEDOWN:
			Topmost->ConsoleScrollBack -= CON_LINE_SCROLL;
			if(Topmost->ConsoleScrollBack < 0)
				Topmost->ConsoleScrollBack = 0;
			CON_UpdateConsole(Topmost);
			break;
		case KEY_UP:
			Command_Up(Topmost);
			break;
		case KEY_DOWN:
			Command_Down(Topmost);
			break;
		case KEY_LEFT:
			Cursor_Left(Topmost);
			break;
		case KEY_RIGHT:
			Cursor_Right(Topmost);
			break;
		case KEY_BACKSP:
			Cursor_BSpace(Topmost);
			break;
		case KEY_DELETE:
			Cursor_Del(Topmost);
			break;
		case KEY_INSERT:
			Topmost->InsMode = 1-Topmost->InsMode;
			break;
		case KEY_TAB:
			CON_TabCompletion(Topmost);
			break;
		case KEY_ENTER:
			if(strlen(Topmost->Command) > 0) {
				CON_NewLineCommand(Topmost);

				// copy the input into the past commands strings
				strcpy(Topmost->CommandLines[0], Topmost->Command);

				// display the command including the prompt
				CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command);
				CON_UpdateConsole(Topmost);

				CON_Execute(Topmost, Topmost->Command);
				//printf("Command: %s\n", Topmost->Command);

				Clear_Command(Topmost);
				Topmost->CommandScrollBack = -1;
			}
			break;
		case KEY_ESC:
			//deactivate Console
			if (event & KEY_SHIFTED) {
				CON_Hide(Topmost);
				return 0;
				}
			break;
		default:
			if(Topmost->InsMode)
				Cursor_Add(Topmost, event);
			else {
				Cursor_Add(Topmost, event);
				Cursor_Del(Topmost);
			}
		}
	}
	return 0;
}