Handle arrow keys and enter in emulator text fields

pull/8721/head
John Beard 2 years ago committed by poire-z
parent e39ee325f9
commit ccc49036aa

@ -543,30 +543,47 @@ end
-- is shown. Mostly likely to be in the emulator, but could be Android + BT
-- keyboard, or a "coder's keyboard" Android input method.
function InputText:onKeyPress(key)
if key["Backspace"] then
self:delChar()
elseif key["Del"] then
self:rightChar()
self:delChar()
elseif key["Left"] then
self:leftChar()
elseif key["Right"] then
self:rightChar()
elseif key["End"] then
self:goToEnd()
elseif key["Home"] then
self:goToHome()
local handled = true
if not key["Ctrl"] and not key["Shift"] and not key["Alt"] then
if key["Backspace"] then
self:delChar()
elseif key["Del"] then
self:rightChar()
self:delChar()
elseif key["Left"] then
self:leftChar()
elseif key["Right"] then
self:rightChar()
elseif key["Up"] then
self:upLine()
elseif key["Down"] then
self:downLine()
elseif key["End"] then
self:goToEnd()
elseif key["Home"] then
self:goToHome()
elseif key["Press"] then
self:addChars("\n")
elseif key["Tab"] then
self:addChars(" ")
else
handled = false
end
elseif key["Ctrl"] and not key["Shift"] and not key["Alt"] then
if key["U"] then
self:delToStartOfLine()
elseif key["H"] then
self:delChar()
else
handled = false
end
else
return false
handled = false
end
return true
return handled
end
-- Handle text coming directly as text from the Device layer (eg. soft keyboard

@ -800,6 +800,20 @@ function VirtualKeyboard:init()
if keyboard.wrapInputBox then
self.uwrap_func = keyboard.wrapInputBox(self.inputbox) or self.uwrap_func
end
if Device:hasDPad() and Device:hasKeyboard() and Device:isTouchDevice() then
-- hadDPad() would have FocusManager handle arrow keys strokes to navigate
-- and activate this VirtualKeyboard's touch keys (needed on non-touch Kindle).
-- If we have a keyboard, we'd prefer arrow keys (and Enter, and Del) to be
-- handled by InputText to navigate the cursor inside the text box, and to
-- add newline and delete chars. And if we are a touch device, we don't
-- need focus manager to help us navigate keys and fields.
-- So, disable all key_event handled by FocusManager
self.key_events.FocusLeft = nil
self.key_events.FocusRight = nil
self.key_events.FocusUp = nil
self.key_events.FocusDown = nil
self.key_events.PressKey = nil -- added above
end
end
function VirtualKeyboard:getKeyboardLayout()

Loading…
Cancel
Save