Esempio n. 1
0
void checkKeypress(SDL_Event *event, int *mode, int *keyboardMode, int *select){
//    if(*keyboardMode < 0)
//        return;

    if(*mode == JOIN_CUSTOM){
        if(event->key.keysym.sym == SDLK_TAB){                      // Tab will change the window that the user is currently entering text to
            (*select)++;
            if(*select > 2)
                *select = 0;
        }
        else if(event->key.keysym.sym == SDLK_RETURN){
            joinLobby(mode);
        }


        else{
            if(*select == ENTERING_IP){
                if(event->key.keysym.sym == SDLK_BACKSPACE)
                    handleBackspace(ENTERING_IP);
                else
                    addCharToString(ENTERING_IP, MAX_IP_LENGTH, event);
            }

            else if(*select == ENTERING_PORT){
                if(event->key.keysym.sym == SDLK_BACKSPACE)
                    handleBackspace(ENTERING_PORT);
                else
                    addCharToString(ENTERING_PORT, MAX_PORT_LENGTH, event);
            }

            else if(*select == ENTERING_NAME){
                if(event->key.keysym.sym == SDLK_BACKSPACE)
                    handleBackspace(ENTERING_NAME);
                else
                    addCharToString(ENTERING_NAME, MAX_NAME_LENGTH, event);

            }
        }
    }

    if(*mode == LOBBY){ // If we're in a lobby

        if(event->key.keysym.sym == SDLK_BACKSPACE)
            handleBackspace(PLAYER_MESSAGE_WRITE);
        else if(event->key.keysym.sym == SDLK_RETURN){
            SDLNet_TCP_Send(client.TCPSock, textString[PLAYER_MESSAGE_WRITE], STRINGLENGTH);
            clearTextString(PLAYER_MESSAGE_WRITE);
        }
        else
            addCharToString(PLAYER_MESSAGE_WRITE, 40, event);
    }


    return;
}
Esempio n. 2
0
/// gets a user-inputted string until return is entered
/// will use getChar to process characters one by one so that individual
/// key handlers can be created
std::string getInputString(teasafe::TeaSafe &theBfs, std::string const &workingPath)
{
    std::string toReturn("");

    // disable echo and prevent need to press enter for getchar flush
    setupTerminal();

    int cursorPos(0);
    while(1) {
        char c = getchar();
        if((int)c == 10) { // enter
            std::cout<<std::endl;
            break;
        }
        if((int)c == 127 || (int)c == 8) { // delete / backspace

            handleBackspace(cursorPos, toReturn);

        } else if((int)c == 9) { // tab

            handleTabKey(theBfs, workingPath, cursorPos, toReturn);

        } else { // print out char to screen and push into string vector
            std::cout<<c;
            ++cursorPos;
            toReturn.push_back(c);
        }
    }
    return toReturn;
}
Esempio n. 3
0
void Console::keyPressEvent(QKeyEvent* e)
{
	switch(e->key()) {
	case Qt::Key_Enter:
	case Qt::Key_Return:
		if(inPromptBlock())
			handleReturn();
		return;
	case Qt::Key_Left:
	case Qt::Key_Backspace:
		if(handleBackspace()||!inPromptBlock())
			return;
		break;
	case Qt::Key_Down:
	case Qt::Key_Up:
		return;
	case Qt::Key_Right:
	case Qt::Key_Home:
	case Qt::Key_End:
		break;
	default:
		if(!inPromptBlock()) {
			moveCursor(QTextCursor::End,QTextCursor::MoveAnchor);
		}
	}

	QPlainTextEdit::keyPressEvent(e);
}
/*************************************************************************
	Handler for when non-printable keys are typed.
*************************************************************************/
void MultiLineEditbox::onKeyDown(KeyEventArgs& e)
{
	// base class processing
	Window::onKeyDown(e);

	if (hasInputFocus() && !isReadOnly())
	{
		WindowEventArgs args(this);
		switch (e.scancode)
		{
		case Key::LeftShift:
		case Key::RightShift:
			if (getSelectionLength() == 0)
			{
				d_dragAnchorIdx = getCaratIndex();
			}
			break;

		case Key::Backspace:
			handleBackspace();
			break;

		case Key::Delete:
			handleDelete();
			break;

		case Key::Return:
		case Key::NumpadEnter:
			handleNewLine(e.sysKeys);
			break;

		case Key::ArrowLeft:
			if (e.sysKeys & Control)
			{
				handleWordLeft(e.sysKeys);
			}
			else
			{
				handleCharLeft(e.sysKeys);
			}
			break;

		case Key::ArrowRight:
			if (e.sysKeys & Control)
			{
				handleWordRight(e.sysKeys);
			}
			else
			{
				handleCharRight(e.sysKeys);
			}
			break;

		case Key::ArrowUp:
			handleLineUp(e.sysKeys);
			break;

		case Key::ArrowDown:
			handleLineDown(e.sysKeys);
			break;

		case Key::Home:
			if (e.sysKeys & Control)
			{
				handleDocHome(e.sysKeys);
			}
			else
			{
				handleLineHome(e.sysKeys);
			}
			break;

		case Key::End:
			if (e.sysKeys & Control)
			{
				handleDocEnd(e.sysKeys);
			}
			else
			{
				handleLineEnd(e.sysKeys);
			}
			break;

        // default case is now to leave event as (possibly) unhandled.
        default:
            return;
		}

		e.handled = true;
	}

}
Esempio n. 5
0
//----------------------------------------------------------------------------//
void Editbox::onKeyDown(KeyEventArgs& e)
{
    // fire event.
    fireEvent(EventKeyDown, e, Window::EventNamespace);

    if (e.handled == 0 && hasInputFocus())
    {
        if (isReadOnly())
        {
            Window::onKeyDown(e);
            return;
        }

        WindowEventArgs args(this);
        switch (e.scancode)
        {
        case Key::LeftShift:
        case Key::RightShift:
            if (getSelectionLength() == 0)
                d_dragAnchorIdx = d_caretPos;
            break;

        case Key::Backspace:
            handleBackspace();
            break;

        case Key::Delete:
            handleDelete();
            break;

        case Key::Tab:
        case Key::Return:
        case Key::NumpadEnter:
            // Fire 'input accepted' event
            onTextAcceptedEvent(args);
            break;

        case Key::ArrowLeft:
            if (e.sysKeys & Control)
                handleWordLeft(e.sysKeys);
            else
                handleCharLeft(e.sysKeys);
            break;

        case Key::ArrowRight:
            if (e.sysKeys & Control)
                handleWordRight(e.sysKeys);
            else
                handleCharRight(e.sysKeys);
            break;

        case Key::Home:
            handleHome(e.sysKeys);
            break;

        case Key::End:
            handleEnd(e.sysKeys);
            break;

        default:
            Window::onKeyDown(e);
            return;
        }

        ++e.handled;
    }

}