From 58fb35e85b112b4c96e0611014f4dde680e9bddd Mon Sep 17 00:00:00 2001 From: Mikayla Date: Wed, 5 Jun 2024 00:31:47 +0000 Subject: [PATCH] keyboard and paste support for pocket --- pocket/renderer.lua | 16 ++++++++++++++++ pocket/startup.lua | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pocket/renderer.lua b/pocket/renderer.lua index 892fc92..bc16037 100644 --- a/pocket/renderer.lua +++ b/pocket/renderer.lua @@ -92,4 +92,20 @@ function renderer.handle_mouse(event) end end +-- handle a keyboard event +---@param event key_interaction|nil +function renderer.handle_key(event) + if ui.display ~= nil and event ~= nil then + ui.display.handle_key(event) + end +end + +-- handle a paste event +---@param text string +function renderer.handle_paste(text) + if ui.display ~= nil then + ui.display.handle_paste(text) + end +end + return renderer diff --git a/pocket/startup.lua b/pocket/startup.lua index c9f8c8d..335bdc1 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -175,8 +175,14 @@ local function main() pocket_comms.handle_packet(packet) elseif event == "mouse_click" or event == "mouse_up" or event == "mouse_drag" or event == "mouse_scroll" or event == "double_click" then - -- handle a monitor touch event + -- handle a mouse event renderer.handle_mouse(core.events.new_mouse_event(event, param1, param2, param3)) + elseif event == "char" or event == "key" or event == "key_up" then + -- handle a keyboard event + renderer.handle_key(core.events.new_key_event(event, param1, param2)) + elseif event == "paste" then + -- handle a paste event + renderer.handle_paste(param1) end -- check for termination request