Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: better handling of Windows LLHOOK stuck keys #531

Merged
merged 1 commit into from
Aug 12, 2023

Conversation

jtroo
Copy link
Owner

@jtroo jtroo commented Aug 11, 2023

There are two changes in this commit.

  1. Always live reload after ~1s.

After 1 second if live reload is still not done, there might be a key in a stuck state. One known instance where this happens is Win+L to lock the screen when on Windows and using the LLHOOK mechanism. The release of Win and L keys will not be caught by the kanata process when on the lock screen. However, the OS knows that these keys have released - only the kanata state is wrong. And since kanata has a key in a stuck state, without this 1s fallback, live reload would never activate. Having this fallback allows live reload to happen which resets the kanata states.

  1. Clear states after ~65.5s of no external input but still not idle.

This code only runs in the LLHOOK Windows version. The reason for this existing is the same as in 1). The main motivator is the Win+L example. The thought is that after locking their screen, the user will probably go away for a while. The software can detect the abnormality of zero user inputs for an extended period of time while still not being idle and assume that keys got stuck.

@jtroo
Copy link
Owner Author

jtroo commented Aug 11, 2023

Other than the compilation failure, this doesn't quite work. As an optimization, in most cases kanata can go idle even while keys are still pressed, so the current 65s check doesn't work properly.

There are two changes in this commit.

1) Always live reload after ~1s.

After 1 second if live reload is still not done, there might be a key in
a stuck state. One known instance where this happens is Win+L to lock
the screen when on Windows and using the LLHOOK mechanism. The release
of Win and L keys will not be caught by the kanata process when on the
lock screen. However, the OS knows that these keys have released - only
the kanata state is wrong. And since kanata has a key in a stuck state,
without this 1s fallback, live reload would never activate. Having this
fallback allows live reload to happen which resets the kanata states.

2) Clear normal states (not fake key) after blocking for a while

This code only runs in the LLHOOK Windows version. The reason for this
existing is the same as in 1). The main motivator is the Win+L example.
The thought is that after locking their screen, the user will probably
go away for a while. The software can detect that the zero user inputs
were input for extended period of time and assume that keys got stuck.
@jtroo
Copy link
Owner Author

jtroo commented Aug 12, 2023

Came up with a different solution that probably works as expected.

@jtroo jtroo merged commit f7e05d9 into main Aug 12, 2023
3 checks passed
@jtroo jtroo deleted the live-reload-1s-bypass branch August 15, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant