2022-05-29 07:01:01 +01:00
|
|
|
Modifiers = {'lctrl', 'rctrl', 'lalt', 'ralt', 'lshift', 'rshift', 'lgui', 'rgui'}
|
|
|
|
|
2024-06-20 05:39:47 +01:00
|
|
|
function love.keypressed(key, scancode, isrepeat)
|
2022-05-29 07:01:01 +01:00
|
|
|
if array.find(Modifiers, key) then
|
2022-05-02 16:20:30 +01:00
|
|
|
-- do nothing when the modifier is pressed
|
2022-06-14 17:32:52 +01:00
|
|
|
return
|
2022-05-02 16:20:30 +01:00
|
|
|
end
|
|
|
|
-- include the modifier(s) when the non-modifer is pressed
|
2024-06-22 17:43:02 +01:00
|
|
|
love.keychord_pressed(combine_modifiers(key), key)
|
2022-05-02 16:20:30 +01:00
|
|
|
end
|
|
|
|
|
2024-06-22 17:43:02 +01:00
|
|
|
function combine_modifiers(key)
|
2023-07-08 02:40:12 +01:00
|
|
|
if love.keyboard.isModifierActive then -- waiting for LÖVE v12
|
|
|
|
if key:match('^kp') then
|
2024-06-22 17:43:02 +01:00
|
|
|
key = translate_numlock(key)
|
2023-07-08 02:40:12 +01:00
|
|
|
end
|
|
|
|
end
|
2022-05-02 16:20:30 +01:00
|
|
|
local result = ''
|
2024-06-22 17:43:02 +01:00
|
|
|
if ctrl_down() then
|
2022-05-02 16:20:30 +01:00
|
|
|
result = result..'C-'
|
|
|
|
end
|
2024-06-22 17:43:02 +01:00
|
|
|
if alt_down() then
|
2022-05-02 16:20:30 +01:00
|
|
|
result = result..'M-'
|
|
|
|
end
|
2024-06-22 17:43:02 +01:00
|
|
|
if shift_down() then
|
2022-05-28 07:34:20 +01:00
|
|
|
result = result..'S-' -- don't try to use this with letters/digits
|
|
|
|
end
|
2024-06-22 17:43:02 +01:00
|
|
|
if cmd_down() then
|
2022-05-28 07:34:20 +01:00
|
|
|
result = result..'s-'
|
2022-05-02 16:20:30 +01:00
|
|
|
end
|
|
|
|
result = result..key
|
|
|
|
return result
|
|
|
|
end
|
2022-05-27 04:40:50 +01:00
|
|
|
|
2024-06-22 17:43:02 +01:00
|
|
|
function any_modifier_down()
|
|
|
|
return ctrl_down() or alt_down() or shift_down() or cmd_down()
|
2022-05-29 07:01:01 +01:00
|
|
|
end
|
|
|
|
|
2024-06-22 17:43:02 +01:00
|
|
|
function ctrl_down()
|
|
|
|
return Keys_down.lctrl or Keys_down.rctrl
|
2022-05-30 00:13:24 +01:00
|
|
|
end
|
|
|
|
|
2024-06-22 17:43:02 +01:00
|
|
|
function alt_down()
|
|
|
|
return Keys_down.lalt or Keys_down.ralt
|
2022-05-30 00:13:24 +01:00
|
|
|
end
|
|
|
|
|
2024-06-22 17:43:02 +01:00
|
|
|
function shift_down()
|
|
|
|
return Keys_down.lshift or Keys_down.rshift
|
2022-05-30 00:13:24 +01:00
|
|
|
end
|
|
|
|
|
2024-06-22 17:43:02 +01:00
|
|
|
function cmd_down()
|
|
|
|
return Keys_down.lgui or Keys_down.rgui
|
2022-05-30 00:13:24 +01:00
|
|
|
end
|
|
|
|
|
2024-06-22 17:43:02 +01:00
|
|
|
function is_cursor_movement(key)
|
2022-06-23 20:05:36 +01:00
|
|
|
return array.find({'left', 'right', 'up', 'down', 'home', 'end', 'pageup', 'pagedown'}, key)
|
|
|
|
end
|
|
|
|
|
2023-07-08 02:40:12 +01:00
|
|
|
-- mappings only to non-printable keys; leave out mappings that textinput will handle
|
|
|
|
Numlock_off = {
|
|
|
|
kp0='insert',
|
|
|
|
kp1='end',
|
|
|
|
kp2='down',
|
|
|
|
kp3='pagedown',
|
|
|
|
kp4='left',
|
|
|
|
-- numpad 5 translates to nothing
|
|
|
|
kp6='right',
|
|
|
|
kp7='home',
|
|
|
|
kp8='up',
|
|
|
|
kp9='pageup',
|
|
|
|
['kp.']='delete',
|
|
|
|
-- LÖVE handles keypad operators in textinput
|
|
|
|
-- what's with the `kp=` and `kp,` keys? None of my keyboards have one.
|
|
|
|
-- Hopefully LÖVE handles them as well in textinput.
|
|
|
|
kpenter='enter',
|
|
|
|
kpdel='delete',
|
|
|
|
}
|
|
|
|
Numlock_on = {
|
|
|
|
kpenter='enter',
|
|
|
|
kpdel='delete',
|
|
|
|
}
|
2024-06-22 17:43:02 +01:00
|
|
|
function translate_numlock(key)
|
2023-07-08 02:40:12 +01:00
|
|
|
if love.keyboard.isModifierActive('numlock') then
|
|
|
|
return Numlock_on[key] or key
|
|
|
|
else
|
|
|
|
return Numlock_off[key] or key
|
|
|
|
end
|
|
|
|
return key
|
|
|
|
end
|