You are not logged in.

#1 2020-08-27 10:41:16

augustin
Member
Registered: 2020-08-27
Posts: 3

[SOLVED] DWM insert character on keyboard shortcut?

Is there a way to set up a keybinding to insert character (or simulate keypress) in DWM config?

I'm from Sweden but using US keyboard layout (due to it's advantages in programming).
However, sometimes I have to write in swedish and have to enter the characters åäö.
My current solution is a DWM keyboard shortcut to switch to swedish keyboard layout, but I would prefer to just have for example MOD + [ insert the å character.
I would prefer to not install additional software if there is a solution native to DWM.

I've searched around for quite a bit but haven't found a satisfactory answer, hence my first post here.
Thanks in advance!

Last edited by augustin (2020-08-29 11:55:57)

Offline

#2 2020-08-27 11:12:28

tucuxi
Member
From: Switzerland
Registered: 2020-03-08
Posts: 291

Re: [SOLVED] DWM insert character on keyboard shortcut?

Configure your xorg keyboard to use a compose key, e.g.

Section "InputClass"
          Identifier "system-keyboard"
          MatchIsKeyboard "on"
          Option "XkbLayout" "us"
          Option "XkbModel" "nodeadkeys"
          Option "XkbOptions" "compose:ralt"
EndSection

https://wiki.archlinux.org/index.php/Xo … ompose_key

Last edited by tucuxi (2020-08-27 11:54:24)

Offline

#3 2020-08-27 12:45:10

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,517
Website

Re: [SOLVED] DWM insert character on keyboard shortcut?

A compose key, as noted above, is almost certainly the best option.

But to your original question, you could spawn a tool like xdotool to have Mod+[ simulate a series of key presses.  But there would still need a series of key presses that would generate the desired character.  So if there already is a sequence of key presses to change the layout, enter that character, then change the layout back, then xdotool could work.  If you don't want an external program for this, you'd need to write your function in dwm to call XSendEvent for each of the needed key presses.

There is, however, no global way to "enter a character" as opposed to a keypress or series of key presses (what would it mean to "enter" it, enter it in what?)  You could also very easily have Mod+[ put a particular character into the primary and/or clibboard selection which would make it easy to paste this character in some other program, but you'd hardly need any dwm binding to do this.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2020-08-29 06:29:46

augustin
Member
Registered: 2020-08-27
Posts: 3

Re: [SOLVED] DWM insert character on keyboard shortcut?

Thank you tucuxi & Trilby for your answers!
I decided to go with xdotool to be launched with DWM keybindings.
For example, to type å:
{ MODKEY, XK_bracketleft, spawn,  {.v="sleep 0.2 && xdotool key aring"} }
Does the trick. Thanks!

Offline

#5 2020-08-29 11:53:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,517
Website

Re: [SOLVED] DWM insert character on keyboard shortcut?

cool: "key aring" - I didn't know xdotool had names for such characters.  I'm glad that helped - please remember to mark your thread  by clicking "edit" on your first post to prepend [SOLVED] to the title.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2020-08-29 11:58:02

augustin
Member
Registered: 2020-08-27
Posts: 3

Re: [SOLVED] DWM insert character on keyboard shortcut?

Trilby wrote:

I'm glad that helped - please remember to mark your thread  by clicking "edit" on your first post to prepend [SOLVED] to the title.

Ah, yes. Thanks for the reminder : )

Offline

Board footer

Powered by FluxBB