Skip to main content

HID event messages

Declaration

thread.register_event("xxtouch.hid_event", function(val)
local event = json.decode(val)
if event.event_type=="touch" then
if event.event_name=="touch.on" then
sys.toast("Touch down at: ("..event.x..", "..event.y..")\n"..event.time)
elseif event.event_name=="touch.move" then
sys.toast("Touch moved to: ("..event.x..", "..event.y..")\n"..event.time)
elseif event.event_name=="touch.off" then
sys.toast("Touch up at: ("..event.x..", "..event.y..")\n"..event.time)
end
else
if event.event_name=="key.down" then
sys.toast("Key down: "..event.key_name.."\n"..event.time)
elseif event.event_name=="key.up" then
sys.toast("Key up: "..event.key_name.."\n"..event.time)
end
end
end)

State

  • val
    If listening is registered, all HID event info will be delivered here. This severely impacts script performance; unregister promptly when no longer needed.
    All touch coordinates in HID events use the portrait coordinate system with the Home button at the bottom. If needed, convert using screen.rotate_xy.

Example

-- Clear message queue
proc_queue_clear("xxtouch.hid_event")
--
-- Start listening
local eid = thread.register_event("xxtouch.hid_event", function(val)
local event = json.decode(val)
if event.event_type=="touch" then
if event.event_name=="touch.on" then
sys.toast("Touch down at: ("..event.x..", "..event.y..")\n"..event.time)
elseif event.event_name=="touch.move" then
sys.toast("Touch moved to: ("..event.x..", "..event.y..")\n"..event.time)
elseif event.event_name=="touch.off" then
sys.toast("Touch up at: ("..event.x..", "..event.y..")\n"..event.time)
end
else
if event.event_name=="key.down" then
sys.toast("Key down: "..event.key_name.."\n"..event.time)
elseif event.event_name=="key.up" then
sys.toast("Key up: "..event.key_name.."\n"..event.time)
end
end
end)
--
touch.on(100, 100):off()
sys.msleep(1000)
key.press('homebutton')
--
sys.msleep(20000) -- wait 20 seconds
--
-- Unregister callback; without unregistering, the script will not end here
thread.unregister_event("xxtouch.hid_event", eid)

Note: Uses sys.toast, sys.msleep, proc_queue_clear, thread.register_event, thread.unregister_event