void QueryServersUserInterface::onControllerButtonDown(U32 buttonIndex) { if(buttonIndex == 0) onKeyDown('\r'); else if(buttonIndex == 1) onKeyDown(27); }
void InputHandler::update() { SDL_Event evt; onMouseButtonUp(); while (SDL_PollEvent(&evt)) { switch (evt.type) { case SDL_QUIT: TheGame::Instance()->quit(); break; case SDL_MOUSEMOTION: onMouseMove(evt); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(evt); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
void InputSystem::handleEvent(Event *event) { switch(event->getType()) { case Event::KeyUp: onKeyUp(static_cast<KeyEvent*> (event)); break; case Event::KeyDown: onKeyDown(static_cast<KeyEvent*> (event)); break; case Event::MouseLeave: mouseControl = false; { Player *player = game->getPlayer(); if(player) { Vector2 velocity = player->getVelocity(); velocity.x = 0.0f; player->setVelocity(velocity); } } break; case Event::MouseMove: onMouseMove(static_cast<MouseMoveEvent*> (event)); break; default: // Do nothing break; } }
void OsuPauseMenu::update() { if (!m_bVisible) return; // update and focus handling m_container->update(); if (m_osu->getOptionsMenu()->isMouseInside()) m_container->stealFocus(); if (m_bScheduledVisibilityChange) { m_bScheduledVisibilityChange = false; setVisible(m_bScheduledVisibility); } if (anim->isAnimating(&m_fWarningArrowsAnimX)) m_fWarningArrowsAnimStartTime = engine->getTime(); // HACKHACK: handle joystick mouse select, inject enter keydown if (env->getOS() == Environment::OS::OS_HORIZON) { if (engine->getMouse()->isLeftDown()) { KeyboardEvent e(KEY_ENTER); onKeyDown(e); } } }
bool WebPluginScrollbarImpl::handleInputEvent(const WebInputEvent& event) { switch (event.type) { case WebInputEvent::MouseDown: return onMouseDown(event); case WebInputEvent::MouseUp: return onMouseUp(event); case WebInputEvent::MouseMove: return onMouseMove(event); case WebInputEvent::MouseLeave: return onMouseLeave(event); case WebInputEvent::MouseWheel: return onMouseWheel(event); case WebInputEvent::KeyDown: return onKeyDown(event); case WebInputEvent::Undefined: case WebInputEvent::MouseEnter: case WebInputEvent::RawKeyDown: case WebInputEvent::KeyUp: case WebInputEvent::Char: case WebInputEvent::TouchStart: case WebInputEvent::TouchMove: case WebInputEvent::TouchEnd: case WebInputEvent::TouchCancel: default: break; } return false; }
LRESULT Win32Window::wndProc(UINT msg, WPARAM wParam, LPARAM lParam) { if(msg == WM_CLOSE) { PostQuitMessage(0); } switch(msg) { case WM_SIZE: onResize(ResizeEvent(LOWORD(lParam), HIWORD(lParam))); break; case WM_KEYDOWN: onKeyDown(KeyEvent(wParam)); break; case WM_KEYUP: onKeyUp(KeyEvent(wParam)); break; case WM_MOUSEMOVE: POINTS pt = MAKEPOINTS(lParam); break; } return DefWindowProc(hwnd, msg, wParam, lParam); }
void InputHandler::update() { SDL_Event event; m_keyStates = SDL_GetKeyboardState(0); while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: // se o usuário saiu da aplicação TheGame::Instance()->quit(); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
void WorldMap::handle(Event::Event* event) { auto game = Game::getInstance(); if (auto mouseEvent = dynamic_cast<Event::Mouse*>(event)) { auto mouse = game->mouse(); // Left button down if (mouseEvent->name() == "mousedown" && mouseEvent->leftButton()) { // check if point clicked belongs to the screen if ((mapMinX<=(unsigned int)mouse->x()) && ((unsigned int)mouse->x()<=(mapMinX+mapWidth)) && (mapMinY<=(unsigned int)mouse->y()) && ((unsigned int)mouse->y()<=(mapMinY+mapHeight))) { // change destination point worldMapX = mouse->x()+deltaX-mapMinX; worldMapY = mouse->y()+deltaY-mapMinY; } } } if (auto keyboardEvent = dynamic_cast<Event::Keyboard*>(event)) { if (keyboardEvent->name() == "keydown") onKeyDown(keyboardEvent); } }
/** * @brief FilterWidget::FilterWidget * @param parent */ FilterWidget::FilterWidget(QWidget *parent) : QWidget(parent), ui(new Ui::FilterWidget) { ui->setupUi(this); ui->lineEdit->setShowMagnifier(true); ui->lineEdit->addAdditionalStyleSheet("QLineEdit { border: 1px solid rgba(0, 0, 0, 100); border-radius: 10px; }"); ui->lineEdit->setType(MyLineEdit::TypeClear); ui->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); m_list = new QListWidget(); m_list->setWindowFlags(Qt::WindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)); m_list->setAttribute(Qt::WA_ShowWithoutActivating); m_activeWidget = WidgetMovies; QPalette palette = m_list->palette(); palette.setColor(QPalette::Highlight, palette.color(QPalette::Highlight)); palette.setColor(QPalette::HighlightedText, palette.color(QPalette::HighlightedText)); m_list->setPalette(palette); m_list->setStyleSheet(QString("background-color: transparent; border: 1px solid rgba(255, 255, 255, 200); border-radius: 5px;")); m_list->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); connect(ui->lineEdit, SIGNAL(textEdited(QString)), this, SLOT(onFilterTextChanged(QString))); connect(ui->lineEdit, SIGNAL(keyDown()), this, SLOT(onKeyDown())); connect(ui->lineEdit, SIGNAL(keyUp()), this, SLOT(onKeyUp())); connect(ui->lineEdit, SIGNAL(focusOut()), m_list, SLOT(hide())); connect(ui->lineEdit, SIGNAL(focusIn()), this, SLOT(setupFilters())); connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(addSelectedFilter())); connect(ui->lineEdit, SIGNAL(backspaceInFront()), this, SLOT(removeLastFilter())); connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(addFilterFromItem(QListWidgetItem*))); initFilters(); }
void SdlApp::handleInput() { SDL_Event sdlEvent; while (SDL_PollEvent(&sdlEvent) != 0) { if (sdlEvent.type == SDL_QUIT) setExitFlag(); else if (sdlEvent.type == SDL_KEYDOWN) onKeyDown(sdlEvent.key.keysym.sym); else if (sdlEvent.type == SDL_WINDOWEVENT) { switch (sdlEvent.window.event) { case SDL_WINDOWEVENT_RESIZED: // Handle resize mWindowWidth = sdlEvent.window.data1; mWindowHeight = sdlEvent.window.data2; onResize(mWindowWidth, mWindowHeight); break; case SDL_WINDOWEVENT_EXPOSED: draw(); } } } }
LRESULT Window::wndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: { if (onCreate()) break; return 0; } case WM_DESTROY: { if (onDestroy()) break; return 0; } case WM_CLOSE: { if (onClose()) break; return 0; } case WM_MOUSEMOVE: { if (onMouseMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) break; return 0; } case WM_LBUTTONDOWN: { if (onMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0)) break; return 0; } case WM_RBUTTONDOWN: { if (onMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 1)) break; return 0; } case WM_MBUTTONDOWN: { if (onMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 2)) break; return 0; } case WM_LBUTTONUP: { if (onMouseUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0)) break; return 0; } case WM_RBUTTONUP: { if (onMouseUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 1)) break; return 0; } case WM_MBUTTONUP: { if (onMouseUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 2)) break; return 0; } case WM_PAINT: { if (onPaint()) break; return 0; } case WM_SIZE: { if (onSizeChanged()) break; return 0; } case WM_KEYDOWN: { if (onKeyDown((UINT)wParam)) break; return 0; } case WM_KEYUP: { if (onKeyUp((UINT)wParam)) break; return 0; } case WM_COMMAND: { if (SendMessage(reinterpret_cast<HWND>(lParam), WM_COMMAND_REFLECT, wParam, lParam)) break; return 0; } } if (mBaseWndProc != sGlobalWndProc) { LRESULT r = CallWindowProc(mBaseWndProc, mHWND, uMsg, wParam, lParam); return r; } else { LRESULT r = DefWindowProc(mHWND, uMsg, wParam, lParam); return r; } }
// Simple main loop void mainLoop() { // Window is not minimized bool active = true; for(;;)// Infinite loop { SDL_Event event; // Wait for event if(SDL_WaitEvent(&event) == 0) throw SDL_Exception(); // Screen needs redraw bool redraw = false; // Handle all waiting events do { camera += cam_velocity; // Call proper event handlers switch(event.type) { case SDL_ACTIVEEVENT : // Stop redraw when minimized if(event.active.state == SDL_APPACTIVE) active = event.active.gain; break; case SDL_KEYDOWN : onKeyDown(event.key.keysym.sym, event.key.keysym.mod); break; case SDL_KEYUP : onKeyUp(event.key.keysym.sym, event.key.keysym.mod); break; case SDL_MOUSEMOTION : onMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, event.motion.state); break; case SDL_MOUSEBUTTONDOWN : onMouseDown(event.button.button, event.button.x, event.button.y); break; case SDL_MOUSEBUTTONUP : onMouseUp(event.button.button, event.button.x, event.button.y); break; case SDL_QUIT : return; // End main loop case SDL_VIDEORESIZE : onWindowResized(event.resize.w, event.resize.h); break; case SDL_VIDEOEXPOSE : redraw = true; break; default : // Do nothing break; } } while(SDL_PollEvent(&event) == 1); // Optionally redraw window if(active && redraw) onWindowRedraw(); } }
void JoltApp::onEvent(SDL_Event* evt) { //JoltConsole::logInfo("Event", "Caught event code %i",evt->type); if(evt->type == SDL_QUIT) { running = false; //We're outta here! } else if(evt->type == SDL_KEYDOWN) { onKeyDown(evt->key.keysym.sym,evt->key.keysym.mod,evt->key.keysym.unicode); } else if(evt->type == SDL_KEYUP) { onKeyUp(evt->key.keysym.sym,evt->key.keysym.mod,evt->key.keysym.unicode); } }
void InputHandler::update() { //SDL_Event event; if (event.type != SDL_MOUSEMOTION) { MouseMoved = false; } while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: TheGame::Instance()->quit(); break; case SDL_JOYAXISMOTION: onJoystickAxisMove(event); break; case SDL_JOYBUTTONDOWN: onJoystickButtonDown(event); break; case SDL_JOYBUTTONUP: onJoystickButtonUp(event); break; case SDL_MOUSEMOTION: MouseMoved = true; onMouseMove(event); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(event); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(event); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
TEST_F(KeyBehaviorTest, FromOneKeyToAnother) { auto behavior = std::make_shared<MockKeyBehavior>("Behavior"); EXPECT_CALL(*behavior, onKeyDown(Devices::KEY_A)); EXPECT_CALL(*behavior, onKeyDown(Devices::KEY_B)); EXPECT_CALL(*behavior, onKeyUp(Devices::KEY_A)); EXPECT_CALL(*behavior, onKeyUp(Devices::KEY_B)); behavior->setInputComponent(inputComponent); element->addComponent(behavior); data.integers().set(DataStructures::Names::KEY, Devices::KeyCode::KEY_A); inputComponent->setData(data); behavior->update(0.0); data.integers().set(DataStructures::Names::KEY, Devices::KeyCode::KEY_B); inputComponent->setData(data); behavior->update(0.0); data.integers().set(DataStructures::Names::KEY, Devices::KeyCode::NONE); inputComponent->setData(data); behavior->update(0.0); // Shouldn't trigger another KeyUp .. behavior->update(0.0); }
void InputHandler::update() { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: Game::getInstance()->clean(); break; case SDL_JOYAXISMOTION: onJoystickAxisMove(event); break; case SDL_JOYBUTTONDOWN: onJoystickButtonDown(event); break; case SDL_JOYBUTTONUP: onJoystickButtonUp(event); break; case SDL_MOUSEMOTION: onMouseMove(event); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(event); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(event); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
//------------------------------------------------------------------------------------------------------------------------------------------ // //------------------------------------------------------------------------------------------------------------------------------------------ void Window::onInputEvent( const Message& message ) { switch( message.type ) { case mtKeyDown: { const MessageKeyDown* messagePointer = static_cast<const MessageKeyDown*>(&message); NOTIFY_LISTENERS( onKeyDown( this, messagePointer->keyCode ) ); break; } case mtPointerButtonUp: NOTIFY_LISTENERS( onClick( this ) ); break; } }
void ManejadorEntrada::actualizar() { SDL_Event evento; while(SDL_PollEvent(&evento)) { switch (evento.type) { case SDL_QUIT: ElJuego::Instancia()->salir(); break; case SDL_JOYAXISMOTION: onJoystickAxisMove(evento); break; case SDL_JOYBUTTONDOWN: onJoystickButtonDown(evento); break; case SDL_JOYBUTTONUP: onJoystickButtonUp(evento); break; case SDL_MOUSEMOTION: onMouseMove(evento); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(evento); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(evento); break; case SDL_KEYDOWN: onKeyDown(); break; case SDL_KEYUP: onKeyUp(); break; default: break; } } }
void CPP_Input::setImpl(std::unique_ptr<CPP_InputImplIF> _impl) { impl = std::move(_impl); if (impl) { impl->registerOnKeyDown([this](const CPP_Key key) { onKeyDown(key); }); impl->registerOnKeyUp([this](const CPP_Key key) { onKeyUp(key); }); } }
LRESULT WebPopupMenuProxyWin::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT lResult = 0; bool handled = true; switch (message) { case WM_MOUSEACTIVATE: lResult = onMouseActivate(hWnd, message, wParam, lParam, handled); break; case WM_SIZE: lResult = onSize(hWnd, message, wParam, lParam, handled); break; case WM_KEYDOWN: lResult = onKeyDown(hWnd, message, wParam, lParam, handled); break; case WM_CHAR: lResult = onChar(hWnd, message, wParam, lParam, handled); break; case WM_MOUSEMOVE: lResult = onMouseMove(hWnd, message, wParam, lParam, handled); break; case WM_LBUTTONDOWN: lResult = onLButtonDown(hWnd, message, wParam, lParam, handled); break; case WM_LBUTTONUP: lResult = onLButtonUp(hWnd, message, wParam, lParam, handled); break; case WM_MOUSEWHEEL: lResult = onMouseWheel(hWnd, message, wParam, lParam, handled); break; case WM_PAINT: lResult = onPaint(hWnd, message, wParam, lParam, handled); break; case WM_PRINTCLIENT: lResult = onPrintClient(hWnd, message, wParam, lParam, handled); break; default: handled = false; break; } if (!handled) lResult = ::DefWindowProc(hWnd, message, wParam, lParam); return lResult; }
LRESULT MenuCaptureWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled){ switch(uMsg) { case WM_KILLFOCUS: onKillFocus(uMsg,wParam,lParam); bHandled = true; break; case WM_KEYDOWN: onKeyDown(uMsg,wParam,lParam); bHandled = true; break; default: bHandled = false; } return 0L; }
void Game::handleEvent( const SDL_Event& e ) { switch( e.type ) { case SDL_QUIT: running_ = false; break; case SDL_KEYDOWN: onKeyDown( e.key.keysym.sym ); break; case SDL_KEYUP: onKeyUp( e.key.keysym.sym ); break; case SDL_MOUSEBUTTONDOWN: int x, y; SDL_GetMouseState( &x, &y ); onMouseDown( Vec2( x, y ) ); break; } }
bool geGUIBase::KeyDown(int charValue, int flag) { if(m_uGUIID==GEGUI_LAYOUT && getActiveWindowPtrOnlyForLayout()) //layout hack { if(getActiveWindowPtrOnlyForLayout()->KeyDown(charValue, flag)) return true; } else { for(std::vector<geGUIBase*>::iterator it = m_vControls.begin(); it != m_vControls.end(); ++it) { geGUIBase* obj = *it; if(obj->KeyDown(charValue, flag)) return true; } } return onKeyDown(charValue, flag); }
void State::handle(Event* event) { if (event->handled()) return; if (auto keyboardEvent = dynamic_cast<KeyboardEvent*>(event)) { if (keyboardEvent->name() == "keydown") { onKeyDown(keyboardEvent); } } for (auto it = _ui.rbegin(); it != _ui.rend(); ++it) { if (event->handled()) return; if (auto activeUI = dynamic_cast<ActiveUI*>(*it)) { activeUI->handle(event); } } }
void LangtonApp::OnEvent(SDL_Event* event) { switch (event->type) { case SDL_QUIT: running = false; break; case SDL_KEYDOWN: onKeyDown(&event->key); break; case SDL_MOUSEWHEEL: squareSize -= event->wheel.y; if (squareSize < 1) squareSize = 1; case SDL_MOUSEBUTTONDOWN: if (event->button.button == SDL_BUTTON_LEFT) { mouseDown = true; mousestartx = event->button.x; mousestarty = event->button.y; } break; case SDL_MOUSEBUTTONUP: if (event->button.button == SDL_BUTTON_LEFT) mouseDown = false; break; case SDL_MOUSEMOTION: if (mouseDown) { tracking = false; int rx = mousestartx - event->button.x; int ry = mousestarty - event->button.y; if (ABS(rx) > squareSize) { centreX += rx / squareSize; mousestartx -= rx; } if (ABS(ry) > squareSize) { centreY -= ry / squareSize; mousestarty -= ry; } } break; default: break; } }
void InputHandler::update() { SDL_Event event; m_keyStates = (Uint8*)SDL_GetKeyboardState(0); while(SDL_PollEvent(&event)){ switch (event.type) { case SDL_QUIT: TheGame::Instance() -> quit(); break; case SDL_JOYAXISMOTION: onJoystickAxisMove(event); break; case SDL_JOYBUTTONDOWN: onJoystickButtonDown(event); break; case SDL_JOYBUTTONUP: onJoystickButtonUp(event); break; case SDL_MOUSEMOTION: onMouseMove(event); break; case SDL_MOUSEBUTTONDOWN: onMouseButtonDown(event); break; case SDL_MOUSEBUTTONUP: onMouseButtonUp(event); break; case SDL_KEYDOWN: onKeyDown(event.key.keysym.scancode); break; case SDL_KEYUP: onKeyUp(event.key.keysym.scancode); break; default: break; } } }
bool UIWidget::propagateOnKeyDown(uchar keyCode, int keyboardModifiers) { // do a backup of children list, because it may change while looping it UIWidgetList children; for(const UIWidgetPtr& child : m_children) { // events on hidden or disabled widgets are discarded if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible()) continue; // key events go only to containers or focused child if(child->isFocused()) children.push_back(child); } for(const UIWidgetPtr& child : children) { if(child->propagateOnKeyDown(keyCode, keyboardModifiers)) return true; } return onKeyDown(keyCode, keyboardModifiers); }
void Engine::proccessEvent(UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CLOSE: stop(); break; case WM_MOUSEMOVE: onMouseMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam); break; case WM_MOUSELEAVE: onMouseLeave(); break; case WM_MOUSEWHEEL: onMouseWheel(GET_WHEEL_DELTA_WPARAM(wParam)); break; case WM_KEYDOWN: onKeyDown(wParam); break; } }
void Module::onEvent(const SDL_Event & event) { switch(event.type) { case SDL_KEYDOWN: onKeyDown(event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.unicode); break; case SDL_KEYUP: onKeyUp(event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.unicode); break; case SDL_MOUSEMOTION: onMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, event.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT), event.motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT), event.motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE)); break; case SDL_JOYAXISMOTION: onJoyAxis(event.jaxis.which, event.jaxis.axis, event.jaxis.value); break; case SDL_JOYBALLMOTION: onJoyBall(event.jball.which, event.jball.ball, event.jball.xrel, event.jball.yrel); break; case SDL_JOYHATMOTION: onJoyHat(event.jhat.which, event.jhat.hat, event.jhat.value); break; case SDL_JOYBUTTONDOWN: onJoyButtonDown(event.jbutton.which, event.jbutton.button); break; case SDL_JOYBUTTONUP: onJoyButtonUp(event.jbutton.which, event.jbutton.button); break; case SDL_VIDEORESIZE: onResize(event.resize.w, event.resize.h); break; //case ... default: break; } }
void CButtons::run() { CTimeout tm; uint32_t newval; while(1) { newval = m_pins; if ( newval != m_flag ) { if ( tm.isExpired(10) ) { // wait for bounce time m_down = newval; for (int i=0; i<m_pins.count(); i++) { if ( bit_chk((m_flag ^ newval), i) ) { // is different? Key Even caused... if ( bit_chk(newval, i) ) { // HIGH is key up onKeyUp(i); } else { // LOW is key down onKeyDown(i); } } } m_flag = newval; } } else { tm.reset(); } } }