예제 #1
0
void PGE_QuestionBox::processBox(float)
{
    #ifndef __APPLE__
    if(AppSettings.interprocessing)
        qApp->processEvents();
    #endif
    SDL_Event event;
    while ( SDL_PollEvent(&event) )
    {
        PGE_Window::processEvents(event);
        switch(event.type)
        {
            case SDL_QUIT:
                reject();
            break;
            case SDL_KEYDOWN: // If pressed key
                processKeyEvent(event.key.keysym.sym);
            break;
            default:
              break;
        }
    }
    if(_menu.isSelected())
    {
        if(_menu.isAccepted())
            _answer_id = _menu.currentItemI();
        else
            _answer_id = -1;
        _page++; setFade(10, 0.0f, 0.05f);return;
    }
}
bool UIHostComboEditorPrivate::winEvent(MSG *pMsg, long* /* pResult */)
{
    switch (pMsg->message)
    {
        case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
        case WM_KEYUP:
        case WM_SYSKEYUP:
        {
            /* Get key-code: */
            int iKeyCode = UINativeHotKey::distinguishModifierVKey((int)pMsg->wParam, (int)pMsg->lParam);

            /* If this is the first event in a synthetic AltGr = LCtrl+RAlt
             * sequence then swallow it. */
            if (isSyntheticLCtrl(pMsg))
                return true;

            /* Process the key event: */
            return processKeyEvent(iKeyCode, pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN);
        }
        default:
            break;
    }

    return false;
}
bool OpenGLGame::update()
{
	if ( !isActive() )						// 程序激活的么?
	{
		return true;
	}

	if ( isKeyPressed( VK_ESCAPE ) )				// ESC 按下了么?
	{
		return false;				// ESC 发出退出信号
	}

	// 不是退出的时候,刷新屏幕
	drawGLScene();				// 绘制场景
	::SwapBuffers( m_hDC );			// 交换缓存 (双缓存)

	processKeyEvent();

	if ( isKeyPressed( VK_F1 ) )					// F1键按下了么?
	{
		onKeyReleased( VK_F1 );			// 若是,使对应的Key数组中的值为 FALSE
		killGLWindow();					// 销毁当前的窗口
		m_bFullScreen = !m_bFullScreen; // 切换 全屏 / 窗口 模式

		// 重建 OpenGL 窗口
		if ( !createGLWindow() )
		{
			return false;				// 如果窗口未能创建,程序退出
		}
	}

	return true;
}
예제 #4
0
void FormGame::mouseReleaseEvent(QMouseEvent *event)
{
    if(_ui->_le_message->isVisible())
    {
        QWidget::mouseReleaseEvent(event);
        return;
    }
    processKeyEvent(event->button(),false);
}
예제 #5
0
void FormGame::keyReleaseEvent(QKeyEvent *event)
{
    if(_ui->_le_message->isVisible())
    {
        QWidget::keyReleaseEvent(event);
        return;
    }
    if(event->isAutoRepeat())
    {
        event->ignore();
        return;
    }
    processKeyEvent(event->key(),false);
}
예제 #6
0
    //---------------------------------------------------------------------
	bool EventDispatcher::dispatchEvent(InputEvent* e) 
	{
		bool ret = false;
		if (e->isEventBetween(MouseEvent::ME_FIRST_EVENT, MouseEvent::ME_LAST_EVENT))	// i am open to suggestions for a better way to do this
																						// maybe a method e->isEvent(InputEvent::MouseEvent) ??
		{
			MouseEvent* me = static_cast<MouseEvent*> (e);
			ret = processMouseEvent(me);
		}
		else if (e->isEventBetween(KeyEvent::KE_FIRST_EVENT, KeyEvent::KE_LAST_EVENT))
		{
			KeyEvent* ke = static_cast<KeyEvent*> (e);
			ret = processKeyEvent(ke);

		}
		return ret;
	}
bool UIHostComboEditorPrivate::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
{
    /* Ignore key changes unless we're the focus widget: */
    if (!hasFocus())
        return false;

    UInt32 eventKind = ::GetEventKind(inEvent);
    switch (eventKind)
    {
        //case kEventRawKeyDown:
        //case kEventRawKeyUp:
        //case kEventRawKeyRepeat:
        case kEventRawKeyModifiersChanged:
        {
            /* Get modifier mask: */
            UInt32 modifierMask = 0;
            ::GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
                                sizeof(modifierMask), NULL, &modifierMask);
            modifierMask = ::DarwinAdjustModifierMask(modifierMask, pvCocoaEvent);
            UInt32 changed = m_uDarwinKeyModifiers ^ modifierMask;

            if (!changed)
                break;

            /* Convert to keycode: */
            unsigned uKeyCode = ::DarwinModifierMaskToDarwinKeycode(changed);

            if (!uKeyCode || uKeyCode == ~0U)
                return false;

            /* Process the key event: */
            if (processKeyEvent(uKeyCode, changed & modifierMask))
            {
                /* Save the new modifier mask state. */
                m_uDarwinKeyModifiers = modifierMask;
                return true;
            }
            break;
        }
        default:
            break;
    }
    return false;
}
예제 #8
0
bool HelpWindow::eventFilter(QObject *watched, QEvent *event)
{
	// We are filtering mouse event on help content widget's viewport
	if (watched == m_helpContentWidget->viewport()) {
		if (event->type() != QEvent::MouseButtonRelease) {
			return false;
		}
		return processMouseEvent(dynamic_cast<QMouseEvent *>(event));
	}

	// We are filtering mouse event on help content widget
	if (watched == m_helpContentWidget) {
		if (event->type() != QEvent::KeyPress) {
			return false;
		}
		return processKeyEvent(dynamic_cast<QKeyEvent *>(event));
	}

	return false;
}
예제 #9
0
    void TextField::processEvent(Event* event)
    {
        if (!getEnabled()) {
            return;
        }

        switch (event->getType() & 0xFFFF) {
        case Event::IME_CHAR:
        {
            int keycode = (event->getType() >> 16) & 0xFFFF;
            accumulateUtf8(((char)(keycode & 0xFF)));
            break;
        }
        case Event::IME_ENDCOMPOSITION:
        {
            String& stringFromIme = getAccumulateUtf8();
            cursor_ += stringFromIme.length();
            insertStringTail(stringFromIme);
            clearAccumulateUtf8();
            repaint();
            break;
        }
        case Event::IME_BACKSPACE:
        {
            backspace();
            break;
        }
        case KeyEvent::KEY_PRESSED:
        {
            processKeyEvent((KeyEvent*)event);
            break;
        }
        case Event::FOCUS_IN:
        case Event::FOCUS_OUT:
        {
            repaint();
            getParent()->processEvent(&this->focusEvent);
            break;
        }
        }
    }
예제 #10
0
bool UIHostComboEditor::winEvent(MSG *pMsg, long* /* pResult */)
{
    switch (pMsg->message)
    {
        case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
        case WM_KEYUP:
        case WM_SYSKEYUP:
        {
            /* Get key-code: */
            int iKeyCode = UINativeHotKey::distinguishModifierVKey((int)pMsg->wParam, (int)pMsg->lParam);

            /* Process the key event: */
            return processKeyEvent(iKeyCode, pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN);
        }
        default:
            break;
    }

    return false;
}
bool UIHostComboEditorPrivate::x11Event(XEvent *pEvent)
{
    switch (pEvent->type)
    {
        case XKeyPress:
        case XKeyRelease:
        {
            /* Get key-code: */
            XKeyEvent *pKeyEvent = (XKeyEvent*)pEvent;
            KeySym ks = ::XKeycodeToKeysym(pKeyEvent->display, pKeyEvent->keycode, 0);

            int iKeySym = (int)ks;

            /* Process the key event: */
            return processKeyEvent(iKeySym, pEvent->type == XKeyPress);
        }
        default:
            break;
    }

    return false;
}
예제 #12
0
/*! \internal
    Translates the QNX keyboard events to Qt keyboard events
 */
