houmain / keymapper

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

Bug with Any key as input in sequence #137

Closed kbilsted closed 1 month ago

kbilsted commented 2 months ago

I am trying to define a repeat key on Y that repeats the last pressed key

Any Y >> Any Any

gives some really weird results

ristomatti commented 2 months ago

Perhaps an alias with params could work better?

kbilsted commented 2 months ago

example?

houmain commented 2 months ago

gives some really weird results

Indeed, but it works as expected. When you press any key it is not output because it waits whether a Y follows or not. If you press Y then the previously entered key is output twice. But if you press some other key then it can no longer match Any Y and the previous key is output and the new key waits until Y is pressed or not.

houmain commented 2 months ago

Do you have by any chance a QWERTZ keyboard and mixed up the Y and Z keys? That's what I did at first.

kbilsted commented 2 months ago

i think for this to be usable I need to use parameters and exclude modifiers

kbilsted commented 2 months ago

what is really needed is a notion of a keybuffer, so that when you press a key it is sent to the screen, then when the magic button is pressed, it will then output the next character, this makes you type less in the blind.. If you want the magic key to replace the output it has to send backspace characters in order to replace content...

but i realize that having a char buffer is radically different to the functional approach so probably this idea is too far off.. I know other keymappers having support for this, e.g. kanata, but I was frustrated with how they handled ALT keys

ristomatti commented 2 months ago

@kbilsted Espanso which I've recommended earlier to check out could possibly be more suitable for this. It is specifically for typed string replacement and supports regex patterns and capture groups. So it can do the backspacing required for this.

I've been thinking about how to solve a bit related need. I'd like to do Vim style leader key mappings but also find it problematic doing it blind as you can't be sure if the initial trigger sequence has gotten registered (or typed correctly).

The vague plan I've been thinking about would involve triggering a virtual key to temporarily enter a different "mode". I would then have an external script waiting for the virtual key to be pressed and then output e.g. the list of valid following keys on the window manager taskbar. Involving a virtual key as a mode would also allow a cleaner config as I could have the follow up keys declared in a separate context block. I haven't yet experimented with the idea though so not sure if this will work or not. :)

ristomatti commented 2 months ago

I have to say though that your plan of having Any Y as the trigger sounds like it would create a noticeable lag for each typed key? I've generally been avoiding to have any common alphas even as the first key in the trigger sequence as it inevitably makes the typed text output in a "staggered" way. Doesn't this bother you? 🤔

With something like Espanso this would not be the case though as it allows the keys to be typed normally and then acts based on that. But I'm not sure if using it in this manner would just end up with your following characters getting mixed up with what Espanso types after it detects the matching sequence. I haven't tried using any type of wildcard as the initial key in a sequence either.

kbilsted commented 2 months ago

@ristomatti thanks for all the ideas! I think espanso is not the way forward. just looked at it again.. you idea of another mode sounds cool! I also was thinking about similar ideas.. also with an idea of having an overlay display the keyboard and light up the keypresses.. this will make it much easier learning a new keyboard layout... I haven't been able to find a keyboard overlay .. but search engines are really difficult to get good results from at the moment it seems

ristomatti commented 2 months ago

@kbilsted You mean something like https://alternativeto.net/software/screenkey/

kbilsted commented 2 months ago

Thanks but i wish for a whole keyboard being displayed:)

kbilsted commented 2 months ago

I gave up and made one myself .. muuuuch easier than i thought ;)

kbilsted commented 2 months ago

@houmain do you think that there could be a notion of a "char buffer" that can be used in as output

then one can define

Any Y >> BUFFER[0]
ristomatti commented 2 months ago

At least to me that sounds like going too deep in the technical details compared to the other features. I'm not for or against the end result you are after, but the example syntax you suggest would make quite an unexpected special case since it could as well mean calling something like this:

BUFFER = 'Hello ' $0

Any Y >> BUFFER[0]  # When pressing any key followed by Y, the output would be: Hello 0
kbilsted commented 2 months ago

semantics over syntax. The importance is a notion of a buffer of the last N typed characters

eg

Any Y >> Buffer<0>   

or

Any Y >> Buffer.Get(0)
houmain commented 2 months ago

what is really needed is a notion of a keybuffer, so that when you press a key it is sent to the screen, then when the magic button is pressed, it will then output the next character, this makes you type less in the blind.. If you want the magic key to replace the output it has to send backspace characters in order to replace content...

This sounds more to me like you are after a new feature on the input side. So the keys are not hold back but can still participate in the input matching, right? Something like:

X? Y >> Backspace Z     # the ? is the new syntax
X    >> W

X would immediately output W and not wait for the potentially following Y, then if a Y follows it would trigger the first mapping, delete the W and output Z.

kbilsted commented 2 months ago

Well there are a few variations on what an adaptive key is.

To some it is a repeat of the previous key.

To others it is a way to reduce Same-finger-bigram

Others again use it to make typing more efficient by autocompleting several characters such as T Y >> "the" and T F Y >> "therefore" etc

and yes, keys are not held back and may thus require the use of backspace

ristomatti commented 2 months ago

Are the other your referring to implementing this on QMK (or some other firmware) or another keymapping tool run on the computer?