From a6ab7a2c200655c760b7b98d61b57d8b9e4b78bc Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 28 May 2022 23:01:01 -0700 Subject: [PATCH] bugfix: include shift keys in modifier_down --- keychord.lua | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/keychord.lua b/keychord.lua index 323c028..3ab0635 100644 --- a/keychord.lua +++ b/keychord.lua @@ -1,7 +1,9 @@ -- Keyboard driver +Modifiers = {'lctrl', 'rctrl', 'lalt', 'ralt', 'lshift', 'rshift', 'lgui', 'rgui'} + function App.keypressed(key, scancode, isrepeat) - if key == 'lctrl' or key == 'rctrl' or key == 'lalt' or key == 'ralt' or key == 'lshift' or key == 'rshift' or key == 'lgui' or key == 'rgui' then + if array.find(Modifiers, key) then -- do nothing when the modifier is pressed end -- include the modifier(s) when the non-modifer is pressed @@ -28,6 +30,26 @@ function App.combine_modifiers(key) end function App.modifier_down() - local down = love.keyboard.isDown - return down('lctrl') or down('rctrl') or down('lalt') or down('ralt') or down('lgui') or down('rgui') + return array.any(Modifiers, love.keyboard.isDown) +end + +array = {} + +function array.find(arr, elem) + for i,x in ipairs(arr) do + if x == elem then + return i + end + end + return nil +end + +function array.any(arr, f) + for i,x in ipairs(arr) do + local result = f(x) + if result then + return result + end + end + return false end