Repository navigation
Description
Summary
If RegisterHotKey fails for any binding during startup (for example F6 is taken by another program), the error callback raises on the hotkey thread before Tk's mainloop is running, the thread exits, and no global hotkey works for the whole session, including Stop and Emergency stop.
Where
autoclicker/app/hotkeys.py:243-250(_loopcalls_apply()outside thetry)autoclicker/app/hotkeys.py:231-232(_applycallson_error)autoclicker/gui/main_window.py:141-143(on_errorgoes through_ui,start()runs beforemainloop)autoclicker/gui/main_window.py:337-343(_uicallsroot.afterdirectly)
Details
def _loop(self) -> None:
...
self._apply() # not inside try/finally
self._ready.set()
try:
while self._user32.GetMessageW(...) > 0:_apply reports failed keys through on_error, which is lambda msg: self._ui(self._set_status_message, msg, "error"). _ui calls self.root.after(0, ...) from the hotkey thread. With threaded Tcl, a Tk call from another thread before the main thread enters mainloop waits about 1 s and then raises RuntimeError: main thread is not in main loop. The exception escapes _apply, so _ready is never set, the message loop never starts, and _thread_id stays set to a dead thread. Later set_running posts go nowhere.
Impact
The documented stop keys silently do not exist for that session, and the "Hotkey unavailable" message is lost. Startup also stalls about 2 s on _ready.wait. This removes one of the three ways to stop a run.
Steps to reproduce
- From another process, register F6 globally (for example with a small script calling
RegisterHotKey(None, 1, 0, 0x75)) - Launch the app, press Start with the button
- Press F7 or Esc: nothing happens and no error is shown
Suggested fix
Catch exceptions from on_error inside _apply and move the initial _apply() inside the try. Make _ui safe from worker threads at any time, for example by putting callbacks on a queue.Queue that a main-thread after loop drains, so worker threads never call Tk. Add a test where on_error raises and assert the loop still runs.
Acceptance criteria
- A failed registration at startup leaves the other hotkeys working
- The "Hotkey unavailable" status is shown once the window is up
- Unit test:
on_errorraising does not stop the hotkey loop
Getting started
- Relevant files:
autoclicker/app/hotkeys.py,autoclicker/gui/main_window.py,tests/test_hotkeys.py - How to run tests:
make check(Git Bash) ortasks.bat lint,tasks.bat typecheck,tasks.bat test(cmd). Single test:python -m pytest tests/test_x.py::TestClass::test_name --no-cov - Related docs:
CONTRIBUTING.md,docs/ARCHITECTURE.md
Filed by repo-audit/full-audit at 9968dc8. Severity: high. Effort: S. audit-key: bug|autoclicker/app/hotkeys.py|HotkeyManager._loop
Activity