diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-02 08:20:30 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-02 08:24:24 -0700 |
commit | 4aa2003c94e8cdadde3d353a8cbc631c3a92833d (patch) | |
tree | 6c9ef0d3ba7e60eabee85633bcd87620d0303265 /main.lua | |
parent | 57d87f2353874d4503dde09c85d29e20ff291c18 (diff) | |
download | lines.love-4aa2003c94e8cdadde3d353a8cbc631c3a92833d.tar.gz |
handle chords
For shift we'll mostly rely on love.textinput. For the rest I've created a simple driver.
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/main.lua b/main.lua index eafcdd3..e9bccf5 100644 --- a/main.lua +++ b/main.lua @@ -1,3 +1,5 @@ +require 'keychord' + lines = {} width, height, flags = 0, 0, nil @@ -25,27 +27,29 @@ end function love.update(dt) end -function love.keypressed(key, scancode, isrepeat) - if key == 'return' then +function love.textinput(t) + lines[#lines] = lines[#lines]..t +end + +function keychord_pressed(chord) + -- Don't handle any keys here that would trigger love.textinput above. + if chord == 'return' then table.insert(lines, '') - elseif key == 'space' then - lines[#lines] = lines[#lines]..' ' - elseif key == 'lctrl' or key == 'rctrl' then - -- do nothing - elseif key == 'lalt' or key == 'ralt' then - -- do nothing - elseif key == 'lshift' or key == 'rshift' then - -- do nothing - elseif love.keyboard.isDown('lctrl') or love.keyboard.isDown('rctrl') then - if key == 'r' then - lines[#lines+1] = eval(lines[#lines])[1] - lines[#lines+1] = '' - end - else - lines[#lines] = lines[#lines]..key + elseif chord == 'C-r' then + lines[#lines+1] = eval(lines[#lines])[1] + lines[#lines+1] = '' end end +function love.keyreleased(key, scancode) +end + +function love.mousepressed(x, y, button) +end + +function love.mousereleased(x, y, button) +end + function eval(buf) local f = load('return '..buf, 'REPL') if f then @@ -69,12 +73,3 @@ function gather_results(success, ...) local n = select('#', ...) return success, { n = n, ... } end - -function love.keyreleased(key, scancode) -end - -function love.mousepressed(x, y, button) -end - -function love.mousereleased(x, y, button) -end |