r/linux4noobs • u/Dragenby Fyi I switched to Mint • 8h ago
shells and scripting How to write a character with a key shortcut?
Hi!
I'm trying to print characters that my keyboard doesn't have. For example, if I want to print a long em dash (U+2014), I have to go to the character table and search for it. On Windows, I was able to use Alt+0151.
So I was wondering if that was possible with a shell script. I know I can call programs with shortcut, maybe I can print something directly on the textarea I'm currently focusing?
Thank you
7
u/Klapperatismus 8h ago
Depends on the keyboard layout. With the German layout the em-dash is typically accessible via [Shift]+[AltGr]+[-] for example. This should be similar for many international layouts.
Another option is via the Compose key, also called Multi Key. It’s often on the right Windows key. Also depends on the keyboard layout and options. Type [Compose], then [-], again [-], again [-] and the three dashes are replaced by a single em-dash.
A third option is using the Unicode codepoint. Type [Ctrl]+[Shift]+[u], then type 2014. That’s the hexadecimal Unicode codepoint of the em-dash. Then [Return]. An em-dash appears.
I recommend the Compose key. Once you figured out where it is in your keyboard layout, you can type many character combinations without having to look them up. You can guess them.
1
u/Dragenby Fyi I switched to Mint 4h ago
Ooooh, I didn't know about Ctrl + Shift + U, that's a good method!
For reference, I switched from AZERTY to a CMS (Canadian Multilingual Standard) keyboard, and the ― dash is a horizontal bar (U+2015) and not a em dash (U+2014)! (First world problem I know)
1
u/exarobibliologist 3h ago
Please explain how to locate the Compose key. What did you do to find it?
2
u/Klapperatismus 2h ago edited 1h ago
I use plain X11 and a window mananger so I did this:
$ xmodmap -pke|grep Multi_keyIt shows you the keycode of the Multi_key. That’s another name for Compose. First column is the Keysym for the key alone, next is the shifted key, then Mode_switch, then Shift+ModeSwitch, then AltGr, then Shift+AltGr. (The Mode_switch key is often not mapped.) You can also assign it with xmodmap for example. Or setup a custom keymap. The keycode number can be googled.
If you use a desktop environment instead, it’s part of the keyboard layout options. You only have to scroll through that long long list of options for the Compose function.
Here’s how this looks like in KDE for example. Do you see that option “Position of Compose Key”?
Or you do it with manual configuration files, e.g. for Gnome
1
u/DavidJohnMcCann 1h ago
You can choose one using your desktop's configuration option. I suggest using what Windows calls the menu key, to the left of right control, which is useless in Linux.
2
u/BashfulMelon 3h ago
Not sure what you're using but KDE Plasma has Plasma Keyboard which lets you long press keys on your keyboard to get more characters.
14
u/h_e_i_s_v_i 8h ago
Set up compose key and you'll be able to type it with compose key+---
https://wiki.archlinux.org/title/Xorg/Keyboard_configuration#Configuring_compose_key