pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.58k stars 834 forks source link

How to synergise Karabiner-elements with existing dead keys in a .keylayout #2818

Open dlejay opened 3 years ago

dlejay commented 3 years ago

It the .keylayout I am using, dead keys are created in the following way: the key is sent to a dedicated action as this one

<key code="41"  action="my_dead_key" />

then the action my_dead_key activates a special "state"

<actions>                                     
    <action id="my_dead_key">              
      <when state="none" next="amazing_dead_key" />

which in turn will change the behaviour of other keys. For example:

<action id="1">
      <when state="none"       output="1" />
      <when state="amazing_dead_key"        output="@" />
</action>

I would like to map a modifier key to act as the dead key. Simply putting the key code number does not work on macOS and thus Karabiner seems to be the tool for the tax.

How do I write a complex modification that maps a modifier key to the "my_dead_key" action? Is it actually possible?

MuhammedZakir commented 3 years ago

Why not do that using only Karabiner? You can do that using variables.


If you must use kelayout, then one simple solution I can think of is to map modifier to a function key you don't use (F1-F20) and use the keycode of that function key in keylayout.


A doubt: to activate that dead key, do you have hold it down, or just tap it?

dlejay commented 3 years ago

First, the answer to the last question: just tap it.

I have tried mapping the modifier key to something else. Here is what I have found out: remaping right_command to semicolon (keycode = 41) works to activate the dead key. But if I use the 50 keycode (grave accent) for the dead key and remap right_command to grave_accent_and_tilde, then the dead key will always spit out a grave accent. I have no idea why.

I also tried a more complex remapping; remapping right_command to: right_option and to_if_alone: semicolon. And if I press the right command key alone, nothing happens (but still gives me a right_option if pressed in a combination).

MuhammedZakir commented 3 years ago

Have you tested your config with EventViewer? Verify you're getting the correct key.

I don't know what are the causes of the problems you mentioned. I have to test it myself, and I won't be able to do that in a few days.


Again: do you have to use keylayout? Can't this be done with just Karabiner using variables?

dlejay commented 3 years ago

Some new things: I managed to make the "to_if_alone" part work. I had placed it under "simple_modifications"; under "complex_modifications" it works (initially, I didn't think this had an impact).

So on an ANSI keyboard, I can correctly remap a key to grave_accent_and_tilde and get the desired behaviour (assuming the grave accent key is already my dead key). But then a new phenomenon appears that has nothing to do with Karabiner. If the grave accent key is a dead key, the layout is impossible to select if I am not using a Terminal. Also, I cannot remove all the other keyboard layouts in my list and only have that one. Somehow macOS wants a backup keyboard and is using the backup keyboard outside of the Terminal.

There seems to be something special about the "the key left of 1" on ANSI keyboards happening.

I need to do more testing for the JIS keyboard. In particular, a standard JIS keyboard does not have a grave_accent_and_tilde key present. So what happens when I select a remapping to grave_accent_and_tilde in Karabiner? Is Karabiner simply remapping to something it knows or is it remapping to another keycode?

To answer the last question: I do not have to use keylayout and I haven’t seen examples of dead keys created with Karabiner variables. So I don’t know.

MuhammedZakir commented 3 years ago

Karabiner won't change keyboard type when you remap a key. It should only intercept keypress, and send same or different keycode depending on your config. All keycodes Karabiner uses are what keyboards use, which is dictated by Apple. There is no Karabiner-specific keycodes.

To answer the last question: I do not have to use keylayout and I haven’t seen examples of dead keys created with Karabiner variables. So I don’t know.

What all symbols do you want to type using the dead key?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.