TEST( Input, KeyInput ) { Input newInput = {}; Input oldInput = {}; newInput.keys[KEY_SPACE] = true; EXPECT_TRUE( KeyDown( &newInput, KEY_SPACE ) ); EXPECT_FALSE( KeyDown( &oldInput, KEY_SPACE ) ); EXPECT_TRUE( KeyPressed( &newInput, &oldInput, KEY_SPACE ) ); EXPECT_FALSE( KeyReleased( &newInput, &oldInput, KEY_SPACE ) ); oldInput.keys[KEY_SPACE] = true; EXPECT_TRUE( KeyDown( &newInput, KEY_SPACE ) ); EXPECT_TRUE( KeyDown( &oldInput, KEY_SPACE ) ); EXPECT_FALSE( KeyPressed( &newInput, &oldInput, KEY_SPACE ) ); EXPECT_FALSE( KeyReleased( &newInput, &oldInput, KEY_SPACE ) ); newInput.keys[KEY_SPACE] = false; EXPECT_FALSE( KeyDown( &newInput, KEY_SPACE ) ); EXPECT_TRUE( KeyDown( &oldInput, KEY_SPACE ) ); EXPECT_FALSE( KeyPressed( &newInput, &oldInput, KEY_SPACE ) ); EXPECT_TRUE( KeyReleased( &newInput, &oldInput, KEY_SPACE ) ); newInput.keys[KEY_ENTER] = true; EXPECT_TRUE( KeyDown( &newInput, KEY_ENTER ) ); EXPECT_FALSE( KeyDown( &oldInput, KEY_ENTER ) ); EXPECT_TRUE( KeyPressed( &newInput, &oldInput, KEY_ENTER ) ); EXPECT_FALSE( KeyReleased( &newInput, &oldInput, KEY_ENTER ) ); }
PyObject* LMF_KeyReleased(PyObject *self, PyObject *args){ int iKeyCode; if (!PyArg_ParseTuple(args, "i", &iKeyCode)) { ParsePyTupleError( __func__, __LINE__ ); return nullptr; } int iKeyUp = KeyReleased(iKeyCode); return Py_BuildValue("i", iKeyUp); }
/// Called by GLFW when a key event occurs void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { auto emu_window = GetEmuWindow(win); int keyboard_id = emu_window->keyboard_id; if (action == GLFW_PRESS) { emu_window->KeyPressed({key, keyboard_id}); } else if (action == GLFW_RELEASE) { emu_window->KeyReleased({key, keyboard_id}); } }
bool InputLayer::AnyReleased() const { for (int32_t i = 0; i < InputLayer::KEYCOUNT; ++i) { if (KeyReleased(i)) { return true; } } return false; }
void SugoiGame::PollEvents() { sr::Event event; while (m_window->PollEvent(event)) { switch (event.type) { case sr::Event::WINDOW_CLOSED: m_window->Close(); break; case sr::Event::KEY_PRESSED: KeyPressed(event.key.keyCode, event.key.alt, event.key.control, event.key.shift, event.key.system); break; case sr::Event::KEY_RELEASED: KeyReleased(event.key.keyCode, event.key.alt, event.key.control, event.key.shift, event.key.system); break; case sr::Event::MOUSE_PRESSED: if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_1) { MouseLeftPressed(); } else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_2) { MouseRightPressed(); } else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_3) { MouseMiddlePressed(); } break; case sr::Event::MOUSE_RELEASED: if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_1) { MouseLeftReleased(event.mouseClicked.x, event.mouseClicked.y); } else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_2) { MouseRightReleased(); } else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_3) { MouseMiddleReleased(); } break; case sr::Event::MOUSE_MOVED: MouseMoved(event.mouseMoved.x, event.mouseMoved.y); break; case sr::Event::MOUSE_SCROLLED: MouseScroll(event.mouseScrolled.xoffset, event.mouseScrolled.yoffset); break; } } }
void InputContext::TriggerKeyEvent(KeyEvent &key) { KeyEventSignalMap::iterator keySignal = registeredKeyEventSignals.find(key.keyCode); switch(key.eventType) { case KeyEvent::KeyPressed: // 1. First emit the generic KeyEventReceived signal that receives all event types for all key codes. emit KeyEventReceived(&key); // 2. Emit the event type -specific signal for all key codes. emit KeyPressed(&key); // 3. Emit the key code -specific signal for specific event. if (keySignal != registeredKeyEventSignals.end()) keySignal->second->OnKeyPressed(key); break; case KeyEvent::KeyDown: if (!IsKeyDownImmediate(key.keyCode)) break; // If we've received a keydown for a key we haven't gotten a corresponding press for before, ignore this event. emit KeyEventReceived(&key); // 1. emit KeyDown(&key); // 2. // if (keySignal != registeredKeyEventSignals.end()) // keySignal->second->OnKeyDown(key); // 3. break; case KeyEvent::KeyReleased: if (!IsKeyDownImmediate(key.keyCode)) break; // If we've received a keydown for a key we haven't gotten a corresponding press for before, ignore this event. emit KeyEventReceived(&key); // 1. emit KeyReleased(&key); // 2. if (keySignal != registeredKeyEventSignals.end()) keySignal->second->OnKeyReleased(key); // 3. break; default: assert(false); break; } // Update the buffered API. KeyPressInformation info; info.keyState = key.eventType; info.keyPressCount = key.keyPressCount; // info.firstPressTime = key.firstPressTime; newKeyEvents[key.keyCode] = info; // Now if this layer is registered to suppress this keypress from being processed further, // mark it handled. if (suppressedKeys.find(key.keyCode) != suppressedKeys.end()) key.handled = true; }
BOOL CConfigShortcuts::PreTranslateMessage(MSG* pMsg) { if (GetFocus() == GetDlgItem(IDC_KEY)) { switch (pMsg->message) { case WM_KEYDOWN: case WM_SYSKEYDOWN: KeyPressed(pMsg->wParam); return TRUE; case WM_KEYUP: case WM_SYSKEYUP: KeyReleased(pMsg->wParam); return TRUE; } } return CPropertyPage::PreTranslateMessage(pMsg); }
bool CUICustomEdit::OnKeyboard(int dik, EUIMessages keyboard_action) { if(!m_bInputFocus) return false; if(keyboard_action == WINDOW_KEY_PRESSED) { m_iKeyPressAndHold = dik; m_bHoldWaitMode = true; if(KeyPressed(dik)) return true; } else if(keyboard_action == WINDOW_KEY_RELEASED) { if(m_iKeyPressAndHold == dik) { m_iKeyPressAndHold = 0; m_bHoldWaitMode = false; } if(KeyReleased(dik)) return true; } return false; }
void C_Mod::loop() { continuer = true; click = keyboard = false; bool clickOnUI = false; sf::Clock camTimer; float previousX = 0, previousY = 0; sf::String str_fps; int compt_fps = 0; sf::Clock timer_fps; str_fps.SetScale(0.4f, 0.4f); str_fps.SetColor(sf::Color::White); str_fps.SetPosition(10, 10); _screen->PreserveOpenGLStates(true); while(continuer) { while(_screen->GetEvent(_event)) { ///EVENT if(_event.Type == sf::Event::Closed) continuer = false; else if(_event.Type == sf::Event::MouseButtonReleased && click) { click = false; float xxx = _screen->GetInput().GetMouseX(); float yyy = _screen->GetInput().GetMouseY(); for(unsigned int i=0;i<_widget.size();i++) _widget[i]->clicked(xxx, yyy); MouseReleased(); } else if(_event.Type == sf::Event::MouseButtonPressed) { click = true; clickOnUI = false; previousX = _screen->GetInput().GetMouseX(); previousY = _screen->GetInput().GetMouseY(); for(unsigned int i=0;i<_widget.size();i++) { if(_widget[i]->mouseOver(previousX, previousY)) { clickOnUI = true; break; } } if(!clickOnUI) _cam->SetMousePosition(previousX, previousY); MousePressed(); } else if(_event.Type == sf::Event::MouseMoved) { _cam->OnMouseMotion(_screen->GetInput().GetMouseX(), _screen->GetInput().GetMouseY()); _screen->SetCursorPosition(_screen->GetWidth()/2, _screen->GetHeight()/2); MouseMoved(); } else if(_event.Type == sf::Event::MouseWheelMoved) { MouseWheel(); _event.MouseWheel.Delta = 0; } else if(_event.Type == sf::Event::KeyPressed) { bool wigdetHasFocus = false; for(unsigned int i=0;i<_widget.size();i++) { if(_widget[i]->injectKey(_event.Key.Code, true)) { wigdetHasFocus = true; break; } } if(!wigdetHasFocus) { keyboard = true; _cam->OnKeyboard(_event); KeyPressed(); } } else if(_event.Type == sf::Event::KeyReleased) { for(unsigned int i=0;i<_widget.size();i++) _widget[i]->injectKey(_event.Key.Code, false); //if(keyboard) { keyboard = false; _cam->OnKeyboard(_event); KeyReleased(); } } } glDisable(GL_LIGHTING); _cam->animate(int(camTimer.GetElapsedTime()*10000)); camTimer.Reset(); TimerManagement(); ///DRAW _screen->SetActive(); if(click && !clickOnUI) _screen->SetCursorPosition(previousX, previousY); //_screen->GetWidth()/2, _screen->GetHeight()/2); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glViewport(0, 0, _screen->GetWidth(), _screen->GetHeight()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, float(_screen->GetWidth()) / float(_screen->GetHeight()), 0.1f, 5000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); _skydome.Draw(); _cam->look(); glPushMatrix(); Draw(); glPopMatrix(); DrawUI(); if(timer_fps.GetElapsedTime() > 1.0f) { str_fps.SetText("FPS : "+IntToString(compt_fps)); compt_fps = 0; timer_fps.Reset(); } compt_fps++; _screen->Draw(str_fps); _screen->Display(); } }
void Events::onEvent(SDL_Event * Event) { switch (Event->type) { case SDL_ACTIVEEVENT: { switch (Event->active.state) { case SDL_APPMOUSEFOCUS: { if (Event->active.gain) MouseFocus(); else MouseBlur(); break; } case SDL_APPINPUTFOCUS: { if (Event->active.gain) InputFocus(); else InputBlur(); break; } case SDL_APPACTIVE: { if (Event->active.gain) Restore(); else Minimaze(); break; } default: break; } } case SDL_KEYDOWN: { KeyPressed(Event->key.keysym.sym, Event->key.keysym.mod, Event->key.keysym.unicode); break; } case SDL_KEYUP: { KeyReleased(Event->key.keysym.sym, Event->key.keysym.mod, Event->key.keysym.unicode); break; } case SDL_MOUSEMOTION: { MouseMove(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_MIDDLE), Event->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)); break; } case SDL_MOUSEBUTTONDOWN: { switch (Event->button.button) { case SDL_BUTTON_LEFT: { LMBPressed(Event->button.x, Event->button.y); break; } case SDL_BUTTON_MIDDLE: { MMBPressed(Event->button.x, Event->button.y); break; } case SDL_BUTTON_RIGHT: { RMBPressed(Event->button.x, Event->button.y); break; } default: break; } } case SDL_MOUSEBUTTONUP: { switch (Event->button.button) { case SDL_BUTTON_LEFT: { LMBReleased(Event->button.x, Event->button.y); break; } case SDL_BUTTON_MIDDLE: { MMBReleased(Event->button.x, Event->button.y); break; } case SDL_BUTTON_RIGHT: { RMBReleased(Event->button.x, Event->button.y); break; } default: break; } } case SDL_JOYAXISMOTION: { break; } case SDL_JOYBALLMOTION: { break; } case SDL_JOYHATMOTION: { break; } case SDL_JOYBUTTONDOWN: { break; } case SDL_JOYBUTTONUP: { break; } case SDL_QUIT: { QuitEv(); break; } case SDL_SYSWMEVENT: { SystemWM(); break; } case SDL_VIDEORESIZE: { ResizeEv(Event->resize.w, Event->resize.h); break; } case SDL_VIDEOEXPOSE: { ExposeEv(); break; } default: { UserEv(Event->user.code, Event->user.data1, Event->user.data2); break; } } }
void GLScene::keyReleaseEvent( QKeyEvent* event ) { emit KeyReleased(event); }
// A keyboard key was released. void GraphicsWindow::OnKeyReleased( KeyEventArgs& e ) { KeyReleased( e ); }
void KeyboardControls::SpecialReleased(int keyCode){ KeyReleased(keyCode, true); }
void KeyboardControls::CharReleased(unsigned char keyChar){ KeyReleased(keyChar, false); }