From d7ad1bfdc9b2ed6d14cab71439ad5afe1e609737 Mon Sep 17 00:00:00 2001 From: David <97603719+Commodore64user@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:45:48 +0100 Subject: [PATCH] add option to use dpad as action keys (#16270) --- .../reader/modules/readerkeyselection.lua | 1 + frontend/apps/reader/modules/readerpaging.lua | 1 + .../apps/reader/modules/readerrolling.lua | 1 + frontend/device/generic/device.lua | 4 +++ frontend/ui/elements/physical_buttons.lua | 29 +++++++++++++++++-- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerkeyselection.lua b/frontend/apps/reader/modules/readerkeyselection.lua index 02b22f248..f4898988b 100644 --- a/frontend/apps/reader/modules/readerkeyselection.lua +++ b/frontend/apps/reader/modules/readerkeyselection.lua @@ -209,6 +209,7 @@ function ReaderKeySelection:registerKeyEvents() -- startHighlightIndicator (H) is handled by hotkeys.koplugin end end +ReaderKeySelection.onRegisterDPadEvents = ReaderKeySelection.registerKeyEvents ReaderKeySelection.onPhysicalKeyboardConnected = ReaderKeySelection.init function ReaderKeySelection:addToMainMenu(menu_items) diff --git a/frontend/apps/reader/modules/readerpaging.lua b/frontend/apps/reader/modules/readerpaging.lua index 62edd10eb..642a6a092 100644 --- a/frontend/apps/reader/modules/readerpaging.lua +++ b/frontend/apps/reader/modules/readerpaging.lua @@ -87,6 +87,7 @@ function ReaderPaging:registerKeyEvents() end ReaderPaging.onPhysicalKeyboardConnected = ReaderPaging.registerKeyEvents +ReaderPaging.onRegisterDPadEvents = ReaderPaging.registerKeyEvents function ReaderPaging:onReaderReady() self:setupTouchZones() diff --git a/frontend/apps/reader/modules/readerrolling.lua b/frontend/apps/reader/modules/readerrolling.lua index 7805df7fa..626f547c8 100644 --- a/frontend/apps/reader/modules/readerrolling.lua +++ b/frontend/apps/reader/modules/readerrolling.lua @@ -155,6 +155,7 @@ function ReaderRolling:registerKeyEvents() end ReaderRolling.onPhysicalKeyboardConnected = ReaderRolling.registerKeyEvents +ReaderRolling.onRegisterDPadEvents = ReaderRolling.registerKeyEvents function ReaderRolling:onReadSettings(config) -- 20180503: some fix in crengine has changed the way the DOM is built diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 5ee3794ca..6c0dba8ce 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -320,6 +320,10 @@ function Device:init() end end + if self:hasDPad() and G_reader_settings:isTrue("input_use_dpad_as_action_keys") then + self.useDPadAsActionKeys = function() return true end + end + if self:hasGSensor() then -- Setup our standard gyro event handler (EV_MSC:MSC_GYRO) if G_reader_settings:nilOrFalse("input_ignore_gsensor") then diff --git a/frontend/ui/elements/physical_buttons.lua b/frontend/ui/elements/physical_buttons.lua index 312e3ec90..11e091eb4 100644 --- a/frontend/ui/elements/physical_buttons.lua +++ b/frontend/ui/elements/physical_buttons.lua @@ -23,7 +23,9 @@ local PhysicalButtons = { }, } -if Device:hasDPad() and Device:useDPadAsActionKeys() then +local uses_d_pad_as_action_keys = Device:hasDPad() and Device:useDPadAsActionKeys() + +if uses_d_pad_as_action_keys then table.insert(PhysicalButtons.sub_item_table, { text = _("Invert left-side page-turn buttons"), enabled_func = function() @@ -49,6 +51,27 @@ if Device:hasDPad() and Device:useDPadAsActionKeys() then end, separator = true, }) +end + +if Device:isTouchDevice() and Device:hasDPad() then + table.insert(PhysicalButtons.sub_item_table, { + text = _("Use cursor keys as action keys"), + help_text = _("When enabled, the cursor keys are used for: Up/Down calls text selection, Left/Right calls previous/next chapter."), + checked_func = function() + return G_reader_settings:isTrue("input_use_dpad_as_action_keys") + end, + callback = function() + G_reader_settings:flipNilOrFalse("input_use_dpad_as_action_keys") + Device.useDPadAsActionKeys = function() + return G_reader_settings:isTrue("input_use_dpad_as_action_keys") + end + UIManager:broadcastEvent(Event:new("RegisterDPadEvents")) + UIManager:broadcastEvent(Event:new("RebuildMenu")) + end, + separator = not uses_d_pad_as_action_keys, + }) +end +if uses_d_pad_as_action_keys then table.insert(PhysicalButtons.sub_item_table, { text = _("Use left and right keys for page turning"), checked_func = function() @@ -56,10 +79,12 @@ if Device:hasDPad() and Device:useDPadAsActionKeys() then end, callback = function() G_reader_settings:flipNilOrFalse("left_right_keys_turn_pages") - UIManager:askForRestart() + UIManager:broadcastEvent(Event:new("RegisterDPadEvents")) end, + separator = true, }) end +-- Hotkeys.koplugin inserts itself here. if Device:canKeyRepeat() then table.insert(PhysicalButtons.sub_item_table, 1, {