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

Added extended flag for navigation keys (Windows) #184

Merged
merged 1 commit into from
Sep 17, 2023

Conversation

klapovav
Copy link
Contributor

This commit fixes a bug that occurs when simulating navigation keys in combination with Shift in Windows.

So far, it has not been possible to select text reliably using (Ctrl) + Shift + Navigation key. The result of this action was inconsistent and dependent on the state of the numlock. If numlock was on, Shift+RightArrow did not mark one letter, but moved the cursor. The reason for this is obvious from the sequence of keyboard messages that appear in the system queue.

The following code should cause 6 keyboard messages to appear in the Windows system message queue, but the system releases the Shift key while the navigation key is held down. If you are interested in the details, check out The effect of numLock & The effect of Shift

enigo.key_down(Key::LShift);
enigo.key_click(Key::RightArrow);
enigo.key_click(Key::RightArrow);
enigo.key_up(Key::LShift);

Message log from the low-level hook
Before:

Keyboard event | scan: (0x)00  | virtual: LShiftKey = (0x)A0     flags INJECTED
Keyboard event | scan: (0x)22A | virtual: LShiftKey = (0x)A0     flags        KEY_RELEASED      
Keyboard event | scan: (0x)00  | virtual:     Right = (0x)27     flags INJECTED
Keyboard event | scan: (0x)00  | virtual:     Right = (0x)27     flags        KEY_RELEASED
Keyboard event | scan: (0x)2A  | virtual: LShiftKey = (0x)A0     flags INJECTED       
Keyboard event | scan: (0x)22A | virtual: LShiftKey = (0x)A0     flags        KEY_RELEASED       
Keyboard event | scan: (0x)00  | virtual:     Right = (0x)27     flags INJECTED
Keyboard event | scan: (0x)00  | virtual:     Right = (0x)27     flags        KEY_RELEASED
Keyboard event | scan: (0x)2A  | virtual: LShiftKey = (0x)A0     flags INJECTED      
Keyboard event | scan: (0x)00  | virtual: LShiftKey = (0x)A0     flags INJECTED, KEY_RELEASED

After:

Keyboard event | scan: (0x)00 | virtual: LShiftKey = (0x)A0     flags INJECTED
Keyboard event | scan: (0x)00 | virtual:     Right = (0x)27     flags EXTENDEDKEY, INJECTED
Keyboard event | scan: (0x)00 | virtual:     Right = (0x)27     flags EXTENDEDKEY, INJECTED, KEY_RELEASED
Keyboard event | scan: (0x)00 | virtual:     Right = (0x)27     flags EXTENDEDKEY, INJECTED
Keyboard event | scan: (0x)00 | virtual:     Right = (0x)27     flags EXTENDEDKEY, INJECTED, KEY_RELEASED
Keyboard event | scan: (0x)00 | virtual: LShiftKey = (0x)A0     flags INJECTED, KEY_RELEASED

@pentamassiv
Copy link
Collaborator

Thank you very much for your PR. I will have a look at it within the next two weeks. Sorry about the delay

@pentamassiv
Copy link
Collaborator

Other than the above comments, the PR looks good and is ready to be merged.

@pentamassiv pentamassiv force-pushed the ext_nav_keys branch 2 times, most recently from 58b7c70 to fbc6dea Compare September 1, 2023 02:22
@pentamassiv
Copy link
Collaborator

@klapovav I was unable to reproduce the issues you described. I am only using a VM to test Windows though so that might be why. For me the text consistently is marked before and after the change. Do you have an idea why or do you know of another way this issue can be observed?

@pentamassiv pentamassiv merged commit 0b04706 into enigo-rs:master Sep 17, 2023
9 checks passed
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.

2 participants