LRESULT GEN::GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam) { // Route Windows messages to game engine member functions switch (msg) { case WM_SETFOCUS: // Activate the game and update the Sleep status GameActivate(hWindow); SetSleep(FALSE); return 0; case WM_KILLFOCUS: // Deactivate the game and update the Sleep status GameDeactivate(hWindow); SetSleep(TRUE); return 0; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC = BeginPaint(hWindow, &ps); // Paint the game GamePaint(hDC); EndPaint(hWindow, &ps); return 0; case MM_MCINOTIFY: if (LOWORD(wParam) == MCI_NOTIFY_SUCCESSFUL) { if (GetMIDIPlayer() != nullptr) GetMIDIPlayer()->Restart(hWindow); } return 0; // Mouse Input Cases case WM_LBUTTONDOWN: // handle mouse button MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE); return 0; case WM_LBUTTONUP: MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE); return 0; case WM_RBUTTONDOWN: MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE); return 0; case WM_RBUTTONUP: MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE); return 0; case WM_MOUSEMOVE: MouseMove(LOWORD(lParam), HIWORD(lParam)); return 0; } return DefWindowProc(hWindow, msg, wParam, lParam); }
VOID ClickMouseLoc(PCHAR szMouseLoc, PCHAR szButton) { CHAR szArg1[MAX_STRING] = {0}; CHAR szArg2[MAX_STRING] = {0}; int ClickX; //actual location to click, calculated from ButtonX int ClickY; //actual location to click, calculated from ButtonY // determine mouse location - x and y given if ((szMouseLoc[0]=='+') || (szMouseLoc[0]=='-') || ((szMouseLoc[0]>='0') && (szMouseLoc[0]<='9'))) { // x and y were given so lets convert them and move mouse GetArg(szArg1,szMouseLoc,1); GetArg(szArg2,szMouseLoc,2); ClickX = atoi(szArg1); ClickY = atoi(szArg2); if ((szArg1[0]=='+') || (szArg1[0]=='-') || (szArg2[0]=='+') || (szArg2[0]=='-')) { // relative location was passed so offset from current ClickX += EQADDR_MOUSE->X; ClickY += EQADDR_MOUSE->Y; DebugSpew("Clicking mouse by relative offset"); } else { DebugSpew("Clicking mouse at absolute position"); } MouseButtonUp(ClickX,ClickY,szButton); } else { MacroError("'%s' mouse click is either invalid or should be done using /notify",szMouseLoc); } }
void BaseScene::ProcessEvents() { SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: QuitEvent(); break; case SDL_MOUSEMOTION: MouseMotion(event.motion); break; case SDL_MOUSEBUTTONDOWN: MouseButtonDown(event.button); break; case SDL_MOUSEBUTTONUP: MouseButtonUp(event.button); break; case SDL_KEYDOWN: KeyDown(event.key); break; case SDL_KEYUP: KeyUp(event.key); break; //TODO: joystick and controller events } } }
bool basic_mouse_handler::eventFilter(QObject* target, QEvent* ev) { // !m_target is for future proofing when gsrender isn't automatically initialized on load to ensure events still occur // !m_target->isVisible() is a hack since currently a guiless application will STILL inititialize a gsrender (providing a valid target) if (!m_target || !m_target->isVisible() || target == m_target) { switch (ev->type()) { case QEvent::MouseButtonPress: MouseButtonDown(static_cast<QMouseEvent*>(ev)); break; case QEvent::MouseButtonRelease: MouseButtonUp(static_cast<QMouseEvent*>(ev)); break; case QEvent::MouseMove: MouseMove(static_cast<QMouseEvent*>(ev)); break; case QEvent::Wheel: MouseScroll(static_cast<QWheelEvent*>(ev)); break; default: return false; } } return false; }
void CEngine::HandleInput() { SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: if(event.key.keysym.sym == SDLK_ESCAPE) { m_bQuit = true; break; } KeyDown(event.key.keysym.sym); break; case SDL_KEYUP: KeyUp(event.key.keysym.sym); break; case SDL_QUIT: m_bQuit = true; break; case SDL_MOUSEMOTION: MouseMoved(event.button.button, event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); break; case SDL_MOUSEBUTTONUP: MouseButtonUp(event.button.button, event.motion.x, event.motion.y, event.motion.xrel,event.motion.yrel); break; case SDL_ACTIVEEVENT: if(event.active.state & SDL_APPACTIVE) { if(event.active.gain) { m_bMinimized = false; WindowActive(); } else { m_bMinimized = true; WindowInactive(); } } break; } } }
void BaseScene::HandleEvents() { SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: QuitEvent(); break; case SDL_VIDEORESIZE: SetScreen(event.resize.w, event.resize.h, 0, screen->flags); break; case SDL_MOUSEMOTION: MouseMotion(event.motion); break; case SDL_MOUSEBUTTONDOWN: MouseButtonDown(event.button); break; case SDL_MOUSEBUTTONUP: MouseButtonUp(event.button); break; case SDL_KEYDOWN: KeyDown(event.key); break; case SDL_KEYUP: KeyUp(event.key); break; #ifdef USE_EVENT_JOYSTICK //TODO: joystick/gamepad support #endif #ifdef USE_EVENT_UNKNOWN default: UnknownEvent(event); break; #endif }//switch }//while }
LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam) { //Route Windows messages to game engine member fucntions switch (msg) { case WM_CREATE: //Set the game window and start the game SetWindow(hWindow); GameStart(hWindow); return 0; case WM_ACTIVATE: //Activate and deactivate the game and update the Sleep status if (wParam != WA_INACTIVE) { GameActivate(hWindow); SetSleep(FALSE); } else { GameDeactivate(hWindow); SetSleep(TRUE); } return 0; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC = BeginPaint(hWindow, &ps); //Paint the game GamePaint(hDC); EndPaint(hWindow, &ps); return 0; case WM_LBUTTONDOWN: //Handle left mouse button press MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE); return 0; case WM_LBUTTONUP: //Handle left mouse button release MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE); return 0; case WM_RBUTTONDOWN: //Handle right mouse button press MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE); return 0; case WM_RBUTTONUP: //Handle right mouse button release MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE); return 0; case WM_MOUSEMOVE: //Handle mouse movement MouseMove(LOWORD(lParam), HIWORD(lParam)); return 0; case WM_DESTROY: //End the game and exit the application GameEnd(); PostQuitMessage(0); return 0; } return DefWindowProc(hWindow, msg, wParam, lParam); }
/** Handles all controller inputs. @remark This function is called once per frame. **/ void CEngine::HandleInput() { // Poll for events, and handle the ones we care about. SDL_Event event; while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case SDL_KEYDOWN: // If escape is pressed set the Quit-flag if (event.key.keysym.sym == SDLK_ESCAPE) { m_bQuit = true; break; } KeyDown( event.key.keysym.sym ); break; case SDL_KEYUP: KeyUp( event.key.keysym.sym ); break; case SDL_QUIT: m_bQuit = true; break; case SDL_MOUSEMOTION: MouseMoved( event.button.button, event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); break; case SDL_MOUSEBUTTONUP: MouseButtonUp( event.button.button, event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); break; case SDL_MOUSEBUTTONDOWN: MouseButtonDown( event.button.button, event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); break; case SDL_ACTIVEEVENT: if ( event.active.state & SDL_APPACTIVE ) { if ( event.active.gain ) { m_bMinimized = false; WindowActive(); } else { m_bMinimized = true; WindowInactive(); } } break; } // switch } // while (handling input) }
void AllegroEngine::Run() { ALLEGRO_EVENT ev; while (!quit) { al_wait_for_event(event_queue, &ev); switch (ev.type) { /* ALLEGRO_EVENT_KEY_DOWN - a keyboard key was pressed. * The three keyboard event fields we use here are: * * keycode -- an integer constant representing the key, e.g. * AL_KEY_ESCAPE; * * unichar -- the Unicode character being typed, if any. This can * depend on the modifier keys and previous keys that were * pressed, e.g. for accents. * * modifiers -- a bitmask containing the state of Shift/Ctrl/Alt, etc. * keys. */ case ALLEGRO_EVENT_KEY_DOWN: if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) quit = true; KeyDown(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers); break; /* ALLEGRO_EVENT_KEY_REPEAT - a keyboard key was held down long enough to * 'repeat'. This is a useful event if you are working on something * that requires typed input. The repeat rate should be determined * by the operating environment the program is running in. */ case ALLEGRO_EVENT_KEY_CHAR: KeyDown(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers, ev.keyboard.repeat); break; /* ALLEGRO_EVENT_KEY_UP - a keyboard key was released. * Note that the unichar field is unused for this event. */ case ALLEGRO_EVENT_KEY_UP: KeyUp(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers); break; /* ALLEGRO_EVENT_MOUSE_AXES - at least one mouse axis changed value. * The 'z' axis is for the scroll wheel. We also have a fourth 'w' * axis for mice with two scroll wheels. */ case ALLEGRO_EVENT_MOUSE_AXES: MouseMoved(ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz); break; /* ALLEGRO_EVENT_MOUSE_BUTTON_UP - a mouse button was pressed. * The axis fields are also valid for this event. */ case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: MouseButtonDown(ev.mouse.button, ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz); break; /* ALLEGRO_EVENT_MOUSE_BUTTON_UP - a mouse button was released. * The axis fields are also valid for this event. */ case ALLEGRO_EVENT_MOUSE_BUTTON_UP: MouseButtonUp(ev.mouse.button, ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz); break; /* ALLEGRO_EVENT_TIMER - a timer 'ticked'. * The `source' field in the event structure tells us which timer * went off, and the `count' field tells us the timer's counter * value at the time that the event was generated. It's not * redundant, because although you can query the timer for its * counter value, that value might have changed by the time you got * around to processing this event. */ case ALLEGRO_EVENT_TIMER: HandleTimers(ev.timer.source, ev.timer.count); break; /* ALLEGRO_EVENT_DISPLAY_CLOSE - the window close button was pressed. */ case ALLEGRO_EVENT_DISPLAY_CLOSE: quit = true; return; /*case ALLEGRO_EVENT_DISPLAY_SWITCH_IN: log_general("Switch In"); break; case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT: log_general("Switch Out"); break;*/ /* We received an event of some type we don't know about. * Just ignore it. */ default: break; } } }