rvaiya / keyd

A key remapping daemon for linux.
MIT License
2.9k stars 171 forks source link

Can I trigger a layer's bindings using another keyboard? #289

Closed ziontee113 closed 2 years ago

ziontee113 commented 2 years ago

Hello and thank you for the amazing project.

I'm currently have a default.conf file, which scoped to 1 keyboard, and a super.conf file scoped to a 2nd keyboard.

I have this example in super.conf file (for 2nd keyboard)

[ids]

# R8 keyboard
1a2c:2124

[main]

z = a
x = overload(xxx_layer, y)

[xxx_layer]

0 = macro(S-f12 S-f12 0)
1 = macro(S-f12 S-f12 1)
2 = macro(S-f12 S-f12 2)

When I hold x in my 2nd keyboard and press 1 with the same keyboard, the macro executes, which is great. When I hold x in my 2nd keyboard and press 1 with my First keyboard the macro does not executes, it simply behaves like I just press 1 with my First Keyboard, which is what I have questions about.

My question is: Can I pick and choose which key, in which keyboard to execute a macro (or any regular mappings)? Thank you very much!

nsbgn commented 2 years ago

My question is: Can I pick and choose which key, in which keyboard to execute a macro (or any regular mappings)? Thank you very much!

Not right now; that would be a feature request. However, you can use the same configuration file for multiple keyboards, which will then share mappings (cf #202). Is that enough?

If not, I'm curious to learn more about your use case. I can imagine that it would make some sense to allow an optional filter-by-keyboard-ID for individual keys (for example, by prefixing them with the keyboard ID(s)). This would actually benefit myself, too, since I currently just have my footswitch send unused keys to skirt the issue. That very minor benefit, on its own, is not enough to defend the introduction of additional complexity --- but your use case might.

ziontee113 commented 2 years ago

However, you can use the same configuration file for multiple keyboards..

My problem is that I don't know how to configure individual keys of each keyboards in the same config file (if it's even possible). Let's say you want your primary keyboard to behave like a "normal" keyboard, and you want every single key on your second keyboard to be a "modifier key".

I have this bizarre use case in Neovim. On specific events, I'd have autocmds calling keyd -e to programmatically enable / disable my keyd layers, so that they only works in Normal Mode, Visual Mode etc.. so they don't hinder my typing when I'm in Insert Mode. Let's say I'm in Normal Mode, I hold down z, and I press p or n to go to the previous / next tab.

If that's not already far gone enough, I'm thinking of having a 2nd keyboard to have more modifier keys, or just more keys --> more macros / mappings. Maybe I'm just a lunatic, but I think there's definitely a use for it.

herrsimon commented 2 years ago

I have this bizarre use case in Neovim. On specific events, I'd have autocmds calling keyd -e to programmatically enable / disable my keyd layers, so that they only works in Normal Mode, Visual Mode etc.. so they don't hinder my typing when I'm in Insert Mode. Let's say I'm in Normal Mode, I hold down z, and I press p or n to go to the previous / next tab.

If I may chime in: Given the complete customizability of neovim, a cleaner approach would probably be to use the application-mapper and deactivate any special keyd functionality while neovim is used, implementing all your layers and macros in neovim.

If that's not already far gone enough, I'm thinking of having a 2nd keyboard to have more modifier keys, or just more keys --> more macros / mappings. Maybe I'm just a lunatic, but I think there's definitely a use for it.

Regularly, people use a dedicated numpad for this. However, I doubt that using such an additional “modifier keyboard” would be efficient, as your hands would have to reach for it. During the time you lose by reaching, you could press a lot of keys on your keybaoord (accessing several nested layers for example). If you need more modifiers, you could try overloading the letter keys, although in my personal opinion keyd's support for this is not complete at the moment (see #278).

ziontee113 commented 2 years ago

Given the complete customizability of neovim, a cleaner approach would probably be to use the application-mapper and deactivate any special keyd functionality while neovim is used, implementing all your layers and macros in neovim.

Well holding down z then press p is a much nicer experience than pressing z then p for me. It's subjective, but I'm enjoying my experience quite a bit.

Regularly, people use a dedicated numpad for this. However, I doubt that using such an additional “modifier keyboard” would be efficient, as your hands would have to reach for it.

