diff options
| author | Kartik K. Agaram <vc@akkartik.com> | 2026-04-01 11:14:16 -0700 |
|---|---|---|
| committer | Kartik K. Agaram <vc@akkartik.com> | 2026-04-01 11:31:14 -0700 |
| commit | 40f180bf292bcbdd0a96330d5f4d3bb7e5251452 (patch) | |
| tree | d82fe9d027322463b897fe2e1363c7654c98020d | |
| parent | 2a1838544efdd6ee5dba7dd827cd985418b7eb71 (diff) | |
| download | text.love-40f180bf292bcbdd0a96330d5f4d3bb7e5251452.tar.gz | |
better support other keyboard layouts
Thanks Garvalf for improving my understanding here relative to
https://love2d.org/forums/viewtopic.php?p=257623#p257623 back in Nov
2023.
Levels of understanding:
- never trigger both textinput and keypressed, so never trigger
textinput if a modifier is down
- wait, shift is a modifier. Ok, ignore modifiers except shift.
- ctrl can never be triggered anyway. get rid of the whole modifier
check.
- wait, alt-c does trigger textinput('c')
- allow textinput if a modifier changes the key being pressed
- and now: turns out azerty requires shift to turn keypress '1' into
textinput '1'. Better understand that layout and others. Textinput
events can be triggered by either shift or altGr combinations. altGr
isn't directly represented by LÖVE. It's usually the right alt key.
There are probably devices out there that send other key combinations on
altGr. I'll wait for people to chime in who can help test on those
devices. In the fullness of time this probably requires some
configuration:
[ ] altGr is right alt
[ ] altGr is ctrl+alt
[ ] disable altGr
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | keychord.lua | 10 | ||||
| -rw-r--r-- | reference.md | 3 | ||||
| -rw-r--r-- | source_text.lua | 11 | ||||
| -rw-r--r-- | text.lua | 11 |
5 files changed, 19 insertions, 19 deletions
@@ -34,6 +34,9 @@ While editing text: * `ctrl+z` to undo, `ctrl+y` to redo * `ctrl+=` to zoom in, `ctrl+-` to zoom out, `ctrl+0` to reset zoom * `alt+right`/`alt+left` to jump to the next/previous word, respectively + Only left alt is supported, because many keyboard layouts use right alt like + shift for typing characters, and I don't know how to figure out the current + layout. * mouse drag or `shift` + movement to select text, `ctrl+a` to select all * `ctrl+e` to modify the sources diff --git a/keychord.lua b/keychord.lua index e817405..01ab16f 100644 --- a/keychord.lua +++ b/keychord.lua @@ -43,15 +43,21 @@ function App.default_modifier(key) end end -function App.any_modifier_down() - return App.ctrl_down() or App.alt_down() or App.shift_down() or App.cmd_down() +-- Many keyboard layouts use a special altGr key to insert additional +-- printable characters. SDL/LÖVE can't represent altGr distinctly. +function alt_gr_down() + return App.key_down('ralt') end +-- altGr is a separate modifier and never considered with alt or ctrl, +-- regardless of layout. function App.ctrl_down() + if alt_gr_down() then return false end return App.key_down('lctrl') or App.key_down('rctrl') end function App.alt_down() + if alt_gr_down() then return false end return App.key_down('lalt') or App.key_down('ralt') end diff --git a/reference.md b/reference.md index 7148c40..ddbf216 100644 --- a/reference.md +++ b/reference.md @@ -339,9 +339,6 @@ The following facilities help set these things up: * `App.cmd_down()`, `App.ctrl_down`, `App.alt_down()`, `App.shift_down()` -- predicates for different modifier keys. -* `App.any_modifier_down()` -- returns `true` if any of the modifier keys is - currently pressed. - * `App.key_down(key)` -- returns `true` if the given key is currently pressed. (Based on [LÖVE](https://love2d.org/wiki/love.keyboard.isDown).) diff --git a/source_text.lua b/source_text.lua index 3a0a941..e884b4b 100644 --- a/source_text.lua +++ b/source_text.lua @@ -220,13 +220,10 @@ end function Text.text_input(State, t) if App.mouse_down(1) then return end - if App.any_modifier_down() then - if App.key_down(t) then - -- The modifiers didn't change the key. Handle it in keychord_press. - return - else - -- Key mutated by the keyboard layout. Continue below. - end + -- textinput events can occur on chords with the shift key or AltGr key + -- but not for ctrl, alt or cmd/super/gui + if App.ctrl_down() or App.alt_down() or App.cmd_down() then + return end local before = snapshot(State, State.cursor1.line) --? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos) @@ -143,13 +143,10 @@ end function Text.text_input(State, t) if App.mouse_down(1) then return end - if App.any_modifier_down() then - if App.key_down(t) then - -- The modifiers didn't change the key. Handle it in keychord_press. - return - else - -- Key mutated by the keyboard layout. Continue below. - end + -- textinput events can occur on chords with the shift key or AltGr key + -- but not for ctrl, alt or cmd/super/gui + if App.ctrl_down() or App.alt_down() or App.cmd_down() then + return end local before = snapshot(State, State.cursor1.line) --? print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos) |