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

Add support for locking keys #1278

Conversation

benoit-pierre
Copy link
Member

Summary of changes

Closes #1161. Depends on #1276 (included).

How it works:

  • a regular {#combo} key combo now can end with keys left in the pressed state
  • a new {##combo} key combo syntax allow continuing a preceding combo
  • otherwise, sending a new combo, sending backspaces, or sending a string will automatically disengage previously held keys
  • when keys are being held, the keyboard machine is fully suppressed (the whole keyboard is suppressed, all keys, including events with modifiers)
  • that's pretty much it!

I ended up moving some of the key combo handling one level higher, in the engine: the KeyboardEmulation.send_key_combination method no expect a pre-parsed list of event to send (pairs of [pressed: boolean, key_code]), parsing and validation is done in the engine.

Because the Windows implementation does not monitor keyboard layout changes though events, but instead would refresh the layout before sending a key combo / backspaces / string, the output instance can now be used as a context manager:

with output:
    output.send_backspaces(...)
    output.send_string(...)

The layout is refreshed on __enter__ on Windows. And on Linux, display.sync() is called at __exit__.

The (keyboard) machine suppression now has 3 possible modes:

  • SUPPRESSION_NONE: no suppression (e.g. when output is disabled)
  • SUPPRESSION_PARTIAL: only suppress some keys (standard mode when output is enabled)
  • SUPPRESSION_FULL: full suppress the keyboard: only used while a combo is active (held keys)

TODO:

  • more tests, including actually testing it works as expected on Linux/Windows/macOS
  • finish TODO...

Pull Request Checklist

  • Changes have tests, but more needed
  • News fragment added in news.d. See documentation for details

Sub-classing the platform KeyboardCapture/KeyboardEmulation class
as keyboardcontrol.KeyboardCapture can lead to non-obvious issues,
e.g. because KeyboardCapture in the context of machine.keyboard
is not the same class as KeyboardCapture in the context of
oslayer.xkeyboardcontrol, making using class attributes more
difficult.

Also move the keys layout to the keyboard machine where it belongs.
@benoit-pierre benoit-pierre added this to the post 4.0.0 milestone Apr 19, 2021
@user202729
Copy link
Member

user202729 commented Apr 20, 2021

Note: need a rebase. (on the dependent pull request)

@petercpark
Copy link

I'm interested in this pull request. Can we make it happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants