handle chords
[?]
May 2, 2022, 3:20 PM
6LJZN727CRPYR34LV75CQF55YZI3E7MGESYZSFSYAE73SNEZE3FACDependencies
- [2]
6Q6XGOFLlittle Lua repl on hitting ctrl-r - [3]
634QBFQXctrl- and alt- combinations - [4]
OTIBCAUJlove2d scaffold - [5]
5TIFKJ7Shandle space key - [6]
QU7NHFOVshow cursor - [*]
R5QXEHUIsomebody stop me
Change contents
- edit in main.lua at line 1
require 'keychord' - replacement in main.lua at line 30
function love.keypressed(key, scancode, isrepeat)if key == 'return' thenfunction love.textinput(t)lines[#lines] = lines[#lines]..tendfunction keychord_pressed(chord)-- Don't handle any keys here that would trigger love.textinput above.if chord == 'return' then - replacement in main.lua at line 38[3.555]→[3.2:70](∅→∅),[3.70]→[3.2:112](∅→∅),[3.112]→[2.2:69](∅→∅),[2.69]→[3.112:207](∅→∅),[3.112]→[3.112:207](∅→∅),[3.207]→[2.70:175](∅→∅),[3.70]→[3.555:601](∅→∅),[2.175]→[3.555:601](∅→∅),[3.249]→[3.555:601](∅→∅),[3.555]→[3.555:601](∅→∅)
elseif key == 'space' thenlines[#lines] = lines[#lines]..' 'elseif key == 'lctrl' or key == 'rctrl' then-- do nothingelseif key == 'lalt' or key == 'ralt' then-- do nothingelseif key == 'lshift' or key == 'rshift' then-- do nothingelseif love.keyboard.isDown('lctrl') or love.keyboard.isDown('rctrl') thenif key == 'r' thenlines[#lines+1] = eval(lines[#lines])[1]lines[#lines+1] = ''endelselines[#lines] = lines[#lines]..keyelseif chord == 'C-r' thenlines[#lines+1] = eval(lines[#lines])[1]lines[#lines+1] = '' - edit in main.lua at line 42
endfunction love.keyreleased(key, scancode)endfunction love.mousepressed(x, y, button) - edit in main.lua at line 50
function love.mousereleased(x, y, button)end - edit in main.lua at line 75
endfunction love.keyreleased(key, scancode) - edit in main.lua at line 76
function love.mousepressed(x, y, button)endfunction love.mousereleased(x, y, button)end - file addition: keychord.lua[8.2]
-- Keyboard driverfunction love.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-- do nothing when the modifier is pressedend-- include the modifier(s) when the non-modifer is pressedkeychord_pressed(combine_modifiers(key))endfunction combine_modifiers(key)local result = ''local down = love.keyboard.isDownif down('lctrl') or down('rctrl') thenresult = result..'C-'endif down('lalt') or down('ralt') thenresult = result..'M-'endif down('lgui') or down('rgui') thenresult = result..'S-'endresult = result..keyreturn resultend