void QWSQnxKeyboardHandler::socketActivated()
{
    _keyboard_packet packet;

    // read one keyboard event
    int bytesRead = QT_READ(keyboardFD, &packet, sizeof(_keyboard_packet));
    if (bytesRead == -1) {
        qErrnoWarning(errno, "QWSQnxKeyboardHandler::socketActivated(): Unable to read data.");
        return;
    }

    // the bytes read must be the size of a keyboard packet
    Q_ASSERT(bytesRead == sizeof(_keyboard_packet));

    if (packet.data.flags & KEY_SYM_VALID_EX)
        packet.data.flags |= KEY_SYM_VALID;
    else if (!(packet.data.flags & (KEY_SYM_VALID | KEY_CAP_VALID)))
        return;

#if 0
    qDebug() << "keyboard got scancode"
             << hex << packet.data.modifiers
             << packet.data.flags
             << packet.data.key_cap
             << packet.data.key_sym
             << packet.data.key_scan;
#endif

    // QNX is nice enough to translate the raw keyboard data into generic format for us.
    // Now we just have to translate it into a format Qt understands.

    // figure out the modifiers that are currently pressed
    Qt::KeyboardModifiers modifiers = Qt::NoModifier;
    if (packet.data.modifiers & KEYMOD_SHIFT)
        modifiers |= Qt::ShiftModifier;
    if (packet.data.modifiers & KEYMOD_CTRL)
        modifiers |= Qt::ControlModifier;
    if (packet.data.modifiers & KEYMOD_ALT)
        modifiers |= Qt::AltModifier;
    if (packet.data.modifiers & KEYMOD_NUM_LOCK)
        modifiers |= Qt::KeypadModifier;
#if 0
    // special case for AltGr
    if (packet.data.modifiers & KEYMOD_ALTGR)
        key = Qt::Key_AltGr;
#endif

    // figure out whether it's a press
    bool isPress = packet.data.flags & KEY_DOWN;
    // figure out whether the key is still pressed and the key event is repeated
    bool isRepeat = packet.data.flags & KEY_REPEAT;

    int key = Qt::Key_unknown;
    int unicode = 0;

    if (((packet.data.flags & KEY_SYM_VALID) && key_sym_displayable(unicode = packet.data.key_sym))
        || ((packet.data.flags & KEY_CAP_VALID) && key_sym_displayable(unicode = packet.data.key_cap))) {
        if (unicode <= 0x0ff) {
            if (unicode >= 'a' && unicode <= 'z')
                key = Qt::Key_A + unicode - 'a';
            else
                key = unicode;
        }
        // Ctrl<something> or Alt<something> is not a displayable character
        if (modifiers & (Qt::ControlModifier | Qt::AltModifier))
            unicode = 0;
    } else {
        unicode = 0;

        unsigned long sym = 0;
        if (packet.data.flags & KEY_SYM_VALID)
            sym = packet.data.key_sym;
        else if (packet.data.flags & KEY_CAP_VALID)
            sym = packet.data.key_cap;

        switch (sym) {
        case KEYCODE_ESCAPE: key = Qt::Key_Escape; unicode = 27; break;
        case KEYCODE_TAB: key = Qt::Key_Tab; unicode = 9; break;
        case KEYCODE_BACK_TAB: key = Qt::Key_Backtab; break;
        case KEYCODE_BACKSPACE: key = Qt::Key_Backspace; unicode = 127; break;
        case KEYCODE_RETURN: key = Qt::Key_Return; break;
        case KEYCODE_KP_ENTER: key = Qt::Key_Enter; break;
        case KEYCODE_INSERT:
        case KEYCODE_KP_INSERT:
            key = Qt::Key_Insert; break;
        case KEYCODE_KP_DELETE:
            if (modifiers & Qt::KeypadModifier) {
                key = Qt::Key_Comma;
                break;
            }
        // fall through
        case KEYCODE_DELETE:
            key = Qt::Key_Delete; break;
        case KEYCODE_PAUSE:
        case KEYCODE_BREAK:
            if (modifiers & (Qt::ControlModifier | Qt::AltModifier))
                return; // sometimes occurs at the middle of a key sequence
            key = Qt::Key_Pause; break;
        case KEYCODE_PRINT:
            if (modifiers & (Qt::ControlModifier | Qt::AltModifier))
                return; // sometimes occurs at the middle of a key sequence
            key = Qt::Key_Print; break;
        case KEYCODE_SYSREQ:
            key = Qt::Key_SysReq; break;
        case KEYCODE_HOME:
        case KEYCODE_KP_HOME:
            key = Qt::Key_Home; break;
        case KEYCODE_END:
        case KEYCODE_KP_END:
            key = Qt::Key_End; break;
        case KEYCODE_LEFT:
        case KEYCODE_KP_LEFT:
            key = Qt::Key_Left; break;
        case KEYCODE_UP:
        case KEYCODE_KP_UP:
            key = Qt::Key_Up; break;
        case KEYCODE_RIGHT:
        case KEYCODE_KP_RIGHT:
            key = Qt::Key_Right; break;
        case KEYCODE_DOWN:
        case KEYCODE_KP_DOWN:
            key = Qt::Key_Down; break;
        case KEYCODE_PG_UP:
        case KEYCODE_KP_PG_UP:
            key = Qt::Key_PageUp; break;
        case KEYCODE_PG_DOWN:
        case KEYCODE_KP_PG_DOWN:
            key = Qt::Key_PageDown; break;

        case KEYCODE_LEFT_SHIFT:
        case KEYCODE_RIGHT_SHIFT:
            key = Qt::Key_Shift; break;
        case KEYCODE_LEFT_CTRL:
        case KEYCODE_RIGHT_CTRL:
            key = Qt::Key_Control; break;
        case KEYCODE_LEFT_ALT:
        case KEYCODE_RIGHT_ALT:
            key = Qt::Key_Alt; break;
        case KEYCODE_CAPS_LOCK:
            key = Qt::Key_CapsLock; break;
        case KEYCODE_NUM_LOCK:
            key = Qt::Key_NumLock; break;
        case KEYCODE_SCROLL_LOCK:
            key = Qt::Key_ScrollLock; break;

        case KEYCODE_F1:
        case KEYCODE_F2:
        case KEYCODE_F3:
        case KEYCODE_F4:
        case KEYCODE_F5:
        case KEYCODE_F6:
        case KEYCODE_F7:
        case KEYCODE_F8:
        case KEYCODE_F9:
        case KEYCODE_F10:
        case KEYCODE_F11:
        case KEYCODE_F12:
            key = Qt::Key_F1 + sym - KEYCODE_F1; break;

        case KEYCODE_MENU: key = Qt::Key_Menu; break;
        case KEYCODE_LEFT_HYPER: key = Qt::Key_Hyper_L; break;
        case KEYCODE_RIGHT_HYPER: key = Qt::Key_Hyper_R; break;

        case KEYCODE_KP_PLUS: key = Qt::Key_Plus; break;
        case KEYCODE_KP_MINUS: key = Qt::Key_Minus; break;
        case KEYCODE_KP_MULTIPLY: key = Qt::Key_multiply; break;
        case KEYCODE_KP_DIVIDE: key = Qt::Key_Slash; break;
        case KEYCODE_KP_FIVE:
            if (!(modifiers & Qt::KeypadModifier))
                key = Qt::Key_5;
            break;

        default: // none of the above
            break;
        }
    }

    if (key == Qt::Key_unknown && unicode == 0)
        return;

    // call processKeyEvent. This is where all the magic happens to insert a
    // key event into Qt's event loop.
    // Note that for repeated key events, isPress must be true
    // (on QNX, isPress is not set when the key event is repeated).
    processKeyEvent(unicode, key, modifiers, isPress || isRepeat, isRepeat);
}
예제 #13
0
void QWSSL5000KeyboardHandler::doKey(uchar code)
{
    int keyCode = Qt::Key_unknown;
    bool release = false;

    if (code & 0x80) {
        release = true;
        code &= 0x7f;
    }

    if (fn && !meta && (code >= 0x42 && code <= 0x52)) {
        ushort unicode=0;
        int scan=0;
        if (code == 0x42) { unicode='X'-'@'; scan=Qt::Key_X; } // Cut
        else if (code == 0x43) { unicode='C'-'@'; scan=Qt::Key_C; } // Copy
        else if (code == 0x44) { unicode='V'-'@'; scan=Qt::Key_V; } // Paste
        else if (code == 0x52) { unicode='Z'-'@'; scan=Qt::Key_Z; } // Undo
        if (scan) {
            processKeyEvent(unicode, scan, Qt::ControlModifier, !release, false);
            return;
        }
    }

    if (code < keyMSize) {
        keyCode = keyMap()[code].key_code;
    }

    bool repeatable = true;

    if (release && (keyCode == Qt::Key_F34 || keyCode == Qt::Key_F35))
        return; // no release for power and light keys
    if (keyCode >= Qt::Key_F1 && keyCode <= Qt::Key_F35
            || keyCode == Qt::Key_Escape || keyCode == Qt::Key_Home
            || keyCode == Qt::Key_Shift || keyCode == Qt::Key_Meta)
        repeatable = false;

    if (qt_screen->isTransformed()
            && keyCode >= Qt::Key_Left && keyCode <= Qt::Key_Down)
    {
        keyCode = transformDirKey(keyCode);
    }

    // Ctrl-Alt-Delete exits qws
    if (ctrl && alt && keyCode == Qt::Key_Delete) {
        qApp->quit();
    }

    if (keyCode == Qt::Key_F22) { /* Fn key */
        fn = !release;
    } else if (keyCode == Qt::Key_NumLock) {
        if (release)
            numLock = !numLock;
    } else if (keyCode == Qt::AltModifier) {
        alt = !release;
    } else if (keyCode == Qt::ControlModifier) {
        ctrl = !release;
    } else if (keyCode == Qt::ShiftModifier) {
        shift = !release;
    } else if (keyCode == Qt::MetaModifier) {
        meta = !release;
    } else if (keyCode == Qt::Key_CapsLock && release) {
        caps = !caps;
    }
    if (keyCode != Qt::Key_unknown) {
        bool bAlt = alt;
        bool bCtrl = ctrl;
        bool bShift = shift;
        int unicode = 0;
        if (code < keyMSize) {
            bool bCaps = caps ^ shift;
            if (fn) {
                if (shift) {
                    bCaps = bShift = false;
                    bCtrl = true;
                }
                if (meta) {
                    bCaps = bShift = true;
                    bAlt = true;
                }
            } else if (meta) {
                bCaps = bShift = true;
            }
            if (code > 40 && caps) {
                // fn-keys should only react to shift, not caps
                bCaps = bShift = shift;
            }
            if (numLock) {
                if (keyCode != Qt::Key_Space && keyCode != Qt::Key_Tab)
                    bCaps = bShift = false;
            }
            if (keyCode == Qt::Key_Delete && (bAlt || bCtrl)) {
                keyCode = Qt::Key_BraceLeft;
                unicode = '[';
                bCaps = bShift = bAlt = bCtrl = false;
            } else if (keyCode == Qt::Key_F31 && bCtrl) {
                keyCode = Qt::Key_QuoteLeft;
                unicode = '`';
            } else if (bCtrl)
                unicode =  keyMap()[code].ctrl_unicode ?  keyMap()[code].ctrl_unicode : 0xffff;
            else if (bCaps)
                unicode =  keyMap()[code].shift_unicode ?  keyMap()[code].shift_unicode : 0xffff;
            else
                unicode =  keyMap()[code].unicode ?  keyMap()[code].unicode : 0xffff;
        }

        modifiers = 0;
        if (bAlt) modifiers |= Qt::AltModifier;
        if (bCtrl) modifiers |= Qt::ControlModifier;
        if (bShift) modifiers |= Qt::ShiftModifier;

        // looks wrong -- WWA
        bool repeat = false;
        if (prevuni == unicode && prevkey == keyCode && !release)
            repeat = true;

        processKeyEvent(unicode, keyCode, modifiers, !release, repeat);

        if (!release) {
            prevuni = unicode;
            prevkey = keyCode;
        } else {
            prevkey = prevuni = 0;
        }
    }

    if (repeatable && !release)
        beginAutoRepeat(prevuni, prevkey, modifiers);
    else
        endAutoRepeat();
}
예제 #14
0
int WindowImplAndroid::processEvent(int fd, int events, void* data)
{
    ActivityStates* states = getActivity(NULL);
    Lock lock(states->mutex);

    AInputEvent* _event = NULL;

    if (AInputQueue_getEvent(states->inputQueue, &_event) >= 0)
    {
        if (AInputQueue_preDispatchEvent(states->inputQueue, _event))
            return 1;

        int handled = 0;

        int32_t type = AInputEvent_getType(_event);

        if (type == AINPUT_EVENT_TYPE_KEY)
        {
            int32_t action = AKeyEvent_getAction(_event);
            int32_t key = AKeyEvent_getKeyCode(_event);

            if ((action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_UP || action == AKEY_EVENT_ACTION_MULTIPLE) &&
                key != AKEYCODE_VOLUME_UP && key != AKEYCODE_VOLUME_DOWN)
            {
                handled = processKeyEvent(_event, states);
            }
        }
        else if (type == AINPUT_EVENT_TYPE_MOTION)
        {
            int32_t action = AMotionEvent_getAction(_event);

            switch (action & AMOTION_EVENT_ACTION_MASK)
            {
                case AMOTION_EVENT_ACTION_SCROLL:
                {
                    handled = processScrollEvent(_event, states);
                    break;
                }

                // todo: should hover_move indeed trigger the event?
                // case AMOTION_EVENT_ACTION_HOVER_MOVE:
                case AMOTION_EVENT_ACTION_MOVE:
                {
                    handled = processMotionEvent(_event, states);
                    break;
                }

                // todo: investigate AMOTION_EVENT_OUTSIDE
                case AMOTION_EVENT_ACTION_POINTER_DOWN:
                case AMOTION_EVENT_ACTION_DOWN:
                {
                    handled = processPointerEvent(true, _event, states);
                    break;
                }

                case AMOTION_EVENT_ACTION_POINTER_UP:
                case AMOTION_EVENT_ACTION_UP:
                case AMOTION_EVENT_ACTION_CANCEL:
                {
                    handled = processPointerEvent(false, _event, states);
                    break;
                }
            }

        }

        AInputQueue_finishEvent(states->inputQueue, _event, handled);
    }

    return 1;
}
예제 #15
0
void EglFSWaylandInput::keyReleased(quint32 time, quint32 key)
{
    processKeyEvent(QEvent::KeyRelease, time, key);
}
예제 #16
0
void QWSPC101KeyboardHandler::doKey(uchar code)
{

    int keyCode = Qt::Key_unknown;
    bool release = false;
    int keypad = 0;
    bool softwareRepeat = false;

#ifndef QT_QWS_USE_KEYCODES
    // extended?
    if (code == 224
#if defined(QT_QWS_IPAQ)
        && !ipaq_return_pressed
#endif
   ) {
        extended = 1;
        return;
    } else if (code == 225) {
        extended = 2;
        return;
    }
#endif

    if (code & 0x80) {
        release = true;
        code &= 0x7f;
    }

#ifndef QT_QWS_USE_KEYCODES
    if (extended == 1) {
        switch (code) {
        case 72:
            keyCode = Qt::Key_Up;
            break;
        case 75:
            keyCode = Qt::Key_Left;
            break;
        case 77:
            keyCode = Qt::Key_Right;
            break;
        case 80:
            keyCode = Qt::Key_Down;
            break;
        case 82:
            keyCode = Qt::Key_Insert;
            break;
        case 71:
            keyCode = Qt::Key_Home;
            break;
        case 73:
            keyCode = Qt::Key_PageUp;
            break;
        case 83:
            keyCode = Qt::Key_Delete;
            break;
        case 79:
            keyCode = Qt::Key_End;
            break;
        case 81:
            keyCode = Qt::Key_PageDown;
            break;
        case 28:
            keyCode = Qt::Key_Enter;
            break;
        case 53:
            keyCode = Qt::Key_Slash;
            break;
        case 0x1d:
            keyCode = Qt::Key_Control;
            break;
        case 0x2a:
            keyCode = Qt::Key_Print;
            break;
        case 0x38:
            keyCode = Qt::Key_Alt;
            break;
        case 0x5b:
            keyCode = Qt::Key_Super_L;
            break;
        case 0x5c:
            keyCode = Qt::Key_Super_R;
            break;
        case 0x5d:
            keyCode = Qt::Key_Menu;
            break;
#if 0
        default:
            qDebug("extended1 code %x release %d", code, release);
            break;
#endif
        }
    } else if (extended == 2) {
        switch (code) {
        case 0x1d:
            return;
        case 0x45:
            keyCode = Qt::Key_Pause;
            break;
        }
    } else
#endif
    {
        if (code < keyMSize) {
            keyCode = pc101KeyM[code].key_code;
        }

#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
        softwareRepeat = true;

        switch (code) {
            case 0x7a: case 0x7b: case 0x7c: case 0x7d:
                keyCode = code - 0x7a + Qt::Key_F9;
                softwareRepeat = false;
                break;
            case 0x79:
                keyCode = Qt::Key_SysReq;
                softwareRepeat = false;
                break;
            case 0x78:
# ifdef QT_QWS_IPAQ
                keyCode = Qt::Key_F24;  // record
# else
                keyCode = Qt::Key_Escape;
# endif
                softwareRepeat = false;
                break;
            case 0x60:
                keyCode = Qt::Key_Return;
# ifdef QT_QWS_IPAQ
                ipaq_return_pressed = !release;
# endif
                break;
            case 0x67:
                keyCode = Qt::Key_Right;
                break;
            case 0x69:
                keyCode = Qt::Key_Up;
                break;
            case 0x6a:
                keyCode = Qt::Key_Down;
                break;
            case 0x6c:
                keyCode = Qt::Key_Left;
                break;
        }

        if (qt_screen->isTransformed()
                && keyCode >= Qt::Key_Left && keyCode <= Qt::Key_Down)
        {
            keyCode = transformDirKey(keyCode);
        }
#endif
        /*
          Translate shift+Qt::Key_Tab to Qt::Key_Backtab
        */
        if ((keyCode == Qt::Key_Tab) && shift)
            keyCode = Qt::Key_Backtab;
    }

#ifndef QT_QWS_USE_KEYCODES
    /*
      Qt::Keypad consists of extended keys 53 and 28,
      and non-extended keys 55 and 71 through 83.
    */
    if ((extended == 1) ? (code == 53 || code == 28) :
         (code == 55 || (code >= 71 && code <= 83)))
#else
    if (code == 55 || code >= 71 && code <= 83 || code == 96
            || code == 98 || code == 118)
#endif
    {
        keypad = Qt::KeypadModifier;
    }

    // Ctrl-Alt-Backspace exits qws
    if (ctrl && alt && keyCode == Qt::Key_Backspace) {
        qApp->quit();
    }

    if (keyCode == Qt::Key_Alt) {
        alt = !release;
    } else if (keyCode == Qt::Key_Control) {
        ctrl = !release;
    } else if (keyCode == Qt::Key_Shift) {
        shift = !release;
    } else if (keyCode == Qt::Key_CapsLock && release) {
        caps = !caps;
#if defined(Q_OS_LINUX)
        char leds;
        ioctl(0, KDGETLED, &leds);
        leds = leds & ~LED_CAP;
        if (caps) leds |= LED_CAP;
        ioctl(0, KDSETLED, leds);
#endif
    }
    if (keyCode != Qt::Key_unknown) {
        bool bAlt = alt;
        bool bCtrl = ctrl;
        bool bShift = shift;
        int unicode = 0;
        if (code < keyMSize) {
            if (!extended) {
                bool bCaps = shift ||
                    (caps ? QChar(keyMap()[code].unicode).isLetter() : false);
                if (bCtrl)
                    unicode =  keyMap()[code].ctrl_unicode ?  keyMap()[code].ctrl_unicode : 0xffff;
                else if (bCaps)
                    unicode =  keyMap()[code].shift_unicode ?  keyMap()[code].shift_unicode : 0xffff;
                else
                    unicode =  keyMap()[code].unicode ?  keyMap()[code].unicode : 0xffff;
#ifndef QT_QWS_USE_KEYCODES
            } else if (extended==1) {
                if (code == 53)
                    unicode = '/';
#endif
            }
        }

        modifiers = 0;
        if (bAlt) modifiers |= Qt::AltModifier;
        if (bCtrl) modifiers |= Qt::ControlModifier;
        if (bShift) modifiers |= Qt::ShiftModifier;
        if (keypad) modifiers |= Qt::KeypadModifier;

        // looks wrong -- WWA
        bool repeat = false;
        if (prevuni == unicode && prevkey == keyCode && !release)
            repeat = true;

        processKeyEvent(unicode, keyCode, modifiers, !release, repeat);

        if (!release) {
            prevuni = unicode;
            prevkey = keyCode;
        } else {
            prevkey = prevuni = 0;
        }
    }

    if (softwareRepeat && !release)
        beginAutoRepeat(prevuni, prevkey, modifiers);
    else
        endAutoRepeat();

    extended = 0;
}
예제 #17
0
/*! \internal
    Translates the QNX keyboard events to Qt keyboard events
 */
