Skip to content

Commit

Permalink
Fix sdl Function & joystick input (#1278)
Browse files Browse the repository at this point in the history
regression from koreader/koreader#7037
  • Loading branch information
yparitcher committed Dec 31, 2020
1 parent 8614f99 commit 7c1057f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions ffi/SDL2_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,27 +213,27 @@ local function handleJoyAxisMotionEvent(event)
if axis == 0 then
if value < -neutral_max_val then
-- send left
genEmuEvent(C.EV_KEY, 80, 1)
genEmuEvent(C.EV_KEY, 1073741904, 1)
else
-- send right
genEmuEvent(C.EV_KEY, 79, 1)
genEmuEvent(C.EV_KEY, 1073741903, 1)
end
elseif axis == 1 then
if value < -neutral_max_val then
-- send up
genEmuEvent(C.EV_KEY, 82, 1)
genEmuEvent(C.EV_KEY, 1073741906, 1)
else
-- send down
genEmuEvent(C.EV_KEY, 81, 1)
genEmuEvent(C.EV_KEY, 1073741905, 1)
end
-- right stick 3/4
elseif axis == 4 then
if value < -neutral_max_val then
-- send page up
genEmuEvent(C.EV_KEY, 75, 1)
genEmuEvent(C.EV_KEY, 1073741899, 1)
else
-- send page down
genEmuEvent(C.EV_KEY, 78, 1)
genEmuEvent(C.EV_KEY, 1073741902, 1)
end
-- left trigger 2
-- right trigger 5
Expand Down Expand Up @@ -361,46 +361,46 @@ function S.waitForEvent(usecs)

if button == SDL.SDL_CONTROLLER_BUTTON_A then
-- send enter
genEmuEvent(C.EV_KEY, 40, 1)
genEmuEvent(C.EV_KEY, 13, 1)
-- send end (bound to press)
genEmuEvent(C.EV_KEY, 77, 1)
genEmuEvent(C.EV_KEY, 1073741901, 1)
elseif button == SDL.SDL_CONTROLLER_BUTTON_B then
-- send escape
genEmuEvent(C.EV_KEY, 41, 1)
genEmuEvent(C.EV_KEY, 27, 1)
-- left bumper
elseif button == SDL.SDL_CONTROLLER_BUTTON_BACK then
-- send page up
genEmuEvent(C.EV_KEY, 75, 1)
genEmuEvent(C.EV_KEY, 1073741899, 1)
-- right bumper
elseif button == SDL.SDL_CONTROLLER_BUTTON_GUIDE then
-- send page down
genEmuEvent(C.EV_KEY, 78, 1)
genEmuEvent(C.EV_KEY, 1073741902, 1)
-- On the Xbox One controller, start = start but leftstick = menu button
elseif button == SDL.SDL_CONTROLLER_BUTTON_START or button == SDL.SDL_CONTROLLER_BUTTON_LEFTSTICK then
-- send F1 (bound to menu in front at the time of writing)
genEmuEvent(C.EV_KEY, 58, 1)
genEmuEvent(C.EV_KEY, 1073741882, 1)
end
--- D-pad ---
elseif event.type == SDL.SDL_JOYHATMOTION then
local hat_position = event.jhat.value

if hat_position == SDL.SDL_HAT_UP then
-- send up
genEmuEvent(C.EV_KEY, 82, 1)
genEmuEvent(C.EV_KEY, 1073741906, 1)
elseif hat_position == SDL.SDL_HAT_DOWN then
-- send down
genEmuEvent(C.EV_KEY, 81, 1)
genEmuEvent(C.EV_KEY, 1073741905, 1)
elseif hat_position == SDL.SDL_HAT_LEFT then
-- send left
genEmuEvent(C.EV_KEY, 80, 1)
genEmuEvent(C.EV_KEY, 1073741904, 1)
elseif hat_position == SDL.SDL_HAT_RIGHT then
-- send right
genEmuEvent(C.EV_KEY, 79, 1)
genEmuEvent(C.EV_KEY, 1073741903, 1)
end
elseif event.type == SDL.SDL_QUIT then
-- send Alt + F4
genEmuEvent(C.EV_KEY, 226, 1)
genEmuEvent(C.EV_KEY, 61, 1)
genEmuEvent(C.EV_KEY, 1073742050, 1)
genEmuEvent(C.EV_KEY, 1073741885, 1)
end
end
end
Expand Down

0 comments on commit 7c1057f

Please sign in to comment.