InputResponder::InputResponder(RenderingWindow* window, Character* character, Camera* camera, BloomFilterEffect* bloom, LuminanceFilterEffect* luminance) : inputProc(window) { //Wire up the event to close window CloseWindowEvent* cWindow = new CloseWindowEvent(window); inputProc.bind(KeySequence(InputEvent::WinClosed), cWindow); //Wire up the event to move the character along the axis KeyMovement* movement = new KeyMovement(character, camera); KeySequence movementKeys; movementKeys.add(InputEvent::KeyW); movementKeys.add(InputEvent::KeyA); movementKeys.add(InputEvent::KeyS); movementKeys.add(InputEvent::KeyD); inputProc.bind(movementKeys, movement); //Wire up the mouse to rotate view MouseLookEvent* mouseLook = new MouseLookEvent(character, window, camera); inputProc.bind(KeySequence(InputEvent::MouseMove), mouseLook); //Wire up the postprocesseffects controller PostprocessParameterInputEvent* pprocessInputs = new PostprocessParameterInputEvent(bloom, luminance); KeySequence paramKeys; paramKeys.add(InputEvent::Key1); paramKeys.add(InputEvent::Key2); paramKeys.add(InputEvent::Key3); paramKeys.add(InputEvent::Key4); inputProc.bind(paramKeys, pprocessInputs); }
void KeySequenceWidget::startRecording() { keySequence() = KeySequence(); setDown(true); setFocus(); grabKeyboard(); setStatus(Recording); }
void Configuration::readShortcuts() { Shortcuts = defaultShortcuts; QMap<QString, Shortcut>::const_iterator it = Shortcuts.begin(); while(it != Shortcuts.end()) { const QString id = it.key(); QString key = shortcutFromConfig(id); if(key != "") { if(key == "NOT_SET") Shortcuts[it.key()].Hotkey = QKeySequence(); else { QKeySequence KeySequence(key); Shortcuts[it.key()].Hotkey = KeySequence; } } it++; } emit shortcutsUpdated(); }
void ShortcutWidget::reset() { clear(); keysequence_ = KeySequence(); }
//bool InputAPI::eventFilter(Object *obj, QEvent *event) void InputAPI::EventFilter(StringHash eventType, VariantMap& eventData) { Urho3D::Input* input = GetSubsystem<Urho3D::Input>(); if (eventType == Urho3D::E_KEYDOWN) { KeyEvent keyEvent(this); keyEvent.urhoEvent = eventData; keyEvent.keyCode = eventData[Urho3D::KeyDown::P_KEY].GetInt();// StripModifiersFromKey(e->key()); keyEvent.sequence = KeySequence(eventData[Urho3D::KeyDown::P_KEY].GetInt() | eventData[Urho3D::KeyDown::P_QUALIFIERS].GetInt()); keyEvent.keyPressCount = 1; keyEvent.modifiers = eventData[Urho3D::KeyDown::P_QUALIFIERS].GetInt(); //keyEvent.text = e->text(); ///\todo keyEvent.eventType = KeyEvent::KeyPressed; keyEvent.timestamp = framework->Frame()->WallClockTime(); // Assign the keys from the heldKeys map to the keyEvent.otherHeldKeys vector for (auto current = heldKeys.Begin(); current != heldKeys.End(); ++ current) keyEvent.otherHeldKeys.Push((*current).first_); keyEvent.handled = false; currentModifiers = eventData[Urho3D::KeyDown::P_QUALIFIERS].GetInt(); // local tracking for mouse events auto keyRecord = heldKeys.Find(keyEvent.keyCode); if (keyRecord == heldKeys.End()) { KeyPressInformation info; info.keyPressCount = 1; info.keyState = KeyEvent::KeyPressed; //info.firstPressTime = now; ///\todo heldKeys[keyEvent.keyCode] = info; } // Queue up the press event for the polling API if (keyEvent.keyPressCount == 1) /// \todo The polling API does not get key repeats at all. Should it? newKeysPressedQueue.Push(eventData[Urho3D::KeyDown::P_KEY].GetInt()); TriggerKeyEvent(keyEvent); return; // If we got true here, need to suppress this event from going to Qt. } else if (eventType == Urho3D::E_KEYUP) { HeldKeysMap::Iterator existingKey = heldKeys.Find(eventData[Urho3D::KeyDown::P_KEY].GetInt()); // If we received a release on an unknown key we haven't received a press for, don't pass it to the scene, // since we didn't pass the press to the scene either (or we've already passed the release before, so don't // pass duplicate releases). if (existingKey == heldKeys.End()) return; KeyEvent keyEvent(this); keyEvent.urhoEvent = eventData; keyEvent.keyCode = eventData[Urho3D::KeyDown::P_KEY].GetInt(); keyEvent.keyPressCount = existingKey->second_.keyPressCount; keyEvent.modifiers = eventData[Urho3D::KeyDown::P_QUALIFIERS].GetInt(); //keyEvent.text = e->text(); ///\todo keyEvent.eventType = KeyEvent::KeyReleased; //keyEvent.otherHeldKeys = heldKeys; ///\todo keyEvent.handled = false; keyEvent.timestamp = framework->Frame()->WallClockTime(); heldKeys.Erase(existingKey); currentModifiers = eventData[Urho3D::KeyDown::P_QUALIFIERS].GetInt(); // local tracking for mouse events // Queue up the release event for the polling API, independent of whether any Qt widget has keyboard focus. if (keyEvent.keyPressCount == 1) /// \todo The polling API does not get key repeats at all. Should it? newKeysReleasedQueue.Push(eventData[Urho3D::KeyDown::P_KEY].GetInt()); TriggerKeyEvent(keyEvent); return; // Suppress this event from going forward. } else if (eventType == Urho3D::E_MOUSEBUTTONDOWN || eventType == Urho3D::E_MOUSEBUTTONUP) { // We always update the global polled input states, independent of whether any the mouse cursor is // on top of any Qt widget. if (eventType == Urho3D::E_MOUSEBUTTONDOWN) { heldMouseButtons |= eventData[Urho3D::MouseButtonDown::P_BUTTON].GetInt(); //(MouseEvent::MouseButton)e->button(); newMouseButtonsPressedQueue |= eventData[Urho3D::MouseButtonDown::P_BUTTON].GetInt(); } else { heldMouseButtons &= ~eventData[Urho3D::MouseButtonDown::P_BUTTON].GetInt(); newMouseButtonsReleasedQueue |= eventData[Urho3D::MouseButtonDown::P_BUTTON].GetInt(); } // The mouse coordinates we receive can come from different widgets, and we are interested only in the coordinates // in the QGraphicsView client area, so we need to remap them. Point mousePos(input->GetMousePosition().x_, input->GetMousePosition().y_);//MapPointToMainGraphicsView(obj, e->pos()); MouseEvent mouseEvent(this); mouseEvent.eventType = (eventType == Urho3D::E_MOUSEBUTTONDOWN) ? MouseEvent::MousePressed : MouseEvent::MouseReleased; mouseEvent.button = (MouseEvent::MouseButton)eventData[Urho3D::MouseButtonDown::P_BUTTON].GetInt(); mouseEvent.x = mousePos.x; mouseEvent.y = mousePos.y; mouseEvent.z = 0; // Mouse presses do not carry relative mouse movement information at the same time. // (separate relative movement messages are passed for first-person mode moves) mouseEvent.relativeX = 0; mouseEvent.relativeY = 0; mouseEvent.relativeZ = 0; mouseEvent.modifiers = eventData[Urho3D::MouseButtonDown::P_QUALIFIERS].GetInt();//currentModifiers; lastMouseX = mouseEvent.x; lastMouseY = mouseEvent.y; mouseEvent.globalX = mouseEvent.x; mouseEvent.globalY = mouseEvent.y; mouseEvent.otherButtons = eventData[Urho3D::MouseButtonDown::P_BUTTONS].GetUInt(); mouseEvent.modifiers = eventData[Urho3D::MouseButtonDown::P_QUALIFIERS].GetInt(); for (auto current = heldKeys.Begin(); current != heldKeys.End(); ++ current) mouseEvent.heldKeys.Push((*current).first_); mouseEvent.handled = false; mouseEvent.timestamp = framework->Frame()->WallClockTime(); TriggerMouseEvent(mouseEvent); return; } //case Urho3D::E_MOUSEMOVE: else if (eventType == Urho3D::E_MOUSEMOVE) { MouseEvent mouseEvent(this); mouseEvent.eventType = MouseEvent::MouseMove; mouseEvent.button = (MouseEvent::MouseButton)eventData[Urho3D::MouseMove::P_BUTTONS].GetInt(); // The mouse coordinates we receive can come from different widgets, and we are interested only in the coordinates // in the QGraphicsView client area, so we need to remap them. Point mousePos(input->GetMousePosition().x_, input->GetMousePosition().y_); mouseEvent.z = 0; mouseEvent.relativeX = eventData[Urho3D::MouseMove::P_DX].GetInt(); mouseEvent.relativeY = eventData[Urho3D::MouseMove::P_DY].GetInt(); mouseEvent.relativeZ = 0; mouseEvent.x = mousePos.x; mouseEvent.y = mousePos.y; // If there wasn't any change to the mouse relative coords in FPS mode, ignore this event. if (mouseEvent.relativeX == 0 && mouseEvent.relativeY == 0) return; mouseEvent.globalX = mousePos.x; mouseEvent.globalY = mousePos.y; mouseEvent.otherButtons = eventData[Urho3D::MouseMove::P_BUTTONS].GetInt(); for (auto current = heldKeys.Begin(); current != heldKeys.End(); ++ current) mouseEvent.heldKeys.Push((*current).first_); mouseEvent.handled = false; mouseEvent.timestamp = framework->Frame()->WallClockTime(); // Save the absolute coordinates to be able to compute the proper relative movement values in the next // mouse event. lastMouseX = mouseEvent.x; lastMouseY = mouseEvent.y; TriggerMouseEvent(mouseEvent); return; } else if (eventType == Urho3D::E_MOUSEWHEEL) { MouseEvent mouseEvent(this); mouseEvent.eventType = MouseEvent::MouseScroll; mouseEvent.button = MouseEvent::NoButton; mouseEvent.otherButtons = eventData[Urho3D::MouseWheel::P_BUTTONS].GetInt(); mouseEvent.x = input->GetMousePosition().x_; mouseEvent.y = input->GetMousePosition().y_; mouseEvent.z = 0; // Mouse wheel does not have an absolute z position, only relative. mouseEvent.relativeX = 0; mouseEvent.relativeY = 0; mouseEvent.relativeZ = eventData[Urho3D::MouseWheel::P_WHEEL].GetInt(); mouseEvent.globalX = input->GetMousePosition().x_; mouseEvent.globalY = input->GetMousePosition().y_; mouseEvent.modifiers = eventData[Urho3D::MouseWheel::P_QUALIFIERS].GetInt(); for (auto current = heldKeys.Begin(); current != heldKeys.End(); ++ current) mouseEvent.heldKeys.Push((*current).first_); mouseEvent.handled = false; mouseEvent.timestamp = framework->Frame()->WallClockTime(); TriggerMouseEvent(mouseEvent); return; } else if (eventType == Urho3D::E_TOUCHBEGIN) { UpdateTouchPoints(); TouchBegin.Emit(eventData); return; } else if (eventType == Urho3D::E_TOUCHMOVE) { UpdateTouchPoints(); TouchUpdate.Emit(eventData); return; } else if (eventType == Urho3D::E_TOUCHEND) { UpdateTouchPoints(); TouchEnd.Emit(eventData); return; } // ~switch }
KeySequence InputAPI::KeyBinding(const String &actionName) const { auto iter = keyboardMappings.Find(actionName); return iter != keyboardMappings.End() ? iter->second_ : KeySequence(); }