void QWSQnxKeyboardHandler::socketActivated()
{
    _keyboard_packet packet;

    // read one keyboard event
    int bytesRead = QT_READ(keyboardFD, &packet, sizeof(_keyboard_packet));
    if (bytesRead == -1) {
        qErrnoWarning(errno, "QWSQnxKeyboardHandler::socketActivated(): Unable to read data.");
        return;
    }

    // the bytes read must be the size of a keyboard packet
    Q_ASSERT(bytesRead == sizeof(_keyboard_packet));

#if 0
    qDebug() << "keyboard got scancode"
             << hex << packet.data.modifiers
             << packet.data.flags
             << packet.data.key_cap
             << packet.data.key_sym
             << packet.data.key_scan;
#endif

    // QNX is nice enough to translate the raw keyboard data into a QNX data structure
    // Now we just have to translate it into a format Qt understands.

    // figure out whether it's a press
    bool isPress = packet.data.key_cap & KEY_DOWN;
    // figure out wheter the key is still pressed and the key event is repeated
    bool isRepeat = packet.data.key_cap & KEY_REPEAT;

    Qt::Key key = Qt::Key_unknown;
    int unicode = 0xffff;

    // TODO - this switch is not complete!
    switch (packet.data.key_scan) {
    case KEYCODE_SPACE: key = Qt::Key_Space; unicode = 0x20; break;
    case KEYCODE_F1: key = Qt::Key_F1; break;
    case KEYCODE_F2: key = Qt::Key_F2; break;
    case KEYCODE_F3: key = Qt::Key_F3; break;
    case KEYCODE_F4: key = Qt::Key_F4; break;
    case KEYCODE_F5: key = Qt::Key_F5; break;
    case KEYCODE_F6: key = Qt::Key_F6; break;
    case KEYCODE_F7: key = Qt::Key_F7; break;
    case KEYCODE_F8: key = Qt::Key_F8; break;
    case KEYCODE_F9: key = Qt::Key_F9; break;
    case KEYCODE_F10: key = Qt::Key_F10; break;
    case KEYCODE_F11: key = Qt::Key_F11; break;
    case KEYCODE_F12: key = Qt::Key_F12; break;
    case KEYCODE_BACKSPACE: key = Qt::Key_Backspace; break;
    case KEYCODE_TAB: key = Qt::Key_Tab; break;
    case KEYCODE_RETURN: key = Qt::Key_Return; break;
    case KEYCODE_KP_ENTER: key = Qt::Key_Enter; break;
    case KEYCODE_UP:
    case KEYCODE_KP_UP:
        key = Qt::Key_Up; break;
    case KEYCODE_DOWN:
    case KEYCODE_KP_DOWN:
        key = Qt::Key_Down; break;
    case KEYCODE_LEFT:
    case KEYCODE_KP_LEFT:
        key = Qt::Key_Left; break;
    case KEYCODE_RIGHT:
    case KEYCODE_KP_RIGHT:
        key = Qt::Key_Right; break;
    case KEYCODE_HOME:
    case KEYCODE_KP_HOME:
        key = Qt::Key_Home; break;
    case KEYCODE_END:
    case KEYCODE_KP_END:
        key = Qt::Key_End; break;
    case KEYCODE_PG_UP:
    case KEYCODE_KP_PG_UP:
        key = Qt::Key_PageUp; break;
    case KEYCODE_PG_DOWN:
    case KEYCODE_KP_PG_DOWN:
        key = Qt::Key_PageDown; break;
    case KEYCODE_INSERT:
    case KEYCODE_KP_INSERT:
        key = Qt::Key_Insert; break;
    case KEYCODE_DELETE:
    case KEYCODE_KP_DELETE:
        key = Qt::Key_Delete; break;
    case KEYCODE_ESCAPE:
        key = Qt::Key_Escape; break;
    default: // none of the above, try the key_scan directly
        unicode = packet.data.key_scan;
        break;
    }

    // figure out the modifiers that are currently pressed
    Qt::KeyboardModifiers modifiers = Qt::NoModifier;
    if (packet.data.flags & KEYMOD_SHIFT)
        modifiers |= Qt::ShiftModifier;
    if (packet.data.flags & KEYMOD_CTRL)
        modifiers |= Qt::ControlModifier;
    if (packet.data.flags & KEYMOD_ALT)
        modifiers |= Qt::AltModifier;

    // if the unicode value is not ascii, we ignore it.
    // TODO - do a complete mapping between all QNX scan codes and Qt codes
    if (unicode != 0xffff && !isascii(unicode))
        return; // unprintable character

    // call processKeyEvent. This is where all the magic happens to insert a
    // key event into Qt's event loop.
    // Note that for repeated key events, isPress must be true
    // (on QNX, isPress is not set when the key event is repeated).
    processKeyEvent(unicode, key, modifiers, isPress || isRepeat, isRepeat);
}
예제 #18
0
bool
Engine::ProcessKeyEvent(uint keyval, uint keycode, uint state)
{
    return processKeyEvent(keyval, keycode, state);
}
예제 #19
0
QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint16 keycode, bool pressed, bool autorepeat)
{
    KeycodeAction result = None;
    bool first_press = pressed && !autorepeat;

    const QEvdevKeyboardMap::Mapping *map_plain = 0;
    const QEvdevKeyboardMap::Mapping *map_withmod = 0;

    quint8 modifiers = m_modifiers;

    // get a specific and plain mapping for the keycode and the current modifiers
    for (int i = 0; i < m_keymap_size && !(map_plain && map_withmod); ++i) {
        const QEvdevKeyboardMap::Mapping *m = m_keymap + i;
        if (m->keycode == keycode) {
            if (m->modifiers == 0)
                map_plain = m;

            quint8 testmods = m_modifiers;
            if (m_locks[0] /*CapsLock*/ && (m->flags & QEvdevKeyboardMap::IsLetter))
                testmods ^= QEvdevKeyboardMap::ModShift;
            if (m->modifiers == testmods)
                map_withmod = m;
        }
    }

    if (m_locks[0] /*CapsLock*/ && map_withmod && (map_withmod->flags & QEvdevKeyboardMap::IsLetter))
        modifiers ^= QEvdevKeyboardMap::ModShift;

    qCDebug(qLcEvdevKeyMap, "Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d  |  plain=%d, withmod=%d, size=%d",
            keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0,
            int(map_plain ? map_plain - m_keymap : -1),
            int(map_withmod ? map_withmod - m_keymap : -1),
            m_keymap_size);

    const QEvdevKeyboardMap::Mapping *it = map_withmod ? map_withmod : map_plain;

    if (!it) {
        // we couldn't even find a plain mapping
        qCDebug(qLcEvdevKeyMap, "Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode, modifiers);
        return result;
    }

    bool skip = false;
    quint16 unicode = it->unicode;
    quint32 qtcode = it->qtcode;

    if ((it->flags & QEvdevKeyboardMap::IsModifier) && it->special) {
        // this is a modifier, i.e. Shift, Alt, ...
        if (pressed)
            m_modifiers |= quint8(it->special);
        else
            m_modifiers &= ~quint8(it->special);
    } else if (qtcode >= Qt::Key_CapsLock && qtcode <= Qt::Key_ScrollLock) {
        // (Caps|Num|Scroll)Lock
        if (first_press) {
            quint8 &lock = m_locks[qtcode - Qt::Key_CapsLock];
            lock ^= 1;

            switch (qtcode) {
            case Qt::Key_CapsLock  : result = lock ? CapsLockOn : CapsLockOff; break;
            case Qt::Key_NumLock   : result = lock ? NumLockOn : NumLockOff; break;
            case Qt::Key_ScrollLock: result = lock ? ScrollLockOn : ScrollLockOff; break;
            default                : break;
            }
        }
    } else if ((it->flags & QEvdevKeyboardMap::IsSystem) && it->special && first_press) {
        switch (it->special) {
        case QEvdevKeyboardMap::SystemReboot:
            result = Reboot;
            break;

        case QEvdevKeyboardMap::SystemZap:
            if (!m_no_zap)
                qApp->quit();
            break;

        case QEvdevKeyboardMap::SystemConsolePrevious:
            result = PreviousConsole;
            break;

        case QEvdevKeyboardMap::SystemConsoleNext:
            result = NextConsole;
            break;

        default:
            if (it->special >= QEvdevKeyboardMap::SystemConsoleFirst &&
                it->special <= QEvdevKeyboardMap::SystemConsoleLast) {
                result = KeycodeAction(SwitchConsoleFirst + ((it->special & QEvdevKeyboardMap::SystemConsoleMask) & SwitchConsoleMask));
            }
            break;
        }

        skip = true; // no need to tell Qt about it
    } else if ((qtcode == Qt::Key_Multi_key) && m_do_compose) {
        // the Compose key was pressed
        if (first_press)
            m_composing = 2;
        skip = true;
    } else if ((it->flags & QEvdevKeyboardMap::IsDead) && m_do_compose) {
        // a Dead key was pressed
        if (first_press && m_composing == 1 && m_dead_unicode == unicode) { // twice
            m_composing = 0;
            qtcode = Qt::Key_unknown; // otherwise it would be Qt::Key_Dead...
        } else if (first_press && unicode != 0xffff) {
            m_dead_unicode = unicode;
            m_composing = 1;
            skip = true;
        } else {
            skip = true;
        }
    }

    if (!skip) {
        // a normal key was pressed
        const int modmask = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier;

        // we couldn't find a specific mapping for the current modifiers,
        // or that mapping didn't have special modifiers:
        // so just report the plain mapping with additional modifiers.
        if ((it == map_plain && it != map_withmod) ||
            (map_withmod && !(map_withmod->qtcode & modmask))) {
            qtcode |= QEvdevKeyboardHandler::toQtModifiers(modifiers);
        }

        if (m_composing == 2 && first_press && !(it->flags & QEvdevKeyboardMap::IsModifier)) {
            // the last key press was the Compose key
            if (unicode != 0xffff) {
                int idx = 0;
                // check if this code is in the compose table at all
                for ( ; idx < m_keycompose_size; ++idx) {
                    if (m_keycompose[idx].first == unicode)
                        break;
                }
                if (idx < m_keycompose_size) {
                    // found it -> simulate a Dead key press
                    m_dead_unicode = unicode;
                    unicode = 0xffff;
                    m_composing = 1;
                    skip = true;
                } else {
                    m_composing = 0;
                }
            } else {
                m_composing = 0;
            }
        } else if (m_composing == 1 && first_press && !(it->flags & QEvdevKeyboardMap::IsModifier)) {
            // the last key press was a Dead key
            bool valid = false;
            if (unicode != 0xffff) {
                int idx = 0;
                // check if this code is in the compose table at all
                for ( ; idx < m_keycompose_size; ++idx) {
                    if (m_keycompose[idx].first == m_dead_unicode && m_keycompose[idx].second == unicode)
                        break;
                }
                if (idx < m_keycompose_size) {
                    quint16 composed = m_keycompose[idx].result;
                    if (composed != 0xffff) {
                        unicode = composed;
                        qtcode = Qt::Key_unknown;
                        valid = true;
                    }
                }
            }
            if (!valid) {
                unicode = m_dead_unicode;
                qtcode = Qt::Key_unknown;
            }
            m_composing = 0;
        }

        if (!skip) {
            // Up until now qtcode contained both the key and modifiers. Split it.
            Qt::KeyboardModifiers qtmods = Qt::KeyboardModifiers(qtcode & modmask);
            qtcode &= ~modmask;

            qCDebug(qLcEvdevKeyMap, "Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode, int(qtmods));

            // If NumLockOff and keypad key pressed remap event sent
            if (!m_locks[1] && (qtmods & Qt::KeypadModifier) &&
                 keycode >= 71 &&
                 keycode <= 83 &&
                 keycode != 74 &&
                 keycode != 78) {

                unicode = 0xffff;
                switch (keycode) {
                case 71: //7 --> Home
                    qtcode = Qt::Key_Home;
                    break;
                case 72: //8 --> Up
                    qtcode = Qt::Key_Up;
                    break;
                case 73: //9 --> PgUp
                    qtcode = Qt::Key_PageUp;
                    break;
                case 75: //4 --> Left
                    qtcode = Qt::Key_Left;
                    break;
                case 76: //5 --> Clear
                    qtcode = Qt::Key_Clear;
                    break;
                case 77: //6 --> right
                    qtcode = Qt::Key_Right;
                    break;
                case 79: //1 --> End
                    qtcode = Qt::Key_End;
                    break;
                case 80: //2 --> Down
                    qtcode = Qt::Key_Down;
                    break;
                case 81: //3 --> PgDn
                    qtcode = Qt::Key_PageDown;
                    break;
                case 82: //0 --> Ins
                    qtcode = Qt::Key_Insert;
                    break;
                case 83: //, --> Del
                    qtcode = Qt::Key_Delete;
                    break;
                }
            }

            // Map SHIFT + Tab to SHIFT + Backtab, QShortcutMap knows about this translation
            if (qtcode == Qt::Key_Tab && (qtmods & Qt::ShiftModifier) == Qt::ShiftModifier)
                qtcode = Qt::Key_Backtab;

            // Generate the QPA event.
            processKeyEvent(keycode, unicode, qtcode, qtmods, pressed, autorepeat);
        }
    }
    return result;
}
예제 #20
0
LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	GHOST_Event *event = 0;
	bool eventHandled = false;

	LRESULT lResult = 0;
	GHOST_SystemWin32 *system = ((GHOST_SystemWin32 *)getSystem());
	GHOST_ASSERT(system, "GHOST_SystemWin32::s_wndProc(): system not initialized");

	if (hwnd) {
		GHOST_WindowWin32 *window = (GHOST_WindowWin32 *)::GetWindowLongPtr(hwnd, GWL_USERDATA);
		if (window) {
			switch (msg) {
				// we need to check if new key layout has AltGr
				case WM_INPUTLANGCHANGE:
					system->handleKeyboardChange();
					break;
				////////////////////////////////////////////////////////////////////////
				// Keyboard events, processed
				////////////////////////////////////////////////////////////////////////
				case WM_INPUT:
				{
					// check WM_INPUT from input sink when ghost window is not in the foreground
					if (wParam == RIM_INPUTSINK) {
						if (GetFocus() != hwnd) // WM_INPUT message not for this window
							return 0;
					} //else wParam == RIM_INPUT

					RAWINPUT raw;
					RAWINPUT *raw_ptr = &raw;
					UINT rawSize = sizeof(RAWINPUT);

					GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw_ptr, &rawSize, sizeof(RAWINPUTHEADER));

					switch (raw.header.dwType)
					{
						case RIM_TYPEKEYBOARD:
							event = processKeyEvent(window, raw);
							if (!event) {
								GHOST_PRINT("GHOST_SystemWin32::wndProc: key event ");
								GHOST_PRINT(msg);
								GHOST_PRINT(" key ignored\n");
							}
							break;
#ifdef WITH_INPUT_NDOF
						case RIM_TYPEHID:
							if (system->processNDOF(raw))
								eventHandled = true;
							break;
#endif
					}
					break;
				}
				////////////////////////////////////////////////////////////////////////
				// Keyboard events, ignored
				////////////////////////////////////////////////////////////////////////
				case WM_KEYDOWN:
				case WM_SYSKEYDOWN:
				case WM_KEYUP:
				case WM_SYSKEYUP:
				/* These functions were replaced by WM_INPUT*/
				case WM_CHAR:
				/* The WM_CHAR message is posted to the window with the keyboard focus when
				 * a WM_KEYDOWN message is translated by the TranslateMessage function. WM_CHAR
				 * contains the character code of the key that was pressed.
				 */
				case WM_DEADCHAR:
					/* The WM_DEADCHAR message is posted to the window with the keyboard focus when a
					 * WM_KEYUP message is translated by the TranslateMessage function. WM_DEADCHAR 
					 * specifies a character code generated by a dead key. A dead key is a key that 
					 * generates a character, such as the umlaut (double-dot), that is combined with 
					 * another character to form a composite character. For example, the umlaut-O 
					 * character (Ö) is generated by typing the dead key for the umlaut character, and
					 * then typing the O key.
					 */
					break;
				case WM_SYSDEADCHAR:
				/* The WM_SYSDEADCHAR message is sent to the window with the keyboard focus when
				 * a WM_SYSKEYDOWN message is translated by the TranslateMessage function.
				 * WM_SYSDEADCHAR specifies the character code of a system dead key - that is,
				 * a dead key that is pressed while holding down the alt key.
				 */
				case WM_SYSCHAR:
					/* The WM_SYSCHAR message is sent to the window with the keyboard focus when 
					 * a WM_SYSCHAR message is translated by the TranslateMessage function. 
					 * WM_SYSCHAR specifies the character code of a dead key - that is, 
					 * a dead key that is pressed while holding down the alt key.
					 * To prevent the sound, DefWindowProc must be avoided by return
					 */
					break;
				case WM_SYSCOMMAND:
					/* The WM_SYSCHAR message is sent to the window when system commands such as 
					 * maximize, minimize  or close the window are triggered. Also it is sent when ALT 
					 * button is press for menu. To prevent this we must return preventing DefWindowProc.
					 */
					if (wParam == SC_KEYMENU) 
					{
						eventHandled = true;
					}// else
						/* XXX Disable for now due to area resizing issue. bug# 34990 */
					/*if((wParam&0xfff0)==SC_SIZE)
					{
						window->registerMouseClickEvent(0);
						window->m_wsh.startSizing(wParam);
						eventHandled = true;
					}*/
					break;
				////////////////////////////////////////////////////////////////////////
				// Tablet events, processed
				////////////////////////////////////////////////////////////////////////
				case WT_PACKET:
					((GHOST_WindowWin32 *)window)->processWin32TabletEvent(wParam, lParam);
					break;
				case WT_CSRCHANGE:
				case WT_PROXIMITY:
					((GHOST_WindowWin32 *)window)->processWin32TabletInitEvent();
					break;
				////////////////////////////////////////////////////////////////////////
				// Mouse events, processed
				////////////////////////////////////////////////////////////////////////
				case WM_LBUTTONDOWN:
					window->registerMouseClickEvent(0);
					event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskLeft);
					break;
				case WM_MBUTTONDOWN:
					window->registerMouseClickEvent(0);
					event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskMiddle);
					break;
				case WM_RBUTTONDOWN:
					window->registerMouseClickEvent(0);
					event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskRight);
					break;
				case WM_XBUTTONDOWN:
					window->registerMouseClickEvent(0);
					if ((short) HIWORD(wParam) == XBUTTON1) {
						event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskButton4);
					}
					else if ((short) HIWORD(wParam) == XBUTTON2) {
						event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskButton5);
					}
					break;
				case WM_LBUTTONUP:
					window->registerMouseClickEvent(1);
					if(window->m_wsh.isWinChanges())
						window->m_wsh.accept();
					else
						event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskLeft);
					break;
				case WM_MBUTTONUP:
					window->registerMouseClickEvent(1);
					event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskMiddle);
					break;
				case WM_RBUTTONUP:
					window->registerMouseClickEvent(1);
					event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskRight);
					break;
				case WM_XBUTTONUP:
					window->registerMouseClickEvent(1);
					if ((short) HIWORD(wParam) == XBUTTON1) {
						event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskButton4);
					}
					else if ((short) HIWORD(wParam) == XBUTTON2) {
						event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskButton5);
					}
					break;
				case WM_MOUSEMOVE:
					if(window->m_wsh.isWinChanges())
						window->m_wsh.updateWindowSize();
					else
						event = processCursorEvent(GHOST_kEventCursorMove, window);
					break;
				case WM_MOUSEWHEEL:
					/* The WM_MOUSEWHEEL message is sent to the focus window 
					 * when the mouse wheel is rotated. The DefWindowProc 
					 * function propagates the message to the window's parent.
					 * There should be no internal forwarding of the message, 
					 * since DefWindowProc propagates it up the parent chain 
					 * until it finds a window that processes it.
					 */
					event = processWheelEvent(window, wParam, lParam);
					break;
				case WM_SETCURSOR:
					/* The WM_SETCURSOR message is sent to a window if the mouse causes the cursor
					 * to move within a window and mouse input is not captured.
					 * This means we have to set the cursor shape every time the mouse moves!
					 * The DefWindowProc function uses this message to set the cursor to an 
					 * arrow if it is not in the client area.
					 */
					if (LOWORD(lParam) == HTCLIENT) {
						// Load the current cursor
						window->loadCursor(window->getCursorVisibility(), window->getCursorShape());
						// Bypass call to DefWindowProc
						return 0;
					} 
					else {
						// Outside of client area show standard cursor
						window->loadCursor(true, GHOST_kStandardCursorDefault);
					}
					break;

				////////////////////////////////////////////////////////////////////////
				// Mouse events, ignored
				////////////////////////////////////////////////////////////////////////
				case WM_NCMOUSEMOVE:
				/* The WM_NCMOUSEMOVE message is posted to a window when the cursor is moved
				 * within the nonclient area of the window. This message is posted to the window
				 * that contains the cursor. If a window has captured the mouse, this message is not posted.
				 */
				case WM_NCHITTEST:
					/* The WM_NCHITTEST message is sent to a window when the cursor moves, or 
					 * when a mouse button is pressed or released. If the mouse is not captured, 
					 * the message is sent to the window beneath the cursor. Otherwise, the message 
					 * is sent to the window that has captured the mouse. 
					 */
					break;

				////////////////////////////////////////////////////////////////////////
				// Window events, processed
				////////////////////////////////////////////////////////////////////////
				case WM_CLOSE:
					/* The WM_CLOSE message is sent as a signal that a window or an application should terminate. */
					event = processWindowEvent(GHOST_kEventWindowClose, window);
					break;
				case WM_ACTIVATE:
					/* The WM_ACTIVATE message is sent to both the window being activated and the window being 
					 * deactivated. If the windows use the same input queue, the message is sent synchronously, 
					 * first to the window procedure of the top-level window being deactivated, then to the window
					 * procedure of the top-level window being activated. If the windows use different input queues,
					 * the message is sent asynchronously, so the window is activated immediately. 
					 */
				{
					GHOST_ModifierKeys modifiers;
					modifiers.clear();
					system->storeModifierKeys(modifiers);
					event = processWindowEvent(LOWORD(wParam) ? GHOST_kEventWindowActivate : GHOST_kEventWindowDeactivate, window);
					/* WARNING: Let DefWindowProc handle WM_ACTIVATE, otherwise WM_MOUSEWHEEL
					 * will not be dispatched to OUR active window if we minimize one of OUR windows. */
					if(LOWORD(wParam)==WA_INACTIVE)
						window->lostMouseCapture();

					lResult = ::DefWindowProc(hwnd, msg, wParam, lParam);
					break;
				}
				case WM_PAINT:
					/* An application sends the WM_PAINT message when the system or another application 
					 * makes a request to paint a portion of an application's window. The message is sent
					 * when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage 
					 * function when the application obtains a WM_PAINT message by using the GetMessage or 
					 * PeekMessage function. 
					 */
					event = processWindowEvent(GHOST_kEventWindowUpdate, window);
					::ValidateRect(hwnd, NULL);
					break;
				case WM_GETMINMAXINFO:
					/* The WM_GETMINMAXINFO message is sent to a window when the size or 
					 * position of the window is about to change. An application can use 
					 * this message to override the window's default maximized size and 
					 * position, or its default minimum or maximum tracking size. 
					 */
					processMinMaxInfo((MINMAXINFO *) lParam);
					/* Let DefWindowProc handle it. */
					break;
				case WM_SIZE:
					/* The WM_SIZE message is sent to a window after its size has changed.
					 * The WM_SIZE and WM_MOVE messages are not sent if an application handles the 
					 * WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient
					 * to perform any move or size change processing during the WM_WINDOWPOSCHANGED 
					 * message without calling DefWindowProc.
					 */
					event = processWindowEvent(GHOST_kEventWindowSize, window);
					break;
				case WM_CAPTURECHANGED:
					window->lostMouseCapture();
					break;
				case WM_MOVING:
				/* The WM_MOVING message is sent to a window that the user is moving. By processing
				 * this message, an application can monitor the size and position of the drag rectangle
				 * and, if needed, change its size or position.
				 */
				case WM_MOVE:
					/* The WM_SIZE and WM_MOVE messages are not sent if an application handles the 
					 * WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient
					 * to perform any move or size change processing during the WM_WINDOWPOSCHANGED 
					 * message without calling DefWindowProc. 
					 */
					event = processWindowEvent(GHOST_kEventWindowMove, window);
					break;
				////////////////////////////////////////////////////////////////////////
				// Window events, ignored
				////////////////////////////////////////////////////////////////////////
				case WM_WINDOWPOSCHANGED:
				/* The WM_WINDOWPOSCHANGED message is sent to a window whose size, position, or place
				 * in the Z order has changed as a result of a call to the SetWindowPos function or
				 * another window-management function.
				 * The WM_SIZE and WM_MOVE messages are not sent if an application handles the
				 * WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient
				 * to perform any move or size change processing during the WM_WINDOWPOSCHANGED
				 * message without calling DefWindowProc.
				 */
				case WM_ERASEBKGND:
				/* An application sends the WM_ERASEBKGND message when the window background must be
				 * erased (for example, when a window is resized). The message is sent to prepare an
				 * invalidated portion of a window for painting.
				 */
				case WM_NCPAINT:
				/* An application sends the WM_NCPAINT message to a window when its frame must be painted. */
				case WM_NCACTIVATE:
				/* The WM_NCACTIVATE message is sent to a window when its nonclient area needs to be changed
				 * to indicate an active or inactive state.
				 */
				case WM_DESTROY:
				/* The WM_DESTROY message is sent when a window is being destroyed. It is sent to the window
				 * procedure of the window being destroyed after the window is removed from the screen.
				 * This message is sent first to the window being destroyed and then to the child windows
				 * (if any) as they are destroyed. During the processing of the message, it can be assumed
				 * that all child windows still exist.
				 */
				case WM_NCDESTROY:
					/* The WM_NCDESTROY message informs a window that its nonclient area is being destroyed. The 
					 * DestroyWindow function sends the WM_NCDESTROY message to the window following the WM_DESTROY
					 * message. WM_DESTROY is used to free the allocated memory object associated with the window. 
					 */
					break;
				case WM_KILLFOCUS:
					/* The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard focus. 
					 * We want to prevent this if a window is still active and it loses focus to nowhere*/
					if (!wParam && hwnd == GetActiveWindow())
						SetFocus(hwnd);
				case WM_SHOWWINDOW:
				/* The WM_SHOWWINDOW message is sent to a window when the window is about to be hidden or shown. */
				case WM_WINDOWPOSCHANGING:
				/* The WM_WINDOWPOSCHANGING message is sent to a window whose size, position, or place in
				 * the Z order is about to change as a result of a call to the SetWindowPos function or
				 * another window-management function.
				 */
				case WM_SETFOCUS:
				/* The WM_SETFOCUS message is sent to a window after it has gained the keyboard focus. */
				case WM_ENTERSIZEMOVE:
					/* The WM_ENTERSIZEMOVE message is sent one time to a window after it enters the moving 
					 * or sizing modal loop. The window enters the moving or sizing modal loop when the user 
					 * clicks the window's title bar or sizing border, or when the window passes the 
					 * WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the 
					 * message specifies the SC_MOVE or SC_SIZE value. The operation is complete when 
					 * DefWindowProc returns. 
					 */
					break;
				////////////////////////////////////////////////////////////////////////
				// Other events
				////////////////////////////////////////////////////////////////////////
				case WM_GETTEXT:
				/* An application sends a WM_GETTEXT message to copy the text that
				 * corresponds to a window into a buffer provided by the caller.
				 */
				case WM_ACTIVATEAPP:
				/* The WM_ACTIVATEAPP message is sent when a window belonging to a
				 * different application than the active window is about to be activated.
				 * The message is sent to the application whose window is being activated
				 * and to the application whose window is being deactivated.
				 */
				case WM_TIMER:
					/* The WIN32 docs say:
					 * The WM_TIMER message is posted to the installing thread's message queue
					 * when a timer expires. You can process the message by providing a WM_TIMER
					 * case in the window procedure. Otherwise, the default window procedure will
					 * call the TimerProc callback function specified in the call to the SetTimer
					 * function used to install the timer. 
					 *
					 * In GHOST, we let DefWindowProc call the timer callback.
					 */
					break;
				case WM_CANCELMODE:
					if(window->m_wsh.isWinChanges())
						window->m_wsh.cancel();

			}
		}
		else {
			// Event found for a window before the pointer to the class has been set.
			GHOST_PRINT("GHOST_SystemWin32::wndProc: GHOST window event before creation\n");
			/* These are events we typically miss at this point:
			 * WM_GETMINMAXINFO	0x24
			 * WM_NCCREATE			0x81
			 * WM_NCCALCSIZE		0x83
			 * WM_CREATE			0x01
			 * We let DefWindowProc do the work.
			 */
		}
	}
	else {
		// Events without valid hwnd
		GHOST_PRINT("GHOST_SystemWin32::wndProc: event without window\n");
	}

	if (event) {
		system->pushEvent(event);
		eventHandled = true;
	}

	if (!eventHandled)
		lResult = ::DefWindowProcW(hwnd, msg, wParam, lParam);

	return lResult;
}
예제 #21
0
int VspGlWindow::handle(int event) 
{
	int mx = Fl::event_x();
	int my = h() - Fl::event_y();
	
	switch(event) 
	{
		case FL_ENTER:
			focusFlag = 1;

			Fl::focus( this );
			return Fl_Gl_Window::handle(event);			// Let Base Widget process all others

		break;

		case FL_LEAVE:
			focusFlag = 0;
			cursor(FL_CURSOR_DEFAULT);
			return Fl_Gl_Window::handle(event);			// Let Base Widget process all others

		break;

		case FL_PUSH:
			{
				for ( int i = 0 ; i < NUM_V_WIN ; i++ )
				{
					vWin[i]->deactivate();
					if ( vWin[i]->mousePress( mx, my ) )
						currVWin = vWin[i];

					aircraftPtr->getScreenMgr()->updateBackgroundScreen();

				}
					
				Fl::focus( this );
						
				redraw();
				return 1;
			}

		case FL_RELEASE:
			{
				if ( currVWin )
				{
					currVWin->mouseRelease( mx, my );
				}
				redraw();
				return 1;
			}

		case FL_MOVE:
			{
				if ( currVWin )
				{
					currVWin->mouseMove( mx, my );
					if (mouseTrack) 
					{
						setWindowFocus(mx, my);
						redraw();
					}
				}
				return 1;
			}

		case FL_DRAG:
			{
				if ( currVWin )
				{
					currVWin->mouseDrag( mx, my );
				}
				redraw();
				return 1;
			}

		case FL_KEYDOWN:
			{
				return processKeyEvent();
			}

		case FL_FOCUS :
		case FL_UNFOCUS :
 			return 1;

		default:
			return Fl_Gl_Window::handle(event);	// Let Base Widget process all others

	}
	return Fl_Gl_Window::handle(event);			// Let Base Widget process all others

}
예제 #22
0
      void processMouse(retro_input_state_t aCallback)
      {
         int16_t joy_x, joy_y, x, y;
         bool do_joystick, down;

         static const uint32_t retroButtons[2] = {RETRO_DEVICE_ID_MOUSE_LEFT, RETRO_DEVICE_ID_MOUSE_RIGHT};
         static const Common::EventType eventID[2][2] =
         {
            {Common::EVENT_LBUTTONDOWN, Common::EVENT_LBUTTONUP},
            {Common::EVENT_RBUTTONDOWN, Common::EVENT_RBUTTONUP}
         };

         down = false;
         do_joystick = false;
         x = aCallback(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
         y = aCallback(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
         joy_x = aCallback(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X);
         joy_y = aCallback(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y);

         if (joy_x > ANALOG_THRESHOLD3)
         {
            _mouseX += 4*ANALOG_VALUE_X_ADD;
            _mouseX = (_mouseX < 0) ? 0 : _mouseX;
            _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;
            do_joystick = true;
         }
         else if (joy_x < -ANALOG_THRESHOLD3)
         {
            _mouseX -= 4*ANALOG_VALUE_X_ADD;
            _mouseX = (_mouseX < 0) ? 0 : _mouseX;
            _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;
            do_joystick = true;
         }
         else if (joy_x > ANALOG_THRESHOLD2)
         {
            _mouseX += 2*ANALOG_VALUE_X_ADD;
            _mouseX = (_mouseX < 0) ? 0 : _mouseX;
            _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;
            do_joystick = true;
         }
         else if (joy_x < -ANALOG_THRESHOLD2)
         {
            _mouseX -= 2*ANALOG_VALUE_X_ADD;
            _mouseX = (_mouseX < 0) ? 0 : _mouseX;
            _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;
            do_joystick = true;
         }
         else if (joy_x > ANALOG_THRESHOLD1)
         {
            _mouseX += ANALOG_VALUE_X_ADD;
            _mouseX = (_mouseX < 0) ? 0 : _mouseX;
            _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;
            do_joystick = true;
         }
         else if (joy_x < -ANALOG_THRESHOLD1)
         {
            _mouseX -= ANALOG_VALUE_X_ADD;
            _mouseX = (_mouseX < 0) ? 0 : _mouseX;
            _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;
            do_joystick = true;
         }

         if (joy_y > ANALOG_THRESHOLD3)
         {
            _mouseY += 4*ANALOG_VALUE_Y_ADD;
            _mouseY = (_mouseY < 0) ? 0 : _mouseY;
            _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;
            do_joystick = true;
         }
         else if (joy_y < -ANALOG_THRESHOLD3)
         {
            _mouseY -= 4*ANALOG_VALUE_Y_ADD;
            _mouseY = (_mouseY < 0) ? 0 : _mouseY;
            _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;
            do_joystick = true;
         }
         else if (joy_y > ANALOG_THRESHOLD2)
         {
            _mouseY += 2*ANALOG_VALUE_Y_ADD;
            _mouseY = (_mouseY < 0) ? 0 : _mouseY;
            _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;
            do_joystick = true;
         }
         else if (joy_y < -ANALOG_THRESHOLD2)
         {
            _mouseY -= 2*ANALOG_VALUE_Y_ADD;
            _mouseY = (_mouseY < 0) ? 0 : _mouseY;
            _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;
            do_joystick = true;
         }
         else if (joy_y > ANALOG_THRESHOLD1)
         {
            _mouseY += ANALOG_VALUE_Y_ADD; 
            _mouseY = (_mouseY < 0) ? 0 : _mouseY;
            _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;
            do_joystick = true;
         }
         else if (joy_y < -ANALOG_THRESHOLD1)
         {
            _mouseY -= ANALOG_VALUE_Y_ADD; 
            _mouseY = (_mouseY < 0) ? 0 : _mouseY;
            _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;
            do_joystick = true;
         }

         {
            if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT))
            {
               _mouseX -= 2*ANALOG_VALUE_X_ADD;
               _mouseX = (_mouseX < 0) ? 0 : _mouseX;
               _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;
               do_joystick = true;
            }

            if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT))
            {
               _mouseX += 2*ANALOG_VALUE_X_ADD;
               _mouseX = (_mouseX < 0) ? 0 : _mouseX;
               _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;
               do_joystick = true;
            }

            if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP))
            {
               _mouseY -= 2*ANALOG_VALUE_Y_ADD; 
               _mouseY = (_mouseY < 0) ? 0 : _mouseY;
               _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;
               do_joystick = true;
            }

            if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN))
            {
               _mouseY += 2*ANALOG_VALUE_Y_ADD; 
               _mouseY = (_mouseY < 0) ? 0 : _mouseY;
               _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;
               do_joystick = true;
            }
         }

         if (aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT))
         {
            Common::Event ev;
            ev.type = Common::EVENT_MAINMENU;
            _events.push_back(ev);
         }

         if (do_joystick)
         {
            Common::Event ev;
            ev.type = Common::EVENT_MOUSEMOVE;
            ev.mouse.x = _mouseX;
            ev.mouse.y = _mouseY;
            _events.push_back(ev);
         }

         down = aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);

         if(down != _joypadmouseButtons[0])
         {
            _joypadmouseButtons[0] = down;

            Common::Event ev;
            ev.type = eventID[0][down ? 0 : 1];
            ev.mouse.x = _mouseX;
            ev.mouse.y = _mouseY;
            _events.push_back(ev);
         }

         down = aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);

         if(down != _joypadmouseButtons[1])
         {
            _joypadmouseButtons[1] = down;

            Common::Event ev;
            ev.type = eventID[1][down ? 0 : 1];
            ev.mouse.x = _mouseX;
            ev.mouse.y = _mouseY;
            _events.push_back(ev);
         }

         down = aCallback(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START);
         if (down != _joypadstartButton)
         {
            _joypadstartButton = down;
            bool state = down ? true : false;
            processKeyEvent(state, 27, 27, 0);
         }

         if(x || y)
         {
            _mouseX += x;
            _mouseX = (_mouseX < 0) ? 0 : _mouseX;
            _mouseX = (_mouseX >= _screen.w) ? _screen.w : _mouseX;

            _mouseY += y;
            _mouseY = (_mouseY < 0) ? 0 : _mouseY;
            _mouseY = (_mouseY >= _screen.h) ? _screen.h : _mouseY;

            Common::Event ev;
            ev.type = Common::EVENT_MOUSEMOVE;
            ev.mouse.x = _mouseX;
            ev.mouse.y = _mouseY;
            _events.push_back(ev);
         }


         for(int i = 0; i < 2; i ++)
         {
            Common::Event ev;
            bool down = aCallback(0, RETRO_DEVICE_MOUSE, 0, retroButtons[i]);
            if(down != _mouseButtons[i])
            {
               _mouseButtons[i] = down;

               ev.type = eventID[i][down ? 0 : 1];
               ev.mouse.x = _mouseX;
               ev.mouse.y = _mouseY;
               _events.push_back(ev);
            }

         }
      }