bugfix: include shift keys in modifier_down

This commit is contained in:
Kartik K. Agaram 2022-05-28 23:01:01 -07:00
parent d58aabe867
commit a6ab7a2c20
1 changed files with 25 additions and 3 deletions

View File

@ -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