Treat key combinations as a unit (combos)

The display now only updates on key-down (the combo grows as you press)
and when the last key is released (the empty payload starts the linger
with the last full combo). Intermediate releases no longer shrink the
display, so the order you let go of a shortcut doesn't matter: Ctrl+Shift+N
stays Ctrl+Shift+N whether Ctrl, Shift, or N goes up first, and the 1s
linger shows the full combo instead of a partial release state. Matches
the keybinding-tutorial use case better than keyviz, which shrinks
key-by-key on spaced releases.
This commit is contained in:
felixzsh
2026-08-11 14:57:45 -05:00
parent f53d2553d6
commit cabdf1307c
3 changed files with 22 additions and 4 deletions
+6 -1
View File
@@ -104,12 +104,17 @@ plugin, not just this one.
- **Typing** — shows just the character: `g`, `G`, `!`, `5`.
- **Modifier combos** — shows every modifier plus the key: `Super Shift G`,
`Ctrl C`, `Super Enter`.
- **Combos are a unit** — a combination stays intact no matter the order you
release it: press `Ctrl Shift N`, let go of `Ctrl` first, then `Shift`,
then `N`, and the display keeps showing `Ctrl Shift N` the whole time
(keyviz shrinks key-by-key; this plugin treats the chord as one unit).
- **Non-printing keys** — labeled: `Esc`, `Tab`, `F1`, arrows, `Space`.
- Modifiers that produce the shifted character (`Shift` with a letter) are
folded into the character itself: `Shift + 1` shows `!`.
- Key repeat is ignored; a held key shows once.
- After the last key is released the combo lingers briefly (1s by default,
keyviz-style "Duration") and then vanishes in one frame — no fade.
keyviz-style "Duration") and then vanishes in one frame — no fade. The
lingering combo is always the last full one, never a partial release state.
- In `mode: "bindings"` only combos with a modifier are shown; plain typing
stays off screen.
+15 -2
View File
@@ -145,6 +145,13 @@ local function emit()
end
end
-- Combos: a combination of keys is treated as a unit. The display only
-- updates on key-down (the combo grows as you press) and when the last key
-- is released (the empty payload starts the panel's linger with the last
-- full combo). Intermediate releases never shrink the display, so the order
-- in which you let go of a shortcut doesn't matter: Ctrl+Shift+N stays
-- Ctrl+Shift+N whether you release Ctrl, Shift, or N first.
--
-- state: 0 = released, 1 = pressed, 2 = repeat (ignored).
hl.on("input.keyboard.key", function(keycode, timeMs, state)
if state == 2 then return end
@@ -158,6 +165,7 @@ hl.on("input.keyboard.key", function(keycode, timeMs, state)
end
if not found then combo[#combo + 1] = keycode end
end
emit()
else
pressed[keycode] = false
if not MODS[keycode] then
@@ -168,7 +176,12 @@ hl.on("input.keyboard.key", function(keycode, timeMs, state)
end
end
end
-- Only emit when the last key goes up: intermediate releases keep the
-- full combo on screen (the panel lingers it after the empty payload).
local any_down = false
for _, down in pairs(pressed) do
if down then any_down = true break end
end
if not any_down then emit() end
end
emit()
end)
+1 -1
View File
@@ -2,7 +2,7 @@
"schemaVersion": 1,
"id": "felixzsh.key-visualizer",
"name": "Key Visualizer",
"version": "1.3.3",
"version": "1.4.0",
"description": "Shows the keys you press on screen. Great for keybinding tutorials, demos, and screencasts.",
"kinds": [
"panel",