houmain / keymapper

A cross-platform context-aware key remapper.
GNU General Public License v3.0
298 stars 25 forks source link

Sequential Any inconsistency #26

Closed Azarattum closed 2 years ago

Azarattum commented 2 years ago

I've been trying to implement VIM replace hotkey when I stumbled upon a weird behavior while using Any key in sequential input.

Case 1

Minimal reproduction configuration:

R Any >> Any

The problem:

This behavior is inconsistent and creates a weird edge case when Any is the same as the key before. The outputs should either be rrr rr1 (assuming any includes the whole sequence) or rr r1 (assuming any maps to any in input).

Case 2

Another potentially related issue:

R Any >> !R Any

Gives:

!R is expected to block the first R, but not the Any one according to the documentation.

!A means that the (potentially pressed) key should be released BEFORE the rest of the expression is applied

Case 3

This gets even crazier when you try to use it with Shift modifier.

R Shift{Any} >> Any

Gives:

Here 2 regular Rs output one symbol, but one regular + capital output 3! Also when pressing 1 after 2 Rs, it gives you an extra r.

The Goal

What I ultimately want to achieve is to make this work:

R Shift{Any} >> replace
R Shift >>
R Any >> replace

replace >> !R Delete Any ArrowLeft

And now it works with every key except for R. To make it work every time I added these 2 lines above:

R Shift{R} >> Delete Any ArrowLeft Backspace # Need backspace to account for extra R
R R >> Delete Any ArrowLeft

Which is not pretty... :(

Ideally I would want this to work with a one liner like R Shift?{Any} >> Delete Any ArrowLeft with an optional Shift modifier (which transfers to the output anyway). But I guess that but be a separate feature request...

Specs

Keymapper: 1.9.1 OS: Windows 10 (1809) have not tested on Linux yet

Azarattum commented 2 years ago

I've been testing input this entire in VSCode. I have no idea why, but when I tried the first case in notepad 0_o

In Windows Search I get 2 or 3 Rs somewhat randomly. Browser search bar gives 2 Rs. Terminal Window gives 4!

WOW! This is crazy

https://user-images.githubusercontent.com/43073346/160141507-cf04cd54-25d0-4eeb-94bb-2204151cf587.mp4

Azarattum commented 2 years ago

I think I found a somewhat reliable solution that works everywhere. The key is to use R literally in the edge cases instead of Any.

R R >> Delete R ArrowLeft
R Shift{R} >> Delete Shift{R} ArrowLeft

R Shift{Any} >> replace
R Shift >>
R Any >> replace

replace >> !R Delete Any ArrowLeft

However it's still really ugly...

Edit:

This

R R >> !R Delete R ArrowLeft
R Shift{R} >> !R Delete Shift{R} ArrowLeft

is equal to this

R R >> Delete R ArrowLeft
R Shift{R} >> Delete Shift{R} ArrowLeft

for some reason... So I removed !R there.

houmain commented 2 years ago

Yes, the Any key needs more work. The different behavior depending on focused application is indeed very strange. I could also reproduce the 3 in Notepad and 4 in Powershell... Thanks for reporting! I will investigate this and try to make Any output only what it matched on the input side. Then this should work: R Shift{Any} >> Delete Shift{Any} ArrowLeft R Any >> Delete Any ArrowLeft

houmain commented 2 years ago

Hi Azarattum, this is fixed with commit ba44c8ab967d0f51d1219f0bae4102cf744f45e9 and will be in the 1.10 release.