From 99495355b4bde77cdfea18698de1472d9e83872a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 4 Sep 2023 00:22:31 -0700 Subject: stop using keyboard.isDown It doesn't work on Android, and it's not much work to avoid. --- app.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app.lua b/app.lua index 477a9b3..da43889 100644 --- a/app.lua +++ b/app.lua @@ -348,13 +348,29 @@ end nativefs = require 'nativefs' +local Keys_down = {} + -- call this once all tests are run -- can't run any tests after this function App.disable_tests() -- have LÖVE delegate all handlers to App if they exist for name in pairs(love.handlers) do if App[name] then - love.handlers[name] = App[name] + -- love.keyboard.isDown doesn't work on Android, so emulate it using + -- keypressed and keyreleased events + if name == 'keypressed' then + love.handlers[name] = function(key, scancode, isrepeat) + Keys_down[key] = true + return App.keypressed(key, scancode, isrepeat) + end + elseif name == 'keyreleased' then + love.handlers[name] = function(key, scancode) + Keys_down[key] = nil + return App.keyreleased(key, scancode) + end + else + love.handlers[name] = App[name] + end end end @@ -410,7 +426,7 @@ function App.disable_tests() App.get_time = love.timer.getTime App.get_clipboard = love.system.getClipboardText App.set_clipboard = love.system.setClipboardText - App.key_down = love.keyboard.isDown + App.key_down = function(key) return Keys_down[key] end App.mouse_move = love.mouse.setPosition App.mouse_down = love.mouse.isDown App.mouse_x = love.mouse.getX -- cgit 1.4.1-2-gfad0