//Check for any window messages (keypress, paint, mousemove, etc) void CheckMessages() { SDL_Event ev; bool quit = false; if(HandleDPad()) { return; } lastchar_is_mouse = false; while(SDL_PollEvent(&ev)) { switch(ev.type) { case SDL_KEYDOWN: { int lc = 0; //hide mouse cursor on keyboard input if(OPTIONS["HIDE_CURSOR"] != "show" && SDL_ShowCursor(-1)) { SDL_ShowCursor(SDL_DISABLE); } Uint8 *keystate = SDL_GetKeyState(NULL); // manually handle Alt+F4 for older SDL lib, no big deal if( ev.key.keysym.sym == SDLK_F4 && (keystate[SDLK_RALT] || keystate[SDLK_LALT]) ) { quit = true; break; } else if( ev.key.keysym.sym == SDLK_RSHIFT || ev.key.keysym.sym == SDLK_LSHIFT || ev.key.keysym.sym == SDLK_RCTRL || ev.key.keysym.sym == SDLK_LCTRL || ev.key.keysym.sym == SDLK_RALT ) { break; // temporary fix for unwanted keys } else if( ev.key.keysym.sym == SDLK_LALT ) { begin_alt_code(); break; } else if( ev.key.keysym.unicode != 0 ) { lc = ev.key.keysym.unicode; switch (lc){ case 13: //Reroute ENTER key for compatilbity purposes lc=10; break; case 8: //Reroute BACKSPACE key for compatilbity purposes lc=127; break; } } if( ev.key.keysym.sym == SDLK_LEFT ) { lc = KEY_LEFT; } else if( ev.key.keysym.sym == SDLK_RIGHT ) { lc = KEY_RIGHT; } else if( ev.key.keysym.sym == SDLK_UP ) { lc = KEY_UP; } else if( ev.key.keysym.sym == SDLK_DOWN ) { lc = KEY_DOWN; } else if( ev.key.keysym.sym == SDLK_PAGEUP ) { lc = KEY_PPAGE; } else if( ev.key.keysym.sym == SDLK_PAGEDOWN ) { lc = KEY_NPAGE; } if( !lc ) { break; } if( alt_down ) { add_alt_code( lc ); } else { lastchar = lc; } lastchar_isbutton = false; } break; case SDL_KEYUP: { if( ev.key.keysym.sym == SDLK_LALT ) { int code = end_alt_code(); if( code ) { lastchar = code; } } } break; case SDL_JOYBUTTONDOWN: lastchar = ev.jbutton.button; lastchar_isbutton = true; break; case SDL_JOYAXISMOTION: // on gamepads, the axes are the analog sticks // TODO: somehow get the "digipad" values from the axes break; case SDL_MOUSEMOTION: if (OPTIONS["HIDE_CURSOR"] == "show" || OPTIONS["HIDE_CURSOR"] == "hidekb") { if (!SDL_ShowCursor(-1)) { SDL_ShowCursor(SDL_ENABLE); } // Only monitor motion when cursor is visible lastchar_is_mouse = true; lastchar = MOUSE_MOVE; } break; case SDL_MOUSEBUTTONUP: lastchar_is_mouse = true; if (ev.button.button == SDL_BUTTON_LEFT) { lastchar = MOUSE_BUTTON_LEFT; } else if (ev.button.button == SDL_BUTTON_RIGHT) { lastchar = MOUSE_BUTTON_RIGHT; } else if (ev.button.button == SDL_BUTTON_WHEELUP) { lastchar = SCROLLWHEEL_UP; } else if (ev.button.button == SDL_BUTTON_WHEELDOWN) { lastchar = SCROLLWHEEL_DOWN; } break; case SDL_QUIT: quit = true; break; } } #ifdef SDLTILES if (needupdate) { try_update(); } #endif if(quit) { endwin(); exit(0); } }
//Check for any window messages (keypress, paint, mousemove, etc) void CheckMessages() { SDL_Event ev; bool quit = false; if(HandleDPad()) { return; } lastchar_is_mouse = false; while(SDL_PollEvent(&ev)) { switch(ev.type) { case SDL_WINDOWEVENT: switch(ev.window.event) { case SDL_WINDOWEVENT_SHOWN: case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_RESTORED: needupdate = true; break; default: break; } break; case SDL_KEYDOWN: { int lc = 0; //hide mouse cursor on keyboard input if(OPTIONS["HIDE_CURSOR"] != "show" && SDL_ShowCursor(-1)) { SDL_ShowCursor(SDL_DISABLE); } const Uint8 *keystate = SDL_GetKeyboardState(NULL); // manually handle Alt+F4 for older SDL lib, no big deal if( ev.key.keysym.sym == SDLK_F4 && (keystate[SDL_SCANCODE_RALT] || keystate[SDL_SCANCODE_LALT]) ) { quit = true; break; } switch (ev.key.keysym.sym) { case SDLK_KP_ENTER: case SDLK_RETURN: case SDLK_RETURN2: lc = 10; break; case SDLK_BACKSPACE: case SDLK_KP_BACKSPACE: lc = 127; break; case SDLK_ESCAPE: lc = 27; break; case SDLK_TAB: lc = 9; break; case SDLK_RALT: case SDLK_LALT: begin_alt_code(); break; case SDLK_LEFT: lc = KEY_LEFT; break; case SDLK_RIGHT: lc = KEY_RIGHT; break; case SDLK_UP: lc = KEY_UP; break; case SDLK_DOWN: lc = KEY_DOWN; break; case SDLK_PAGEUP: lc = KEY_PPAGE; break; case SDLK_PAGEDOWN: lc = KEY_NPAGE; break; } if( !lc ) { break; } if( alt_down ) { add_alt_code( lc ); } else { lastchar = lc; } lastchar_isbutton = false; } break; case SDL_KEYUP: { if( ev.key.keysym.sym == SDLK_LALT || ev.key.keysym.sym == SDLK_RALT ) { int code = end_alt_code(); if( code ) { lastchar = code; } } } break; case SDL_TEXTINPUT: lastchar = *ev.text.text; break; case SDL_JOYBUTTONDOWN: lastchar = ev.jbutton.button; lastchar_isbutton = true; break; case SDL_JOYAXISMOTION: // on gamepads, the axes are the analog sticks // TODO: somehow get the "digipad" values from the axes break; case SDL_MOUSEMOTION: if (OPTIONS["HIDE_CURSOR"] == "show" || OPTIONS["HIDE_CURSOR"] == "hidekb") { if (!SDL_ShowCursor(-1)) { SDL_ShowCursor(SDL_ENABLE); } // Only monitor motion when cursor is visible lastchar_is_mouse = true; lastchar = MOUSE_MOVE; } break; case SDL_MOUSEBUTTONUP: lastchar_is_mouse = true; switch (ev.button.button) { case SDL_BUTTON_LEFT: lastchar = MOUSE_BUTTON_LEFT; break; case SDL_BUTTON_RIGHT: lastchar = MOUSE_BUTTON_RIGHT; break; } break; case SDL_MOUSEWHEEL: lastchar_is_mouse = true; if(ev.wheel.y > 0) { lastchar = SCROLLWHEEL_UP; } else if(ev.wheel.y < 0) { lastchar = SCROLLWHEEL_DOWN; } break; case SDL_QUIT: quit = true; break; } } #ifdef SDLTILES if (needupdate) { try_update(); } #endif if(quit) { endwin(); exit(0); } }