diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-09-04 00:22:31 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-09-04 00:22:31 -0700 |
commit | 99495355b4bde77cdfea18698de1472d9e83872a (patch) | |
tree | c2ef5be55ad2ed71ffeb0c1be02cbaaf494ea4a9 | |
parent | 6e54ad55d98ff041db15a1a1157e493d76776dfc (diff) | |
download | view.love-99495355b4bde77cdfea18698de1472d9e83872a.tar.gz |
stop using keyboard.isDown
It doesn't work on Android, and it's not much work to avoid.
-rw-r--r-- | app.lua | 20 |
1 files 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 |