Frontend: Extract keyboard handling to seperate function
This commit is contained in:
parent
3db77a3139
commit
87f9f99938
|
@ -307,100 +307,104 @@ bool SDLInterface::HandleSDLEvent(const SDL_Event* event)
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
|
return HandleSDLKeyEvent(event);
|
||||||
|
|
||||||
|
case SDL_QUIT:
|
||||||
|
m_running = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SDLInterface::HandleSDLKeyEvent(const SDL_Event* event)
|
||||||
|
{
|
||||||
|
const bool pressed = (event->type == SDL_KEYDOWN);
|
||||||
|
switch (event->key.keysym.scancode)
|
||||||
|
{
|
||||||
|
case SDL_SCANCODE_KP_8:
|
||||||
|
case SDL_SCANCODE_I:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Triangle, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_KP_2:
|
||||||
|
case SDL_SCANCODE_K:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Cross, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_KP_4:
|
||||||
|
case SDL_SCANCODE_J:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Square, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_KP_6:
|
||||||
|
case SDL_SCANCODE_L:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Circle, pressed);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_W:
|
||||||
|
case SDL_SCANCODE_UP:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Up, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_S:
|
||||||
|
case SDL_SCANCODE_DOWN:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Down, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_A:
|
||||||
|
case SDL_SCANCODE_LEFT:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Left, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_D:
|
||||||
|
case SDL_SCANCODE_RIGHT:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Right, pressed);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_Q:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::L1, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_E:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::R1, pressed);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_1:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::L2, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_3:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::R2, pressed);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_RETURN:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Start, pressed);
|
||||||
|
return true;
|
||||||
|
case SDL_SCANCODE_BACKSPACE:
|
||||||
|
m_controller->SetButtonState(DigitalController::Button::Select, pressed);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F1:
|
||||||
|
case SDL_SCANCODE_F2:
|
||||||
|
case SDL_SCANCODE_F3:
|
||||||
|
case SDL_SCANCODE_F4:
|
||||||
|
case SDL_SCANCODE_F5:
|
||||||
|
case SDL_SCANCODE_F6:
|
||||||
|
case SDL_SCANCODE_F7:
|
||||||
|
case SDL_SCANCODE_F8:
|
||||||
{
|
{
|
||||||
const bool pressed = (event->type == SDL_KEYDOWN);
|
if (!pressed)
|
||||||
switch (event->key.keysym.scancode)
|
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_KP_8:
|
const u32 index = event->key.keysym.scancode - SDL_SCANCODE_F1 + 1;
|
||||||
case SDL_SCANCODE_I:
|
if (event->key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT))
|
||||||
m_controller->SetButtonState(DigitalController::Button::Triangle, pressed);
|
DoSaveState(index);
|
||||||
return true;
|
else
|
||||||
case SDL_SCANCODE_KP_2:
|
DoLoadState(index);
|
||||||
case SDL_SCANCODE_K:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Cross, pressed);
|
|
||||||
return true;
|
|
||||||
case SDL_SCANCODE_KP_4:
|
|
||||||
case SDL_SCANCODE_J:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Square, pressed);
|
|
||||||
return true;
|
|
||||||
case SDL_SCANCODE_KP_6:
|
|
||||||
case SDL_SCANCODE_L:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Circle, pressed);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_W:
|
|
||||||
case SDL_SCANCODE_UP:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Up, pressed);
|
|
||||||
return true;
|
|
||||||
case SDL_SCANCODE_S:
|
|
||||||
case SDL_SCANCODE_DOWN:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Down, pressed);
|
|
||||||
return true;
|
|
||||||
case SDL_SCANCODE_A:
|
|
||||||
case SDL_SCANCODE_LEFT:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Left, pressed);
|
|
||||||
return true;
|
|
||||||
case SDL_SCANCODE_D:
|
|
||||||
case SDL_SCANCODE_RIGHT:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Right, pressed);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_Q:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::L1, pressed);
|
|
||||||
return true;
|
|
||||||
case SDL_SCANCODE_E:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::R1, pressed);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_1:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::L2, pressed);
|
|
||||||
return true;
|
|
||||||
case SDL_SCANCODE_3:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::R2, pressed);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_RETURN:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Start, pressed);
|
|
||||||
return true;
|
|
||||||
case SDL_SCANCODE_BACKSPACE:
|
|
||||||
m_controller->SetButtonState(DigitalController::Button::Select, pressed);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
|
||||||
case SDL_SCANCODE_F2:
|
|
||||||
case SDL_SCANCODE_F3:
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
case SDL_SCANCODE_F6:
|
|
||||||
case SDL_SCANCODE_F7:
|
|
||||||
case SDL_SCANCODE_F8:
|
|
||||||
{
|
|
||||||
if (!pressed)
|
|
||||||
{
|
|
||||||
const u32 index = event->key.keysym.scancode - SDL_SCANCODE_F1 + 1;
|
|
||||||
if (event->key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT))
|
|
||||||
DoSaveState(index);
|
|
||||||
else
|
|
||||||
DoLoadState(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_TAB:
|
|
||||||
{
|
|
||||||
m_speed_limiter_temp_disabled = pressed;
|
|
||||||
UpdateAudioVisualSync();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_QUIT:
|
case SDL_SCANCODE_TAB:
|
||||||
m_running = false;
|
{
|
||||||
|
m_speed_limiter_temp_disabled = pressed;
|
||||||
|
UpdateAudioVisualSync();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ private:
|
||||||
void DoSaveState(u32 index);
|
void DoSaveState(u32 index);
|
||||||
|
|
||||||
bool HandleSDLEvent(const SDL_Event* event);
|
bool HandleSDLEvent(const SDL_Event* event);
|
||||||
|
bool HandleSDLKeyEvent(const SDL_Event* event);
|
||||||
bool PassEventToImGui(const SDL_Event* event);
|
bool PassEventToImGui(const SDL_Event* event);
|
||||||
void Render();
|
void Render();
|
||||||
void RenderDisplay();
|
void RenderDisplay();
|
||||||
|
|
Loading…
Reference in New Issue