Example #1
0
void InputAPI::TriggerKeyEvent(KeyEvent &key)
{
    assert(key.eventType != KeyEvent::KeyEventInvalid);
    assert(key.handled == false);

    // First, we pass the key to the global top level input context, which operates above Qt widget input.
    topLevelInputContext.TriggerKeyEvent(key);
    if (key.handled) // Convert a Pressed event to a Released event if it was suppressed, so that lower contexts properly let go of the key.
        key.eventType = KeyEvent::KeyReleased;

    // If the mouse cursor is hidden, we treat each InputContext as if it had TakesKeyboardEventsOverQt true.
    // This is because when the mouse cursor is hidden, no key input should go to the main 2D UI window.

    // Pass the event to all input contexts in the priority order.
    for(auto iter = registeredInputContexts.Begin(); iter != registeredInputContexts.End(); ++iter)
    {
        InputContextPtr context = iter->Lock();
        if (context.Get())// && (!qtWidgetHasKeyboardFocus || context->TakesKeyboardEventsOverQt() || !IsMouseCursorVisible()))
            context->TriggerKeyEvent(key);
        if (key.handled)
            key.eventType = KeyEvent::KeyReleased;
    }

    // If the mouse cursor is hidden, all key events should go to the 'scene' - In that case, suppress all key events from going to the main 2D Qt window.
    if (!IsMouseCursorVisible())
        key.Suppress();
}