Files
Frans de Jonge fa6b3cde8f [SDL,plugin/hotkeys] Process gamepad events (#15449)
Gives Hotkeys the ability to configure gamepads, at least to a degree. Advanced users might wish to use a shoulder button or a trigger as a modifier like in Tony Hawk or Devil May Cry. But in that case I suggest they might be advanced enough to make a follow-up PR as well. It's out of scope for this one anyway.

Things like deadzones might prefer to be independently configurable in the future, but then again it's a reader app.

Depends on <https://github.com/koreader/koreader-base/pull/2376>.
2026-06-06 20:56:55 +02:00

173 lines
8.0 KiB
Lua

-- typed on my Commodore 64 ;)
local Device = require("device")
local util = require("util")
-- The hotkey shortcuts defined here are only the defaults. The user can
-- change them at any time using the hotkey shortcuts configuration menu.
-- NOTE: The combinations that contain the tag ** keep nil, "existing function outside plugin" **
-- should never be assigned to any action in this plugin, because they are already assigned
-- to events in core. If you assign them to actions in this plugin, those actions will be in
-- conflict with the existing ones and hell will break loose.
local defaults = {
hotkeys_fm = {
modifier_plus_up = nil,
-- modifier_plus_down -- keep nil, brings up FM search widget (equivalent to tapping on 'Page x of y').
modifier_plus_left = nil,
modifier_plus_right = nil,
-- modifier_plus_left_page_back -- keep nil, goes to first FM page, (i.e <<).
-- modifier_plus_left_page_forward -- keep nil, goes to last FM page (i.e >>).
-- modifier_plus_right_page_back -- keep nil, goes to first FM page, (i.e <<).
-- modifier_plus_right_page_forward -- keep nil, goes to last FM page (i.e >>).
modifier_plus_back = {open_previous_document = true,},
modifier_plus_home = Device:hasWifiToggle() and {toggle_wifi = true,} or {},
-- modifier_plus_press -- keep nil, long press or hold.
-- modifier_plus_menu -- keep nil, screenshots on K4.
-- optional, user can select whether or not to enable it.
-- press -- keep nil, select button.
-- alt
alt_plus_up = nil,
alt_plus_down = nil,
alt_plus_left = nil,
alt_plus_right = nil,
alt_plus_left_page_back = nil,
alt_plus_left_page_forward = nil,
alt_plus_right_page_back = nil,
alt_plus_right_page_forward = nil,
alt_plus_back = nil,
alt_plus_home = nil,
alt_plus_press = nil,
alt_plus_menu = nil,
-- alt+alphabet
alt_plus_a = nil,
alt_plus_b = nil,
alt_plus_c = nil,
alt_plus_d = Device:hasKeyboard() and {dictionary_lookup = true,} or {},
alt_plus_e = nil,
alt_plus_f = Device:hasKeyboard() and {file_search = true,} or {},
alt_plus_g = nil,
alt_plus_h = nil,
alt_plus_i = nil,
alt_plus_j = nil,
alt_plus_k = nil,
alt_plus_l = nil,
alt_plus_m = nil,
alt_plus_n = nil,
alt_plus_o = nil,
alt_plus_p = nil,
alt_plus_q = nil,
alt_plus_r = nil,
alt_plus_s = nil,
alt_plus_t = nil,
alt_plus_u = nil,
alt_plus_v = nil,
alt_plus_w = Device:hasKeyboard() and {wikipedia_lookup = true,} or {},
alt_plus_x = nil,
alt_plus_y = nil,
alt_plus_z = nil,
-- alphabet (no modifier)
-- Note: these are all nil in FM mode since we already use them
-- as shortcuts for opening documents.
-- a = nil, b = nil, c = nil, d = nil, e = nil, f = nil,
-- g = nil, h = nil, i = nil, j = nil, k = nil, l = nil,
-- m = nil, n = nil, o = nil, p = nil, q = nil, r = nil,
-- s = nil, t = nil, u = nil, v = nil, w = nil, x = nil,
-- y = nil, z = nil,
},
hotkeys_reader = {
modifier_plus_up = {toc = true,},
modifier_plus_down = {book_map = true,},
modifier_plus_left = {bookmarks = true,},
modifier_plus_right = {toggle_bookmark = true,},
modifier_plus_left_page_back = not Device:isTouchDevice() and {select_prev_page_link = true,} or {},
modifier_plus_left_page_forward = not Device:isTouchDevice() and {select_next_page_link = true,} or {},
modifier_plus_right_page_back = not Device:isTouchDevice() and {select_prev_page_link = true,} or {},
modifier_plus_right_page_forward = not Device:isTouchDevice() and {select_next_page_link = true,} or {},
modifier_plus_back = {open_previous_document = true,},
modifier_plus_home = Device:hasWifiToggle() and {toggle_wifi = true,} or {},
modifier_plus_press = {add_location_to_history = true,},
-- modifier_plus_menu -- keep nil, screenshots on K4.
-- optional, user can select whether or not to enable it.
press = {show_config_menu = true,},
-- alt
alt_plus_up = nil,
alt_plus_down = nil,
alt_plus_left = nil,
alt_plus_right = nil,
alt_plus_left_page_forward = nil,
alt_plus_left_page_back = nil,
alt_plus_right_page_forward = nil,
alt_plus_right_page_back = nil,
alt_plus_back = nil,
alt_plus_home = nil,
alt_plus_press = nil,
alt_plus_menu = nil,
-- alt+alphabet
alt_plus_a = nil,
alt_plus_b = nil,
alt_plus_c = nil,
alt_plus_d = Device:hasKeyboard() and {dictionary_lookup = true,} or {},
alt_plus_e = nil,
alt_plus_f = Device:hasKeyboard() and {file_search = true,} or {},
alt_plus_g = nil,
alt_plus_h = nil,
alt_plus_i = nil,
alt_plus_j = nil,
alt_plus_k = nil,
alt_plus_l = nil,
alt_plus_m = nil,
alt_plus_n = nil,
alt_plus_o = nil,
alt_plus_p = nil,
alt_plus_q = nil,
alt_plus_r = nil,
alt_plus_s = Device:hasKeyboard() and {fulltext_search = true,} or {},
alt_plus_t = nil,
alt_plus_u = nil,
alt_plus_v = nil,
alt_plus_w = Device:hasKeyboard() and {wikipedia_lookup = true,} or {},
alt_plus_x = nil,
alt_plus_y = nil,
alt_plus_z = nil,
-- alphabet (no modifier)
a = nil,
b = Device:hasKeyboard() and {bookmarks = true,} or {},
c = nil, d = nil, e = nil, f = nil, g = nil,
h = Device:hasKeyboard() and {text_selection = true,} or {},
i = nil, j = nil, k = nil, l = nil, m = nil, n = nil,
o = nil, p = nil, q = nil, r = nil, s = nil,
t = Device:hasKeyboard() and {toc = true,} or {},
u = nil, v = nil, w = nil, x = nil, y = nil, z = nil,
},
}
if Device:supportsGamepad() then
local gamepad_defaults = {
gamepad_axis_left_x_minus = {key_left = true,}, -- left
gamepad_axis_left_x_plus = {key_right = true,}, -- right
gamepad_axis_left_y_minus = {key_up = true,}, -- up
gamepad_axis_left_y_plus = {key_down = true,}, -- down
gamepad_axis_right_y_minus = {key_right_page_back = true,}, -- Page Up
gamepad_axis_right_y_plus = {key_right_page_forward = true,}, -- Page Down
gamepad_button_a = {key_press = true,}, -- South (A) -> Enter/Press
gamepad_button_b = {key_back = true,}, -- East (B) -> Escape
gamepad_button_y = {key_context_menu = true,}, -- North (Y) -> ContextMenu
gamepad_button_back = {key_right_page_back = true,}, -- Back
gamepad_button_guide = {key_right_page_forward = true,}, -- Guide
gamepad_button_start = {key_menu = true,}, -- Start
gamepad_button_left_stick = {key_menu = true,}, -- Left Stick
gamepad_button_left_shoulder = {key_right_page_back = true,}, -- Left Shoulder
gamepad_button_right_shoulder = {key_right_page_forward = true,}, -- Right Shoulder
gamepad_button_dpad_up = {key_up = true,}, -- D-pad Up
gamepad_button_dpad_down = {key_down = true,}, -- D-pad Down
gamepad_button_dpad_left = {key_left = true,}, -- D-pad Left
gamepad_button_dpad_right = {key_right = true,}, -- D-pad Right
}
for _, mode in ipairs({"hotkeys_fm", "hotkeys_reader"}) do
util.tableMerge(defaults[mode], gamepad_defaults)
end
end
return defaults