//This function processes any Windows messages we get. Keyboard, OnClose, etc LRESULT CALLBACK ProcessMessages(HWND__ *hWnd,unsigned int Msg, WPARAM wParam, LPARAM lParam) { uint16_t MouseOver; switch (Msg) { case WM_DEADCHAR: case WM_CHAR: lastchar = (int)wParam; switch (lastchar){ case VK_RETURN: //Reroute ENTER key for compatilbity purposes lastchar=10; break; case VK_BACK: //Reroute BACKSPACE key for compatilbity purposes lastchar=127; break; } return 0; case WM_KEYDOWN: //Here we handle non-character input switch (wParam){ case VK_LEFT: lastchar = KEY_LEFT; break; case VK_RIGHT: lastchar = KEY_RIGHT; break; case VK_UP: lastchar = KEY_UP; break; case VK_DOWN: lastchar = KEY_DOWN; break; case VK_NEXT: lastchar = KEY_NPAGE; break; case VK_PRIOR: lastchar = KEY_PPAGE; break; case VK_F1: lastchar = KEY_F(1); break; case VK_F2: lastchar = KEY_F(2); break; case VK_F3: lastchar = KEY_F(3); break; case VK_F4: lastchar = KEY_F(4); break; case VK_F5: lastchar = KEY_F(5); break; case VK_F6: lastchar = KEY_F(6); break; case VK_F7: lastchar = KEY_F(7); break; case VK_F8: lastchar = KEY_F(8); break; case VK_F9: lastchar = KEY_F(9); break; case VK_F10: lastchar = KEY_F(10); break; case VK_F11: lastchar = KEY_F(11); break; case VK_F12: lastchar = KEY_F(12); break; default: break; }; return 0; case WM_KEYUP: if (!GetAsyncKeyState(VK_LMENU) && alt_down){ // LeftAlt hack if (int code = end_alt_code()) lastchar = code; } return 0; case WM_SYSCHAR: add_alt_code((char)wParam); return 0; case WM_SYSKEYDOWN: if (GetAsyncKeyState(VK_LMENU) && !alt_down){ // LeftAlt hack begin_alt_code(); } break; case WM_SETCURSOR: MouseOver = LOWORD(lParam); if (OPTIONS["HIDE_CURSOR"] == "hide") { if (MouseOver==HTCLIENT && CursorVisible) { CursorVisible = false; ShowCursor(false); } else if (MouseOver!=HTCLIENT && !CursorVisible) { CursorVisible = true; ShowCursor(true); } } else if (!CursorVisible) { CursorVisible = true; ShowCursor(true); } break; case WM_ERASEBKGND: return 1; // Don't erase background case WM_PAINT: BitBlt(WindowDC, 0, 0, WindowWidth, WindowHeight, backbuffer, 0, 0,SRCCOPY); ValidateRect(WindowHandle,NULL); return 0; case WM_DESTROY: exit(0); // A messy exit, but easy way to escape game loop }; return DefWindowProcW(hWnd, Msg, wParam, lParam); }
//Check for any window messages (keypress, paint, mousemove, etc) void CheckMessages() { SDL_Event ev; bool quit = false; while(SDL_PollEvent(&ev)) { switch(ev.type) { case SDL_KEYDOWN: { int lc = 0; if(OPTIONS[OPT_HIDE_CURSOR] > 0 && SDL_ShowCursor(-1)) SDL_ShowCursor(SDL_DISABLE); //hide mouse cursor on keyboard input 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 ) { break; // temporary fix for unwanted keys } else if(ev.key.keysym.sym==SDLK_RALT || 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; } } break; case SDL_KEYUP: { if(ev.key.keysym.sym==SDLK_RALT || ev.key.keysym.sym==SDLK_LALT) { int code = end_alt_code(); if(code) lastchar = code; } } break; case SDL_MOUSEMOTION: if((OPTIONS[OPT_HIDE_CURSOR] == 0 || OPTIONS[OPT_HIDE_CURSOR] == 2) && !SDL_ShowCursor(-1)) SDL_ShowCursor(SDL_ENABLE); break; case SDL_QUIT: quit = true; break; } } if (needupdate) try_update(); 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); } }
//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; } 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; } } switch (ev.key.keysym.sym) { case SDLK_RSHIFT||SDLK_LSHIFT||SDLK_RCTRL||SDLK_LCTRL||SDLK_RALT: lc= 0; break; // temporary fix for unwanted keys 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 ) { 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; switch (ev.button.button) { case SDL_BUTTON_LEFT: lastchar = MOUSE_BUTTON_LEFT; break; case SDL_BUTTON_RIGHT: lastchar = MOUSE_BUTTON_RIGHT; break; case SDL_BUTTON_WHEELUP: lastchar = SCROLLWHEEL_UP; break; case SDL_BUTTON_WHEELDOWN: lastchar = SCROLLWHEEL_DOWN; break; } 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_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") && !SDL_ShowCursor(-1)) { SDL_ShowCursor(SDL_ENABLE); } break; case SDL_MOUSEBUTTONUP: if (ev.button.button == SDL_BUTTON_LEFT) { lastchar_is_mouse = true; lastchar = MOUSE_BUTTON_LEFT; } else if (ev.button.button == SDL_BUTTON_RIGHT) { lastchar_is_mouse = true; lastchar = MOUSE_BUTTON_RIGHT; } else if (ev.button.button == SDL_BUTTON_WHEELUP) { // Mouse wheel emulates '<' and '>' // FIXME This should really find current key from 'keymap', in case it's remapped, but // that's in action.h. When that's available at a different abstraction level, // this can be improved. lastchar = '<'; } else if (ev.button.button == SDL_BUTTON_WHEELDOWN) { lastchar = '>'; } break; case SDL_QUIT: quit = true; break; } } #ifdef SDLTILES if (needupdate) { try_update(); } #endif if(quit) { endwin(); exit(0); } }