analog support via keyboard

This commit is contained in:
georgemoralis 2024-06-17 13:42:39 +03:00
parent 48d6ccd9bb
commit 91e6d35e89
1 changed files with 46 additions and 0 deletions

View File

@ -99,6 +99,9 @@ void WindowSDL::onKeyPress(const SDL_Event* event) {
using Libraries::Pad::OrbisPadButtonDataOffset; using Libraries::Pad::OrbisPadButtonDataOffset;
u32 button = 0; u32 button = 0;
Input::Axis axis = Input::Axis::AxisMax;
int axisvalue = 0;
int ax = 0;
switch (event->key.keysym.sym) { switch (event->key.keysym.sym) {
case SDLK_UP: case SDLK_UP:
button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_UP; button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_UP;
@ -127,12 +130,55 @@ void WindowSDL::onKeyPress(const SDL_Event* event) {
case SDLK_RETURN: case SDLK_RETURN:
button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_OPTIONS; button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_OPTIONS;
break; break;
case SDLK_a:
axis = Input::Axis::LeftX;
axisvalue += -127;
ax = Input::GetAxis(-0x80, 0x80, axisvalue);
break;
case SDLK_d:
axis = Input::Axis::LeftX;
axisvalue += 127;
ax = Input::GetAxis(-0x80, 0x80, axisvalue);
break;
case SDLK_w:
axis = Input::Axis::LeftY;
axisvalue += -127;
ax = Input::GetAxis(-0x80, 0x80, axisvalue);
break;
case SDLK_s:
axis = Input::Axis::LeftY;
axisvalue += 127;
ax = Input::GetAxis(-0x80, 0x80, axisvalue);
break;
case SDLK_j:
axis = Input::Axis::RightX;
axisvalue += -127;
ax = Input::GetAxis(-0x80, 0x80, axisvalue);
break;
case SDLK_l:
axis = Input::Axis::RightX;
axisvalue += 127;
ax = Input::GetAxis(-0x80, 0x80, axisvalue);
break;
case SDLK_i:
axis = Input::Axis::RightY;
axisvalue += -127;
ax = Input::GetAxis(-0x80, 0x80, axisvalue);
break;
case SDLK_k:
axis = Input::Axis::RightY;
axisvalue += 127;
ax = Input::GetAxis(-0x80, 0x80, axisvalue);
break;
default: default:
break; break;
} }
if (button != 0) { if (button != 0) {
controller->CheckButton(0, button, event->type == SDL_EVENT_KEY_DOWN); controller->CheckButton(0, button, event->type == SDL_EVENT_KEY_DOWN);
} }
if (axis != Input::Axis::AxisMax&& event->type == SDL_EVENT_KEY_DOWN) {
controller->Axis(0, axis, ax);
}
} }
} // namespace Frontend } // namespace Frontend