bugfix: include shift keys in modifier_down
This commit is contained in:
parent
d58aabe867
commit
a6ab7a2c20
28
keychord.lua
28
keychord.lua
|
@ -1,7 +1,9 @@
|
||||||
-- Keyboard driver
|
-- Keyboard driver
|
||||||
|
|
||||||
|
Modifiers = {'lctrl', 'rctrl', 'lalt', 'ralt', 'lshift', 'rshift', 'lgui', 'rgui'}
|
||||||
|
|
||||||
function App.keypressed(key, scancode, isrepeat)
|
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
|
-- do nothing when the modifier is pressed
|
||||||
end
|
end
|
||||||
-- include the modifier(s) when the non-modifer is pressed
|
-- include the modifier(s) when the non-modifer is pressed
|
||||||
|
@ -28,6 +30,26 @@ function App.combine_modifiers(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function App.modifier_down()
|
function App.modifier_down()
|
||||||
local down = love.keyboard.isDown
|
return array.any(Modifiers, love.keyboard.isDown)
|
||||||
return down('lctrl') or down('rctrl') or down('lalt') or down('ralt') or down('lgui') or down('rgui')
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue