Emscripten: fixed Ctrl key not working

This commit is contained in:
Sergii Pylypenko
2021-06-22 01:08:14 +03:00
parent 80aeaf1156
commit 81e820c93e
3 changed files with 20 additions and 20 deletions

View File

@@ -36,6 +36,8 @@ static bool _cursor_new_in_window = false;
static bool _request_fullscreen = true;
#endif
static bool old_ctrl_pressed;
void VideoDriver_SDL_Base::MakeDirty(int left, int top, int width, int height)
{
Rect r = {left, top, left + width, top + height};
@@ -486,6 +488,21 @@ bool VideoDriver_SDL_Base::PollEvent()
!IsValidChar(character, CS_ALPHANUMERAL)) {
HandleKeypress(keycode, character);
}
if (ev.key.keysym.sym == SDLK_LCTRL || ev.key.keysym.sym == SDLK_RCTRL) {
_ctrl_pressed = true;
}
if (ev.key.keysym.sym == SDLK_LSHIFT || ev.key.keysym.sym == SDLK_RSHIFT) {
_shift_pressed = true;
}
}
break;
case SDL_KEYUP:
if (ev.key.keysym.sym == SDLK_LCTRL || ev.key.keysym.sym == SDLK_RCTRL) {
_ctrl_pressed = false;
}
if (ev.key.keysym.sym == SDLK_LSHIFT || ev.key.keysym.sym == SDLK_RSHIFT) {
_shift_pressed = false;
}
break;
@@ -604,14 +621,8 @@ void VideoDriver_SDL_Base::Stop()
void VideoDriver_SDL_Base::InputLoop()
{
uint32 mod = SDL_GetModState();
const Uint8 *keys = SDL_GetKeyboardState(NULL);
bool old_ctrl_pressed = _ctrl_pressed;
_ctrl_pressed = !!(mod & KMOD_CTRL);
_shift_pressed = !!(mod & KMOD_SHIFT);
#if defined(_DEBUG)
this->fast_forward_key_pressed = _shift_pressed;
#else
@@ -628,6 +639,7 @@ void VideoDriver_SDL_Base::InputLoop()
(keys[SDL_SCANCODE_DOWN] ? 8 : 0);
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
old_ctrl_pressed = _ctrl_pressed;
}
void VideoDriver_SDL_Base::LoopOnce()

View File

@@ -49,6 +49,7 @@ static int _requested_hwpalette; /* Did we request a HWPALETTE for the current v
static SDL_Joystick * _multitouch_device = NULL;
static Point _multitouch_second_point;
static bool old_ctrl_pressed;
void VideoDriver_SDL::MakeDirty(int left, int top, int width, int height)
{
@@ -600,25 +601,21 @@ bool VideoDriver_SDL::PollEvent()
WChar character;
uint keycode = ConvertSdlKeyIntoMy(&ev.key.keysym, &character);
HandleKeypress(keycode, character);
#ifdef __ANDROID__
if (ev.key.keysym.sym == SDLK_LCTRL || ev.key.keysym.sym == SDLK_RCTRL) {
_ctrl_pressed = true;
}
if (ev.key.keysym.sym == SDLK_LSHIFT || ev.key.keysym.sym == SDLK_RSHIFT) {
_shift_pressed = true;
}
#endif
}
break;
case SDL_KEYUP:
#ifdef __ANDROID__
if (ev.key.keysym.sym == SDLK_LCTRL || ev.key.keysym.sym == SDLK_RCTRL) {
_ctrl_pressed = false;
}
if (ev.key.keysym.sym == SDLK_LSHIFT || ev.key.keysym.sym == SDLK_RSHIFT) {
_shift_pressed = false;
}
#endif
break;
#ifdef __ANDROID__
case SDL_JOYBALLMOTION:
@@ -698,17 +695,9 @@ void VideoDriver_SDL::Stop()
void VideoDriver_SDL::InputLoop()
{
uint32 mod = SDL_GetModState();
int numkeys;
Uint8 *keys = SDL_GetKeyState(&numkeys);
bool old_ctrl_pressed = _ctrl_pressed;
#ifndef __ANDROID__
_ctrl_pressed = !!(mod & KMOD_CTRL);
_shift_pressed = !!(mod & KMOD_SHIFT);
#endif
#if defined(_DEBUG)
this->fast_forward_key_pressed = _shift_pressed;
#else
@@ -725,6 +714,7 @@ void VideoDriver_SDL::InputLoop()
(keys[SDLK_DOWN] ? 8 : 0);
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
old_ctrl_pressed = _ctrl_pressed;
}
void VideoDriver_SDL::MainLoop()

View File

@@ -35,5 +35,3 @@
- Implement cloud saves by downloading the savegame from the web browser.
- Find some developer with a MacBook and $100 to publish the 'OpenTTD Webapp Launcher' to the Apple Store.
- Ctrl screen button is getting stuck in the pressed state.