It depends on desk and the type of keyboards you have honestly. My idea is to have a full sized keyboard, rotated 90 degress (so it's vertical), on the left side of your main keyboard as a "modifier keyboard". While your right hand still at hjkl. I think it's cool because I'm a lunatic :smile:

herrsimon commented 2 years ago

Well holding down z then press p is a much nicer experience than pressing z then p for me. It's subjective, but I'm enjoying my experience quite a bit.

I'm surprised that you can't reconfigure 'z' from a leader to a modifier key directly in neovim.

It depends on desk and the type of keyboards you have honestly. My idea is to have a full sized keyboard, rotated 90 degress (so it's vertical), on the left side of your main keyboard as a "modifier keyboard". While your right hand still at hjkl. I think it's cool because I'm a lunatic

At least about a hundred additional modifiers, that's something! Instead of a rotated regular keyboard, the same can be achieved by placing the sides of (one or more) split keyboards to the left and right of your keyboard, but I'm of course not endorsing either of these setups at all. Here is a good market overview, there are lots of models with more keys than your fingers will ever be able to handle.

ziontee113 commented 2 years ago

I'm surprised that you can't reconfigure 'z' from a leader to a modifier key directly in neovim.

Being a terminal-based application has it's drawbacks. You'd have to configure your terminal emulator to differentiate C-I with Tab etc.. That why I use keyd to be able to hold down keys.

Here is a good market overview, there are lots of models with more keys than your fingers will ever be able to handle.

Thank you for the information. I'm poor right now and don't have a job yet, so it'll be quite some time till I can get one. I'm also living in Vietnam so it's even more difficult to get my hands on one of those. I'm currently using Microsoft Ergonomic Keyboard, which I just wish that I can cut off the arrow keys and the numpad :smile:

herrsimon commented 2 years ago

I'm surprised that you can't reconfigure 'z' from a leader to a modifier key directly in neovim.

Being a terminal-based application has it's drawbacks. You'd have to configure your terminal emulator to differentiate C-I with Tab etc.. That why I use keyd to be able to hold down keys.

I'm still convinced that properly configuring your terminal emulator (and then implement all neovim mappings directly in neovim) is less of a hassle and also simpler than using keyd for this purpose. But I also don't use neovim a lot, so maybe there's some lack of understanding from my side.

Thank you for the information. I'm poor right now and don't have a job yet, so it'll be quite some time till I can get one. I'm also living in Vietnam so it's even more difficult to get my hands on one of those. I'm currently using Microsoft Ergonomic Keyboard, which I just wish that I can cut off the arrow keys and the numpad smile

I bet that once you have grown a bit older, you will desire other things than lots of potential modifiers...

ziontee113 commented 2 years ago

Hi @rvaiya , after some time, I finally have a justified use case for this feature.

Short story is: I now use two keyboards to type. One for each hand. I ditched the Microsoft keyboard because it's very heavy to type and gives me pain. I went on a whim and try out having 1 keyboard for each hand, and it feels amazing to type. I can't afford or able to buy a split keyboard atm so 2 keyboards. :sweat_smile:

Everything is fine and dandy, until I try out mapping keys for individual keyboards. Back then, I used to map Capslock+hjkl to Arrow keys. It works just fine on 2 keyboards. Only if I don't remap any keyboard individually.

Here's my example: default.conf

[ids]
*
[main]
capslock = overload(capslock, esc)

This works fine, until I add another file, 2ndKeyboard.conf

[ids]
my_kb_id
[main]
b = x

Now I can no longer hold down Capslock on my left hand, and press hjkl to trigger Arrow Keys :(

I wish I can solve this somehow. Thank you very much!

ziontee113 commented 2 years ago

I wonder if implementing the feature of prefixing mappings with keyboard id will take a lot of work. It's such a shame that I don't know how to write C. Man, I'm even thinking about learning C just to make this happen. :sweat_smile:

@rvaiya @slakkenhuis @herrsimon what do you guys think about this feature? Should I learn C to implement this? If so, which files in the project should I start from? Thank you very much :smile:

herrsimon commented 2 years ago

I think that your very exotic use case is too specific for keyd. Instead, the following solution comes to mind:

Use the interception tools to either

  1. map some physical keys of one of the keyboards to keycodes of keys not present on the other keyboard (F13-F24 etc., see keyd list-keys for inspiration) via intercept | mapping_script | uinput and then have keyd manage this virtual keyboard and the other physical one in the same config.

  2. merge both physical keyboards into a virtual one with a lot of different keys (using mux, still remapping the keys of one keyboard to keycodes not present on the other one) and manage this using keyd.

Apart from this, split keyboards are actually not that expensive, especially if you build them yourself. See for example the Cantor. Of course you will still pay more than for a standard off-the-shelf rubber dome keyboard.

ziontee113 commented 2 years ago

Thank you very much @herrsimon , I'll look into the merge keyboards approach. Thank you very much for the info!

ziontee113 commented 2 years ago

@herrsimon Thank you very much for the suggestion for Intercepting the keyboards. I ended up using kmonad to modify each keyboard, then keyd can join them and it works like a charm. Thank you so much :pray:

gerardbosch commented 10 months ago

@herrsimon Thank you very much for the suggestion for Intercepting the keyboards. I ended up using kmonad to modify each keyboard, then keyd can join them and it works like a charm. Thank you so much 🙏

Thanks @ziontee113 for confirming that Kmonad and keyd can coexist 😃😃.

Just if it helps someone landing here:

I already had a more or less complex setup for KMonad but there was something I was not able to achieve with it (swapping ;/: and \/|, and other symbols that are on the same key). It has been really easy and clear to do that with keyd 🎉, and without resigning to existent KMonad setup :)

I'm running keyd as systemd system service, while KMonad as systemd user service. So the trick to make them play well together was to put only the KMonad keyboard id under [ids] section, then:

P.S. Running journalctl -f -u keyd you find the KMonad id.

Final setup files:

Related discussions: