[InputText] Toggle on-screen keyboard with a lone Sym/ScreenKB tap (#15669)

On devices with a physical keyboard (e.g. Kindle), the on-screen keyboard
can already be toggled while a text field is focused via Shift/ScreenKB +
Home. This adds a lone tap of the physical Sym key as an additional, more
natural trigger.

Sym is otherwise a held modifier for the symbol layer, and Input:handleKeyBoardEv
swallows a bare modifier press/release before it becomes a key event. Detect a
Sym press+release with no other key in between and surface it as a dedicated
"SymPress" key event, which InputText handles the same way as the existing
Shift/ScreenKB + Home toggle. The symbol layer (Sym+<key>) is unaffected: any
intervening key press clears the lone-tap state, so only a true solo tap fires.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Igor VelkovandClaude Opus 4.8 authored and GitHub committed 2026-07-12 22:20:20 +02:00
1 parent c6f6e75021
commit 8a48cc4ff5
3 files changed
+65 -13

No files matched your search

+36
View File
@@ -851,12 +851,48 @@ function Input:handleKeyBoardEv(ev)
UIManager:nextTick(function() UIManager:quit() end) -- Ensure the program closes in case of some lingering dialog.
end
-- A lone Sym or ScreenKB key tap (pressed and released with no other key in
-- between) is used by InputText to toggle the on-screen keyboard, mirroring
-- Shift/ScreenKB + Home. Both are otherwise only modifiers whose bare
-- press/release is swallowed just below, so we track which one, if any, was
-- "tapped alone" across the press/release pair. It only counts as a lone tap
-- if no other modifier is held at press time (the key itself is not marked in
-- self.modifiers until the block below), so combinations like Shift + Sym do
-- not toggle the keyboard. Pressing any other key clears the flag, so the
-- symbol layer (Sym + key) never toggles. A held Sym is not a tap either: on
-- the Kindle 3 mxckpd advertises EV_REP (~1s delay then ~5 Hz), so a held Sym
-- repeats; any event for it that is neither a press nor a release clears the
-- flag and a long hold does not toggle on release. That guard also covers
-- "Disable key repeat" (Kindle:toggleKeyRepeat), which rewrites the repeat
-- value to -1 rather than dropping the event. The ScreenKB key (Kindle 4) does
-- not emit repeats, so it needs no such guard; a bare press/release is a tap.
if ev.value == KEY_PRESS then
local solo = keycode == "Sym" or keycode == "ScreenKB"
if solo then
for _, held in pairs(self.modifiers) do
if held then
solo = false
break
end
end
end
self.keyboard_toggle_tapped = solo and keycode or nil
elseif ev.value ~= KEY_RELEASE and keycode == "Sym" then
self.keyboard_toggle_tapped = nil
end
-- handle modifier keys
if self.modifiers[keycode] ~= nil then
if ev.value == KEY_PRESS then
self.modifiers[keycode] = true
elseif ev.value == KEY_RELEASE then
self.modifiers[keycode] = false
if self.keyboard_toggle_tapped == keycode then
self.keyboard_toggle_tapped = nil
-- Surface the lone tap as a dedicated key event; nothing else binds it.
local tap_key = keycode == "Sym" and "SymPress" or "ScreenKBPress"
return Event:new("KeyPress", Key:new(tap_key, self.modifiers))
end
end
return
end
+12 -8
View File
@@ -229,23 +229,27 @@ local sub_item_table = {
}
if Device:hasKeyboard() or Device:hasScreenKB() then
-- we use same pos. 4 as below so we are always above "keyboard appearance settings"
-- The shortcut that temporarily toggles the keyboard while a field is focused: a
-- lone Sym/ScreenKB press on devices that have such a key, otherwise Shift + Home.
local vk_shortcut
if Device:hasScreenKB() then
vk_shortcut = _("'ScreenKB'")
elseif Device:hasSymKey() then
vk_shortcut = _("'Sym'")
else
vk_shortcut = _("'Shift' + 'Home'")
end
table.insert(sub_item_table, 4, {
text = _("Show virtual keyboard"),
help_text = _("Enable this setting to always display the virtual keyboard within a text input field. When a field is selected (in focus), you can temporarily toggle the keyboard on/off by pressing 'Shift' (or 'ScreenKB') + 'Home'."),
help_text = T(_("Enable this setting to always display the virtual keyboard within a text input field. When a field is selected (in focus), you can temporarily toggle the keyboard on/off by pressing %1."), vk_shortcut),
checked_func = function()
return G_reader_settings:isTrue("virtual_keyboard_enabled")
end,
callback = function()
G_reader_settings:flipNilOrFalse("virtual_keyboard_enabled")
if G_reader_settings:nilOrFalse("virtual_keyboard_enabled") then
local keyboard_infomessage
if Device:hasScreenKB() then
keyboard_infomessage = _("When a text field is selected (in focus), you can temporarily bring up the virtual keyboard by pressing 'ScreenKB' + 'Home'.")
else
keyboard_infomessage = _("When a text field is selected (in focus), you can temporarily bring up the virtual keyboard by pressing 'Shift' + 'Home'.")
end
UIManager:show(InfoMessage:new{
text = keyboard_infomessage
text = T(_("When a text field is selected (in focus), you can temporarily bring up the virtual keyboard by pressing %1."), vk_shortcut),
})
end
end,
+17 -5
View File
@@ -796,6 +796,13 @@ function InputText:onKeyPress(key)
if not self.focused then
return false
end
-- A lone Sym or ScreenKB key press toggles the on-screen keyboard, same as Shift/ScreenKB + Home.
if key["SymPress"] or key["ScreenKBPress"] then
self:toggleKeyboard()
return self.keyboard ~= nil -- readonly fields have no keyboard: let the event bubble
end
local handled = true
if not key["Ctrl"] and not key["Shift"] and not key["Alt"] and not key["ScreenKB"] then
@@ -880,11 +887,7 @@ function InputText:onKeyPress(key)
elseif key["Press"] then
self:holdTextBox()
elseif key["Home"] then
if self.keyboard:isVisible() then
self:onCloseKeyboard()
else
self:onShowKeyboard()
end
self:toggleKeyboard()
elseif key["."] and Device:hasSymKey() then
-- Kindle does not have a dedicated button for commas
self:addChars(",")
@@ -977,6 +980,15 @@ function InputText:isKeyboardVisible()
return false
end
-- Temporarily show/hide the on-screen keyboard, e.g. via Shift/ScreenKB + Home or a lone Sym/ScreenKB press.
function InputText:toggleKeyboard()
if self:isKeyboardVisible() then
self:onCloseKeyboard()
else
self:onShowKeyboard()
end
end
function InputText:lockKeyboard(toggle)
if self.keyboard then
return self.keyboard:lockVisibility(toggle)