Improve performance by reducing ctypes calls #497
Closed
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.
From my testing (albeit with a quite heavily modified version of this script), this provides a roughly 30x performance boost with measurements taken from the first line of
_modifier_state
to the line after thelayout_data
assignment in__call__
for the unmodified version and from the first line of__call__
to the line after thelayout_data
assignment in__call__
.The test was conducting by pressing 4 regular keys (asdf), 4 shift keys ("!#¤), 2 more shift keys (() open and close parentheses) and then 2 ctrl+alt keys ([] open and close brackets). After this, I made a sum of all the measured times between the previously mentioned lines and compared those sums with each other.
From my research, there shouldn't be any problem with some keyboards having different shift/ctrl/alt keys since the vkCodes for these should be the same across all keyboard according this documentation: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
IMPORTANT NOTE: This would also require a change to
Listener._event_to_key
inkeyboard/_win32.py
since it as of now does not pass "special keys" toKeyTranslator
at all, however, I think that theKeyTranslator
class should be the one to deal with those as well (especially since it already has access to thewin32_vks.py
module)As a final note I would just like to say that I've enjoyed sifting through this project to extract the parts needed for my own and I want to thank everyone that has contributed to it