Defold had never been able to get mobile text input from the keyboard with the HTML5 restrictions. Using jstodef and html5.run
, I’ve created a way to get text input with the element on HTML. No need for virtual keyboards that don’t support copy and pasting and spellcheck. Since this uses HTML to get the text, the device keyboard is already taking care of it for you. It even works on Fullscreen!
Demo: mchlkpng.github.io/mobilehtml5-typing
Since this is a lua module, feel free to edit the style of the tags.
It has been tested on Android, and it should work for Apple too (I don’t have any devices to test).
Example implimentation:
local mht = require "mobilehtml5typing.index"
function init(self)
if mht then -- only runs on mobile browsers
-- set listener for text
self.listener = mht.onText(self, function(self, text)
print("text:", text)
label.set_text("#label", text)
end)
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("removelistener") and mht then
--removes the text listener so it's no longer called when input is given
mht.removeListener(self.listener)
end
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed and mht then
-- opens the textbox
mht.openTextBox(self.text)
end
end
This code was made in less than a day, so please contact me with any bugs and errors.