-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Dev docs for Keyboard Manager #7340
Dev docs for Keyboard Manager #7340
Conversation
@arjunbalgovind
|
It is ideal to minimize the number of sent keys for performance, because ensuring that key remaps are responsive is very important. Since most keyboard have input latency in the order of several milliseconds we have to make sure that any latency added by us is small enough that users will not feel it compared to typing without remaps. Even if performance is not a concern, I have seen cases where minimizing the key events fixes certain OS scenarios, such as remaps to Win key not opening start menu (#7171 recently fixed remapping shortcuts to Win key remaps. Even before the PR the logic made sense that when you release the shortcut it should just reset the state but for some reason it wouldn't open start menu properly (it would only appear some times).
I'm not sure I'm understanding this correctly, but if by keeping the state of physically pressed keys you mean having a buffer of size 256 and updating each key (like we do in tests), there can be some issues with that if the user is not running as admin. This is somewhat what happened in ColorPicker and PowerToys Run since the old logic for those two keyboard hooks was storing key state. It can lead to false positives because an app running as admin may be in the foreground in between, so any key events there would not be updated in our local buffers. Normally this is not an issue (and it is sufficient to tell users that for KBM to work with elevated windows, KBM needs to be run as admin), but it can lead to cases where user holds Alt, presses an admin window and releases Alt while that is in focus. Now until a user presses Alt and releases Alt again on a non-admin window, KBM will think that Alt is pressed as per its local buffer.
This logic seems straightforward and makes sense (assuming updating the state has no side effects). But in code, apart from the first point, almost everything matches what is currently there in the HandleShortcutRemapEvent. While it is possible to reduce some lines of code by removing the logic which is used for minimizing number of key events, for the The only part which could cause issues in non-elevated state is the storing key state part. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I think it could have been less detailed, keyboardeventhandlers.md file almost duplicates code and can become irrelevant in the future.
Summary of the Pull Request
What is this about?
This PR adds dev docs for KBM.
The docs can be viewed in the rendered state at https://github.com/arjunbalgovind/PowerToys/tree/user/arbalgov/kbmDevDocs/doc/devdocs/modules/keyboardmanager
Navigate using the links from the Readme.
PR Checklist
Info on Pull Request
What does this include?
Validation Steps Performed
How does someone test & validate?
Validate that the links to different sections work as expected.