fix: re-install keyboard hooks after Windows session unlock#19
Open
ChristophNoetel wants to merge 1 commit intohandy-computer:mainfrom
Open
fix: re-install keyboard hooks after Windows session unlock#19ChristophNoetel wants to merge 1 commit intohandy-computer:mainfrom
ChristophNoetel wants to merge 1 commit intohandy-computer:mainfrom
Conversation
Windows low-level hooks (WH_KEYBOARD_LL, WH_MOUSE_LL) are silently invalidated when the user locks their session (Win+L) because Windows switches to the Winlogon secure desktop. After unlocking, the hooks never fire again. Fix this by registering for WTS_SESSION_UNLOCK notifications via a message-only window on the hook thread. When session unlock is detected, the old hooks are removed and fresh ones are installed. This is transparent to consumers -- no API changes needed. Closes cjpais/Handy#1213
ChristophNoetel
added a commit
to ChristophNoetel/Handy
that referenced
this pull request
Apr 23, 2026
…el watcher Moves session-unlock hook re-registration from the Handy app into the handy-keys library (handy-computer/handy-keys#19). The library's Windows listener thread now automatically detects WTS_SESSION_UNLOCK and re-installs hooks transparently. This removes ~170 lines of app-level session watcher code: - start_session_watcher() function and wndproc_stub callback - ReregisterAll command, do_reregister_all(), reregister_all() - session_watcher_hwnd field and Drop cleanup - Win32_System_RemoteDesktop feature from Handy's Cargo.toml The handy-keys dependency now points at the fork branch temporarily until the upstream PR is merged and published to crates.io. Addresses cjpais's review feedback on cjpais#1301.
6 tasks
Contributor
|
Thank you! I will test and pull this in when I get a chance Have you tested and validated on your own machine @ChristophNoetel, I will do the same, I just want to get confirmation it works |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WH_KEYBOARD_LL/WH_MOUSE_LLhooks when the user locks their session because the Winlogon secure desktop switch detaches hooks from the interactive desktopHow it works
The hook thread already runs a message pump (
MsgWaitForMultipleObjects+PeekMessageW). This PR adds:HWND_MESSAGE) created on the hook thread at startupWTSRegisterSessionNotification()to receive session change eventsWM_WTSSESSION_CHANGE+WTS_SESSION_UNLOCKin the existing message drain loopUnhookWindowsHookExon old hooks,SetWindowsHookExWto install fresh onesWTSUnRegisterSessionNotification+DestroyWindow) on thread exitSession notification setup is non-fatal -- if it fails, hooks still work normally, they just won't auto-recover after lock/unlock.
Context
This fixes cjpais/Handy#1213. The fix was originally implemented at the app level in cjpais/Handy#1301, but @cjpais suggested moving it into handy-keys itself since hook lifecycle is a library concern.
Changes
Cargo.toml: addWin32_System_RemoteDesktopfeaturesrc/platform/windows/listener.rs: session watcher + hook re-installationTest plan
cargo check/cargo clippypasscargo test)basicexample, Win+L lock/unlock, verify hotkeys still fire