Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(hotkeys): fire a shortcut again while one of its keys stays held (#598)

Ruben Lütkeb2273f10091a
diff --git a/docs/os-parity.md b/docs/os-parity.md
index 4ba3cd9a2a..4f257437d6 100644
--- a/docs/os-parity.md
+++ b/docs/os-parity.md
@@ -1301,6 +1301,7 @@ experiences today.
| P-23 | Info | Coding-CLI panes | Kimi Code's alternate screen cannot be disabled (an open upstream request notes it is the outlier versus Claude Code, Codex and the Gemini CLI), so it may conflict with the pane's own scrollback the way a Claude Code pane once did | Upstream issue; `jarvis/agentic_ide/screen.py` | All OSes equally — not an OS gap, recorded here because it is the same class of pane defect and is expected to need the same kind of fix |
| P-27 | Low | Mouse-button shortcuts | A shortcut may now be a MOUSE BUTTON (middle, and the two side buttons — `mouse_middle` / `mouse_x1` / `mouse_x2`). All three OSes are implemented in the same change and share one token vocabulary, but the delivery is not uniform: Windows needs nothing extra (the backend polls `GetAsyncKeyState`, which reports mouse buttons); macOS needs pyobjc `Quartz` plus the Input Monitoring grant, the one requirement of the listen-only tap (it was Accessibility and Input Monitoring before 2026-10-02), asked when the user enables global shortcuts and never at launch; Linux/X11 needs `pynput`, which is the opt-in `[desktop-linux]` extra for the reason recorded in P-24 (`evdev` is source-only). Wayland cannot do it at all — no global button grab exists, the same design reason keyboard shortcuts degrade there. The left and right buttons are deliberately not bindable on any OS: their meaning follows the system "swap mouse buttons" setting, so a shortcut recorded as "left" would fire on the physical right button for a left-handed user | `jarvis/trigger/hotkey.py::mouse_hotkeys_available`, `backends/global_hotkeys.py::_MOUSE_TOKEN_TO_VK`, `backends/pynput.py::_start_mouse_listener`, `backends/quartz.py::_MOUSE_BUTTON_TO_TOKEN` | Every host answers the capability question BEFORE offering the control: `mouse_hotkeys_available()` returns an English sentence naming what is missing and what still works, and a backend that cannot start its mouse hook logs the same thing and keeps the KEYBOARD shortcuts alive rather than failing the whole binding. macOS/Linux desktop with the extras: parity with Windows once the macOS grant exists (not exercised on a Mac). Wayland and headless: key combinations only |
| P-43 | Low | Keybind recorder modifiers | The settings recorder used to trust only DOM keydown/keyup. On macOS WKWebView a lone Option/Command/Control can arrive as `flagsChanged` (not a DOM event) or as a keydown whose keyup never comes, so the recorder previewed the key and then hung (GitHub #98). The recorder now (a) syncs the modifier flag word from every keyboard and mouse event, and (b) while capturing, polls `GET /api/settings/keybinds/held`, which is a capability probe (`modifier_snapshot`): Windows `GetAsyncKeyState` for Shift/Ctrl/Alt/Win; macOS `CGEventSourceFlagsState` (no event tap and no Accessibility grant); Linux/X11 falls back to the running pynput held-set when the listener is up; Wayland/headless/missing extras answer `available: false` and the on-screen picker still works. A lagging first poll that says "nothing held" does not commit a chord the user just pressed — the snapshot may only DROP a modifier it has already seen down | `jarvis/trigger/hotkey.py::modifier_snapshot`, `jarvis/ui/web/settings_routes.py::get_keybind_held`, `jarvis/ui/web/frontend/src/views/settings/KeybindRow.tsx` | Windows: live modifier snapshot, no extra packages. macOS with pyobjc Quartz: live snapshot even when the hotkey tap is not running. macOS without Quartz / Wayland / headless: honest `available: false`, click-to-assign and letter+modifier chords still record. Linux/X11 with pynput running: snapshot from the listener held-set. Fn is still not a portable key (the OS often swallows it) and is not offered |
+| P-47 | Low | Shortcut re-press while a key stays held | A toggle shortcut fires each time its chord is completed, in either key order, and again while one key stays down: hold Ctrl, press X, press X (or another bound letter) again. Three matchers had to agree. The Windows poller used to end a chord only once EVERY key was up, so a toggle stayed deaf until the whole chord was released; toggle rows now ask the library to end on the first lifted key (`actuate_on_partial_release`), which is the edge the event-driven backends always used. Push-to-talk keeps the full release, so lifting one key of a held chord does not submit the recording. The Windows AppShot key listener latched the first chord of a hold until every key was up, which blocked a second AppShot shortcut sharing the held modifier; a chord now starts on the press that completes it and the longest completed chord wins. The both-keys gesture (both Alt) re-arms when either key lifts instead of both | `jarvis/trigger/backends/global_hotkeys.py::_library_handlers`, `jarvis/appshot/key_events.py::AppshotKeyEvents._reconcile`, `jarvis/appshot/gesture.py::BothKeysWatcher.step` | Windows: poller toggles and the AppShot key listener changed; verified against the real library with simulated key states and unit tests, not on a physical keyboard. macOS (event tap) and Linux/X11 (pynput): unchanged, they already ended a toggle on the first lifted key. The both-keys gesture change applies on every OS that has a key-state probe; both Shift and both Ctrl still require the joint press within the typing guard |
| P-28 | Low | Local realtime | The one-click managed install AND the 2026-08-08 supervisor (prewarm, pidfile ownership, start/stop routes, Ollama keep-alive warm ping) are built cross-platform — pathlib, `os.name` venv layout with a POSIX `lib/python*/site-packages` glob, per-hardware torch flavor, `start_new_session` + `killpg` SIGTERM→SIGKILL escalation on POSIX, `HF_HUB_DISABLE_SYMLINKS` Windows-only — but have only been RUN on the Windows dev box. The preflight narrows the SHARED accelerator probe to the two sources this stack can drive -- NVIDIA VRAM (nvidia-smi) and Apple-Silicon unified memory (total RAM), which the derived launch command maps to `cuda`/`mps`. The shared probe itself also reads AMD and Intel cards now (BUG-206), for the local-model fit verdicts; the preflight deliberately drops those to `(0.0, "none")` via `_DRIVEABLE_SOURCES`, because clearing the memory floor and then launching with a torch device the box does not have is worse than the refusal. An AMD/Intel/no-nvidia-smi host therefore still gets the honest "no supported accelerator" blocker (unit-tested) | `jarvis/realtime/local_server/{preflight,install,supervisor}.py` | Any host under 12 GB usable accelerator memory (including every GPU-less/headless box) gets the honest blocker with a cloud pointer instead of an install — verified by unit tests. macOS Apple-Silicon: preflight and install should work but the smoke boot (`--qwen3_tts_device mps`) is UNVERIFIED on real hardware; a failure is honest (install ends in an error state naming the smoke log, readiness stays fail-closed). Linux+NVIDIA: expected to work via the same cu130 wheel index, unverified; the supervisor's POSIX kill/spawn branches are unit-tested but not live-run. The bring-your-own-server URL socket keeps full parity everywhere |
| P-30 | Medium | Local STT on the GPU | The on-device CTranslate2 recognizer (faster-whisper) needs the cuBLAS 12 / cuDNN 9 runtime wheels, which the `[full]` profile deliberately does not carry. Without them the engine self-heals onto the CPU and, until 2026-08-22, nothing but a log line said so (36 silent fallbacks in one live log; the cloud fallback then ran at ~1× realtime). The wheels are now the opt-in `[cuda]` extra, the provider card reports the accelerator truth (`accelerator_status`: requested device, effective device, reason code) and offers the install from inside the app (`POST /api/local-gpu/libraries`), and the library probe is a pure on-disk look — the out-of-process inference probe (AP-25) remains the only verdict on whether the GPU WORKS | `jarvis/plugins/stt/fwhisper.py::cuda_runtime_libraries_present`, `GPU_LIBRARY_PACKAGES`, `jarvis/speech/local_models.py::accelerator_status`, `jarvis/speech/local_install.py::start_gpu_libraries_install` | Windows: verified live on the dev box (install → `ctranslate2.get_cuda_device_count() == 1`, base/cuda decode). Linux: the same wheels land in `nvidia/cublas/lib`; the probe also accepts a system-wide CUDA via `ctypes.util.find_library("cublas")` — expected to work, UNVERIFIED on real hardware. macOS: no CUDA exists; the card says `unsupported_os` and the recognizer runs on the CPU with no install offered. Headless/GPU-less Linux: libraries absent → honest `cuda_libraries_missing` when the config asks for `cuda`, silent when it asks for `cpu` |
diff --git a/jarvis/appshot/gesture.py b/jarvis/appshot/gesture.py
index 17c18c9bd3..ded69b811f 100644
--- a/jarvis/appshot/gesture.py
+++ b/jarvis/appshot/gesture.py
@@ -169,7 +169,7 @@ def make_probe(family: str = "alt") -> tuple[Probe | None, str]:
class BothKeysWatcher:
- """Calls ``on_fire`` once each time both keys of a pair go down together."""
+ """Calls ``on_fire`` once each time both keys of a pair are down together."""
def __init__(
self,
@@ -212,8 +212,11 @@ class BothKeysWatcher:
if state is None:
return False
left, right = state
- if not (left or right):
+ if not (left and right):
+ # Either key lifting ends the press: holding one key and pressing
+ # the other again is a new gesture.
self._armed = True
+ if not (left or right):
self._first_down = None
return False
now = self._clock()
diff --git a/jarvis/appshot/key_events.py b/jarvis/appshot/key_events.py
index d464fdad5a..3ca412b138 100644
--- a/jarvis/appshot/key_events.py
+++ b/jarvis/appshot/key_events.py
@@ -10,7 +10,11 @@ from __future__ import annotations
import logging
import sys
-from jarvis.trigger.backends.pynput import PynputBackend, _combo_is_down
+from jarvis.trigger.backends.pynput import (
+ _GENERIC_MODIFIER_ALIASES,
+ PynputBackend,
+ _combo_is_down,
+)
log = logging.getLogger(__name__)
@@ -52,15 +56,23 @@ def key_is_down(token: str, vk: int | None = None) -> bool | None:
return None
+def _completes(tokens: frozenset[str], pressed: set[str]) -> bool:
+ """Whether one of the newly pressed keys belongs to the chord."""
+ return any(
+ _GENERIC_MODIFIER_ALIASES.get(token, frozenset({token})) & pressed for token in tokens
+ )
+
+
class AppshotKeyEvents(PynputBackend):
"""One keyboard hook; inherited stop() joins it before any re-registration."""
def __init__(self) -> None:
super().__init__()
- # The longest chord that has been fully down during this hold. A
- # shorter chord inside it (area ``ctrl+b`` under recording
- # ``ctrl+shift+b``) must not fire on the way up.
- self._latched: set[int] | None = None
+ # The held set as the last reconcile saw it. Only a key that is new
+ # against it can start a chord, so a shorter chord (area ``ctrl+b``)
+ # never starts because a longer one (recording ``ctrl+shift+b``) lost
+ # a key on the way up.
+ self._seen: set[str] = set()
self._token_vk: dict[str, int] = {}
@property
@@ -89,11 +101,10 @@ class AppshotKeyEvents(PynputBackend):
removed = True
if not removed:
return
+ self._seen &= self._held
for combo in self._combos:
if combo["down"] and not _combo_is_down(combo["tokens"], self._held):
combo["down"] = False
- if not self._held:
- self._latched = None
def _on_press_key(self, key) -> None:
token = self._token_for(key)
@@ -106,57 +117,49 @@ class AppshotKeyEvents(PynputBackend):
super()._on_release_key(key)
self._drop_stale(keep=None)
+ def stop(self) -> None:
+ super().stop()
+ self._seen.clear()
+
def _reconcile(self) -> None:
- """Fire only the longest chord that is fully held.
+ """Start a chord on the press that completes it; end it when a key lifts.
- The shared matcher fires every chord whose keys are down, so a shorter
- shortcut starts as well the moment the longer one is released one key
- at a time. Once a longer chord has been the winner, it stays the winner
- until every key is up.
+ The shared matcher starts every chord whose keys are down, whatever the
+ last event was, so a shorter shortcut started the moment a longer one
+ lost a key. Here only a newly pressed key starts a chord, and of the
+ chords it completes the longest wins. A key that stays down serves the
+ next chord too: Ctrl+X, then Ctrl+Y, without letting go of Ctrl.
"""
if not self._permission_check():
self._held.clear()
- self._latched = None
+ self._seen.clear()
for combo in self._combos:
combo["down"] = False
return
- down_now = [combo for combo in self._combos if _combo_is_down(combo["tokens"], self._held)]
- if down_now:
- longest = max(len(combo["tokens"]) for combo in down_now)
- winners = {id(combo) for combo in down_now if len(combo["tokens"]) == longest}
- previous = self._latched or set()
- prev_len = max(
- (len(combo["tokens"]) for combo in self._combos if id(combo) in previous),
- default=0,
- )
- if self._latched is None or longest > prev_len:
- for combo in self._combos:
- if combo["down"] and id(combo) not in winners:
- combo["down"] = False
- self._latched = winners
- winners = self._latched or set()
- if not self._held:
- for combo in self._combos:
- if not combo["down"]:
- continue
- combo["down"] = False
- if id(combo) in winners and combo["on_release"] is not None:
- self._got_event = True
- combo["on_release"]()
- self._latched = None
- return
- for combo in self._combos:
- is_down = id(combo) in winners and _combo_is_down(combo["tokens"], self._held)
- if is_down and not combo["down"]:
- combo["down"] = True
- self._got_event = True
- if combo["on_press"] is not None:
- combo["on_press"]()
- elif not is_down and combo["down"]:
+ pressed = self._held - self._seen
+ self._seen = set(self._held)
+ live = [(combo, _combo_is_down(combo["tokens"], self._held)) for combo in self._combos]
+ for combo, is_down in live:
+ if combo["down"] and not is_down:
combo["down"] = False
self._got_event = True
if combo["on_release"] is not None:
combo["on_release"]()
+ if not pressed:
+ return
+ longest = max((len(combo["tokens"]) for combo, is_down in live if is_down), default=0)
+ for combo, is_down in live:
+ if not is_down:
+ continue
+ if len(combo["tokens"]) < longest:
+ combo["down"] = False # The longer chord took over: no toggle.
+ continue
+ if combo["down"] or not _completes(combo["tokens"], pressed):
+ continue
+ combo["down"] = True
+ self._got_event = True
+ if combo["on_press"] is not None:
+ combo["on_press"]()
def _token_for(self, key) -> str | None:
vk = getattr(key, "vk", None)
diff --git a/jarvis/trigger/backends/global_hotkeys.py b/jarvis/trigger/backends/global_hotkeys.py
index 1aea914d92..5c69bbf557 100644
--- a/jarvis/trigger/backends/global_hotkeys.py
+++ b/jarvis/trigger/backends/global_hotkeys.py
@@ -316,6 +316,21 @@ def _registration_combos(normalized: str) -> list[str]:
return combos
+def _library_handlers(row) -> list:
+ """``[on_press, on_release, actuate_on_partial_release]`` for one row.
+
+ The library ends a chord only once EVERY key of it is up, unless the row
+ asks for the first lifted key to end it. A toggle (release handler only)
+ asks for that: otherwise it stays deaf while one key is held and the other
+ is pressed again, and fires on a different edge than the event-driven
+ backends. Push-to-talk keeps the full release, so letting go of one key of
+ a held chord does not submit the recording.
+ """
+ on_press = row[1] if len(row) > 1 else None
+ on_release = row[2] if len(row) > 2 else None
+ return [on_press, on_release, on_press is None]
+
+
class GlobalHotkeysBackend:
"""Windows ``global-hotkeys`` backend (relocated logic, AD-7).
@@ -364,8 +379,9 @@ class GlobalHotkeysBackend:
compat: list[list] = []
for row in bindings:
variants = _registration_combos(row[0])
- primary.append([_to_library_combo(variants[0]), *row[1:]])
- compat.extend([_to_library_combo(v), *row[1:]] for v in variants[1:])
+ handlers = _library_handlers(row)
+ primary.append([_to_library_combo(variants[0]), *handlers])
+ compat.extend([_to_library_combo(v), *handlers] for v in variants[1:])
bindings = primary
combo_strings = [row[0] for row in primary + compat]
diff --git a/tests/unit/appshot/test_appshot_core.py b/tests/unit/appshot/test_appshot_core.py
index 51b3b3b2d6..7fd9f1155c 100644
--- a/tests/unit/appshot/test_appshot_core.py
+++ b/tests/unit/appshot/test_appshot_core.py
@@ -130,6 +130,23 @@ def test_both_alt_fires_once_per_press_and_rearms_on_release(monkeypatch) -> Non
assert len(fired) == 2
+def test_both_alt_fires_again_when_one_key_stays_down(monkeypatch) -> None:
+ import jarvis.platform.self_input as self_input
+
+ monkeypatch.setattr(self_input, "synthetic_input_recent", lambda *a, **k: False)
+ keys, clock, fired = Keys(), Clock(), []
+ watcher = BothAltWatcher(lambda: fired.append(1), probe=keys, clock=clock)
+
+ keys.state = (True, True)
+ assert watcher.step()
+ keys.state = (True, False)
+ watcher.step()
+ clock.now += 1.0
+ keys.state = (True, True)
+ assert watcher.step(), "pressing the second key again is a new gesture"
+ assert len(fired) == 2
+
+
def test_both_alt_ignores_a_bounce_and_synthetic_input(monkeypatch) -> None:
import jarvis.platform.self_input as self_input
diff --git a/tests/unit/appshot/test_appshot_key_events.py b/tests/unit/appshot/test_appshot_key_events.py
index f59aa1acd9..8eae46642f 100644
--- a/tests/unit/appshot/test_appshot_key_events.py
+++ b/tests/unit/appshot/test_appshot_key_events.py
@@ -53,6 +53,81 @@ def test_a_shorter_chord_does_not_fire_with_the_longer_one(monkeypatch):
assert events == ["long"]
+CTRL = SimpleNamespace(name="ctrl_l", char=None)
+SHIFT = SimpleNamespace(name="shift", char=None)
+X = SimpleNamespace(vk=0x58, char="x")
+Y = SimpleNamespace(vk=0x59, char="y")
+B = SimpleNamespace(vk=0x42, char="b")
+
+
+def _area_and_recording(monkeypatch):
+ monkeypatch.setattr("jarvis.appshot.key_events.key_is_down", lambda *_args: None)
+ events = []
+ listener = AppshotKeyEvents()
+ listener.register([
+ ["control + x", None, lambda: events.append("area")],
+ ["control + y", None, lambda: events.append("recording")],
+ ])
+ return listener, events
+
+
+def test_a_held_modifier_serves_the_next_shortcut_too(monkeypatch):
+ listener, events = _area_and_recording(monkeypatch)
+ listener._on_press_key(CTRL)
+ for key in (X, Y, X):
+ listener._on_press_key(key)
+ listener._on_release_key(key)
+ listener._on_release_key(CTRL)
+ assert events == ["area", "recording", "area"]
+
+
+def test_the_letter_may_go_down_before_the_modifier(monkeypatch):
+ listener, events = _area_and_recording(monkeypatch)
+ listener._on_press_key(X)
+ listener._on_press_key(X) # The held letter repeats before Ctrl joins.
+ for _ in range(2):
+ listener._on_press_key(CTRL)
+ listener._on_release_key(CTRL)
+ listener._on_release_key(X)
+ assert events == ["area", "area"]
+
+
+def test_a_shorter_chord_does_not_start_when_the_longer_one_loses_a_key(monkeypatch):
+ monkeypatch.setattr("jarvis.appshot.key_events.key_is_down", lambda *_args: None)
+ events = []
+ listener = AppshotKeyEvents()
+ listener.register([
+ ["control + shift + b", None, lambda: events.append("long")],
+ ["control + b", None, lambda: events.append("short")],
+ ])
+ for key in (CTRL, SHIFT, B):
+ listener._on_press_key(key)
+ listener._on_release_key(SHIFT)
+ listener._on_press_key(Y) # An unrelated key must not start it either.
+ listener._on_release_key(Y)
+ listener._on_release_key(B)
+ listener._on_release_key(CTRL)
+ assert events == ["long"]
+
+
+def test_a_key_whose_release_was_lost_still_starts_the_chord_again(monkeypatch):
+ down = {"x": True}
+ listener, events = _area_and_recording(monkeypatch)
+ monkeypatch.setattr(
+ "jarvis.appshot.key_events.key_is_down", lambda name, _vk=None: down.get(name),
+ )
+ listener._on_press_key(X) # Its release never arrives.
+ down["x"] = False
+ listener._on_press_key(Y)
+ listener._on_release_key(Y)
+ assert "x" not in listener._held
+ listener._on_press_key(CTRL)
+ down["x"] = True
+ listener._on_press_key(X)
+ listener._on_release_key(X)
+ assert events == ["area"]
+
+
def test_a_stuck_modifier_does_not_turn_the_next_letter_into_the_chord(monkeypatch):
# The OS says every leftover key is up. Z itself is the key this event
# is about, so the sweep must leave it for the press and release edges.
diff --git a/tests/unit/trigger/test_hotkey_backends.py b/tests/unit/trigger/test_hotkey_backends.py
index c98a319db8..cc9cf05e69 100644
--- a/tests/unit/trigger/test_hotkey_backends.py
+++ b/tests/unit/trigger/test_hotkey_backends.py
@@ -201,6 +201,22 @@ def test_global_backend_delivers_one_ptt_press_release_pair(fake_gh):
assert edges == ["down", "up"]
+def test_global_backend_toggle_ends_on_the_first_lifted_key(fake_gh):
+ """A toggle fires again while one key stays held; push-to-talk does not."""
+ from jarvis.trigger.backends.global_hotkeys import GlobalHotkeysBackend
+
+ def handler() -> None:
+ return None
+
+ backend = GlobalHotkeysBackend()
+ backend.register([["f1 + f2", None, handler], ["control + alt + l", handler, handler]])
+ rows = {row[0]: row[1:] for call in fake_gh.register_calls for row in call}
+ backend.unregister()
+
+ assert rows["f1 + f2"] == [None, handler, True]
+ assert rows["control + alt + l"] == [handler, handler, False]
+
+
def test_global_backend_unregister_removes_by_string(fake_gh):
"""REGRESSION: unregister must pass combo STRINGS, never the rows."""
from jarvis.trigger.backends.global_hotkeys import GlobalHotkeysBackend