mooz / xkeysnail

Yet another keyboard remapping tool for X environment
890 stars 112 forks source link

Interleave pressing/releasing of modifier keys. #137

Closed laech closed 2 years ago

laech commented 3 years ago

Fixes #43, fixes #82, by pressing new modifier keys before releasing the old ones to avoid triggering actions in applications that recognize the old keys.

For example, if we bind alt+f to ctrl+right, before this change, the following key sequence is generated with alt+f :

(user)       send Key.LEFT_ALT   Action.PRESS
(xkeysnail)  send Key.LEFT_ALT   Action.RELEASE
(xkeysnail)  send Key.RIGHT_CTRL Action.PRESS
(xkeysnail)  send Key.RIGHT      Action.PRESS
(xkeysnail)  send Key.RIGHT      Action.RELEASE
(xkeysnail)  send Key.RIGHT_CTRL Action.RELEASE
(xkeysnail)  send Key.LEFT_ALT   Action.PRESS
(user)       send Key.LEFT_ALT   Action.RELEASE

The press + release of the alt key (both at the start and end of the sequence) is what's causing apps like Firefox to show/focus the menu.

After this change, the following key sequence is generated with alt+f:

(user)       send Key.LEFT_ALT   Action.PRESS
(xkeysnail)  send Key.RIGHT_CTRL Action.PRESS
(xkeysnail)  send Key.LEFT_ALT   Action.RELEASE
(xkeysnail)  send Key.RIGHT      Action.PRESS
(xkeysnail)  send Key.RIGHT      Action.RELEASE
(xkeysnail)  send Key.LEFT_ALT   Action.PRESS
(xkeysnail)  send Key.RIGHT_CTRL Action.RELEASE
(user)       send Key.LEFT_ALT   Action.RELEASE

So the difference here is that we press the ctrl key before releasing alt, so will not trigger apps like Firefox to show hide the menu when alt+f is used, and a single press and release of the alt key will still show the menu as their normal behavior.

As far as I can observe, this is also the behavior of AutoHotKey on Windows.