about summary refs log tree commit diff stats
path: root/keychord.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-28 23:01:01 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-28 23:01:01 -0700
commita6ab7a2c200655c760b7b98d61b57d8b9e4b78bc (patch)
treeb42bc26b4c510601d01e09fe90b90c61b60e4b67 /keychord.lua
parentd58aabe86790584d8445698059aeeddba27674f8 (diff)
downloadlines.love-a6ab7a2c200655c760b7b98d61b57d8b9e4b78bc.tar.gz
bugfix: include shift keys in modifier_down
Diffstat (limited to 'keychord.lua')
-rw-r--r--keychord.lua28
1 files 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