evdevremapkeys icon indicating copy to clipboard operation
evdevremapkeys copied to clipboard

How can I remap a combination of keys to a single key?

Open tjanez opened this issue 6 years ago • 13 comments

Is it possible to map, e.g. a combination of Ctrl and left arrow keys to the Home key?

If yes, how can I specify that in the YAML configuration?

tjanez avatar Dec 27 '17 13:12 tjanez

No, I haven't had this use-case so I didn't implement it.

philipl avatar Dec 27 '17 20:12 philipl

No, I haven't had this use-case so I didn't implement it.

Ok, I see.

Would it be hard to implement N:1 mappings? I really got accustomed to using Fn + Left for Home and Fn + Fight for End on my Dell XPS 15, so I miss that when I use a regular external keyboard.

tjanez avatar Dec 29 '17 12:12 tjanez

It wouldn't be terribly hard - the main thing is you have to make the event mapping logic stateful as you need to track multiple keys being held down, and each of those is a separate event. There's a smaller problem of how you express a combination in the config syntax, but that can be solved for sure.

I'm not particularly motivated to implement this, but I'll happily take a PR for it.

philipl avatar Dec 30 '17 00:12 philipl

I am also interested in a feature like this.

Maybe the easiest way to implement this is using the following function? http://python-evdev.readthedocs.io/en/latest/tutorial.html#getting-currently-active-keys

if you want to remap Ctrl+s, you could check after each s-event whether the ctrl key is active, and only do the remapping in that case. No idea if this actually could work.

TheoRet avatar Jan 31 '18 01:01 TheoRet

That helps solve the event mapping. Still need to come up with an efficient config expression.

philipl avatar Feb 19 '18 17:02 philipl

I quickly hacked a way to handle N:N mappings: https://github.com/pronobis/evdevremapkeys

The input keys can be specified as a "tuple" in a config file, e.g.:

remapping:
    KEY_F1:
      - BTN_LEFT
    (KEY_LEFTMETA, KEY_F1):
      - KEY_LEFTCTRL
      - KEY_F5

All additional keys are simply passed from the input to the output, e.g. Shift+F1 will become Shift+BTN_LEFT and Shift+Meta+F1 will become Shift+Ctrl+F5.

Also, since I needed it, I added some basic functionality that allows remappings to be conditioned on the active window class (for X11 only for now), e.g.:

    (KEY_LEFTMETA, KEY_F1, Google-chrome):

Key repeating ('repeat' and 'delay' config options) is not yet implemented/tested for N:N mappings.

pronobis avatar Jul 25 '18 08:07 pronobis

happy user of @pronobis fork. please consider a merge. thanks! ;-)

rpodgorny avatar Aug 30 '19 14:08 rpodgorny

I merged #16 which provides an equivalent capability in a different way, although it doesn't do anything like window mapping. That's beyond the scope of what I want this program to do.

philipl avatar Aug 30 '19 14:08 philipl

The problem I had with modifier_groups is that as soon as I define one for say ALT key, all other combinations won't work anymore (like ALT+TAB). Fork of @pronobis worked just fine :)

sjentzsch avatar Jan 18 '20 22:01 sjentzsch

I need a way not just to capture multiple keys, but also to suppress additional scancodes from multiscancode keys. (my HP EliteBook 735 G6 has a very strange keyboard)

I did some work based on @pronobis work here: https://github.com/philipl/evdevremapkeys/issues/22

kolAflash avatar Jun 05 '20 19:06 kolAflash

The problem is you have to wait for all keys pressed to decide whether or not to remap to a single.

SO if you are remapping CTRL+X to "BKSPACE", everytime ctrl is pressed, evedevremapkeys will have to not send the ctrl code on until it sees the next key. So remapping CTRL+X to a single key delays the handling for all CTRL combos. This is true of all N to 1 mappings.

DanielJoyce avatar Aug 18 '20 17:08 DanielJoyce

Probably a bug in modifier group handling. My suspicion is if you have a modifier group for Ctrl-A, and you press Ctrl-B, it forgets to send on the original Ctrl code.

The of "Modifiers" doesn't really exist at the event level, so I don't necessarily think this is the best implementation.

What is seen is CTRL-pressed B pressed B released Ctrl-released.

If we had a syntax for supporting A is pressed and then B is pressed vs A pressed B pressed B released A released, we could be a bit more flexible.

Hmm.

DanielJoyce avatar Aug 19 '20 18:08 DanielJoyce

@pronobis "All additional keys are simply passed from the input to the output" is it possible to disable this feature?

cjh9 avatar Apr 18 '21 16:04 cjh9