3 Modifiers
= {'lctrl', 'rctrl', 'lalt', 'ralt', 'lshift', 'rshift', 'lgui', 'rgui'}
5 function App
.keypressed(key
, scancode
, isrepeat
)
6 if array
.find(Modifiers
, key
) then
7 -- do nothing when the modifier is pressed
10 -- include the modifier(s) when the non-modifer is pressed
11 App
.keychord_press(App
.combine_modifiers(key
), key
)
14 function App
.combine_modifiers(key
)
15 if love
.keyboard
.isModifierActive
then -- waiting for LÖVE v12
16 if key
:match('^kp') then
17 key
= App
.translate_numlock(key
)
21 if App
.ctrl_down() then
24 if App
.alt_down() then
27 if App
.shift_down() then
28 result
= result
..'S-' -- don't try to use this with letters/digits
30 if App
.cmd_down() then
37 function App
.any_modifier_down()
38 return App
.ctrl_down() or App
.alt_down() or App
.shift_down() or App
.cmd_down()
41 function App
.ctrl_down()
42 return App
.key_down('lctrl') or App
.key_down('rctrl')
45 function App
.alt_down()
46 return App
.key_down('lalt') or App
.key_down('ralt')
49 function App
.shift_down()
50 return App
.key_down('lshift') or App
.key_down('rshift')
53 function App
.cmd_down()
54 return App
.key_down('lgui') or App
.key_down('rgui')
57 function App
.is_cursor_movement(key
)
58 return array
.find({'left', 'right', 'up', 'down', 'home', 'end', 'pageup', 'pagedown'}, key
)
61 -- mappings only to non-printable keys; leave out mappings that textinput will handle
68 -- numpad 5 translates to nothing
74 -- LÖVE handles keypad operators in textinput
75 -- what's with the `kp=` and `kp,` keys? None of my keyboards have one.
76 -- Hopefully LÖVE handles them as well in textinput.
84 function App
.translate_numlock(key
)
85 if love
.keyboard
.isModifierActive('numlock') then
86 return Numlock_on
[key
] or key
88 return Numlock_off
[key
] or key
95 function array
.find(arr
, elem
)
96 if type(elem
) == 'function' then
97 for i
,x
in ipairs(arr
) do
103 for i
,x
in ipairs(arr
) do
112 function array
.any(arr
, f
)
113 for i
,x
in ipairs(arr
) do