rvaiya / keyd

A key remapping daemon for linux.
MIT License
2.87k stars 170 forks source link

How do I remap SHIFT+4 to $? #388

Closed tarjei closed 1 year ago

tarjei commented 1 year ago

Hi, I've been trying to remap SHIFT+4 on a keyboard with the "Norwegian no dead keys" layout in Ubuntu.

I've tried a few combinations but none of them seem to have any effect:

[no_shift:S]
¤ = $ 
[main]
shift+4=$
[main]
¤=$

Any tips?

rvaiya commented 1 year ago

keyd operates at the level of the keycode, the names used by the config file correspond to the names found on a standard ANSI keyboard (though right hand unicode values can be assigned (see the relevant section of the man page)). By default, leftshift = layer(shift), so your goal is to remap 4 within the shift layer which can be achieved like so

[shift]
4 = $

Note that $ will generate the key codes <leftshift> <4>, how this is interpreted by your display server will depend on the active keymap.

tarjei commented 1 year ago

Thanks @rvaiya , but no dice :(

What is the easiest way to debug which keycodes are sent to keyd?

Regards, Tarjei

rvaiya commented 1 year ago

You can use keyd monitor to see what actually gets sent to the display server. While keyd is disabled, this corresponds to the input from your keyboard(s), while keyd is active it corresponds to the output of the keyd virtual device (i.e the translated output).

tarjei commented 1 year ago

Hmm seems correct:

Metadot - Das Keyboard Das Keyboard 24f0:0140   enter up
Metadot - Das Keyboard Das Keyboard 24f0:0140   rightshift down
Metadot - Das Keyboard Das Keyboard 24f0:0140   4 down
Metadot - Das Keyboard Das Keyboard 24f0:0140   4 up
Metadot - Das Keyboard Das Keyboard 24f0:0140   rightshift up
Metadot - Das Keyboard Das Keyboard 24f0:0140   rightcontrol down
Metadot - Das Keyboard Das Keyboard 24f0:0140   c down

Config:

[ids]
*

[main]

capslock = overload(control, esc)

[shift]
4 = $

This on Ubuntu 22.04 running i3 + i3-gnome-flashback btw. grm3 + Xorg.

rvaiya commented 1 year ago

Sorry, I just realized [shift] 4 = $ is redundant. Does pressing S-4 produce $ while keyd is disabled? If not, then you will need to alter your display server keymap. keyd cannot send keysyms directly to the key server (it operates at the level of the keycode), so if S-4 doesn't produce $ without keyd, it won't produce it with keyd. You need to figure out which physical keys allow you to enter $ and map those within your shift layer. What is the output of xmodmap -pke|grep dollar?

tarjei commented 1 year ago

@rvaiya no problem! (And Thank You for persisting in helping me).

Here's the output of xmodmap:

$xmodmap -pke|grep -i dollar
keycode  13 = 4 currency 4 currency dollar onequarter dollar onequarter 4 dollar

When keyd is disabled, S-4 produces ¤.

ajgrf commented 1 year ago

@tarjei There's no way to type $ with your chosen keyboard layout. You could try the "Norwegian (Macintosh, no dead keys)" layout to see if that works for you. It includes the dollar sign at Shift-4 already. Otherwise, you'll need to mess with xkb or xmodmap to get what you want.

ajgrf commented 1 year ago

Actually, disregard that. I think this might work:

[shift]
4 = G-4
rvaiya commented 1 year ago

I believe @ajgrf is correct. To clarify,$ is just syntactic sugar for S-4 which can be a source of a confusion for non-qwerty/ANSI users. It seems $ is mapped to altgr+4 in your layout which corresponds to G-4 in keyd.

tarjei commented 1 year ago

YAY! Success! Thanks a bundle! Big kudos to @rvaiya and @ajgrf!