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 /keychord.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 'keychord.lua')
-rw-r--r-- | keychord.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/keychord.lua b/keychord.lua new file mode 100644 index 0000000..d9b89f5 --- /dev/null +++ b/keychord.lua @@ -0,0 +1,25 @@ +-- Keyboard driver + +function 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 pressed + end + -- include the modifier(s) when the non-modifer is pressed + keychord_pressed(combine_modifiers(key)) +end + +function combine_modifiers(key) + local result = '' + local down = love.keyboard.isDown + if down('lctrl') or down('rctrl') then + result = result..'C-' + end + if down('lalt') or down('ralt') then + result = result..'M-' + end + if down('lgui') or down('rgui') then + result = result..'S-' + end + result = result..key + return result +end |