Is there something equivalent to symlinks to keyboard strokes?
I want to make one specific key (numeric keypad '.' button) to act like an ALT+A. More specifically I want that all applications receive ALT+A when I press numeric keypad '.'.
Tks!
Is there something equivalent to symlinks to keyboard strokes?
I want to make one specific key (numeric keypad '.' button) to act like an ALT+A. More specifically I want that all applications receive ALT+A when I press numeric keypad '.'.
Tks!
I am not aware of a solution at the level of the keyboard map, but probably you could achieve what you want using the X automation tool xdotool
.
Setup
xdotool
with the command sudo apt install xdotool
.Then create a very small script with the following content. A script is a small text file with the "Execute" file permission enabled. You could create this file in a folder "macros" somewhere under your home folder. For the purpose of this example, I will assume you are storing macros in a folder macros
in the hidden folder .local
in your home folder (so it is never in your way during your daily work).
So create that folder first with your file manager or with the command mkdir ~/.local/macros
.
Then create the script macros
and open it in your text editor with the command gedit ~/.local/macros/send_alt_a
Put following content in that file:
#!/usr/bin/xdotool
keyup KP_Separator
key Alt+a
Save and close the file.
Make the script executable by editing its properties using your file manager, or with the command: chmod +x ~/.local/macros/send_alt_a
Now assign the macro to the keyboard shortcut Numeric keypad '.' using "Keyboard Shortcuts" in "Settings" (provide the full path name to the script in the "Add Custom Shortcut" dialog if the script is not in a folder that is within the search path (as for ~/.local/macros/
).
Comments on the script
You may need to introduce a little delay in the script for it to work (reliably). If needed, insert a command such as sleep 0.2
on the second (or perhaps better as the third line). This causes a delay of 0.2 seconds before the script is continued.
The command keyup KP_Separator
simulates a release of the hotkey used to trigger the macro. That avoids any interference that could happen when you physically have the key pressed while the script simulates pressing another keyboard combination. The full list of key names xdotool
understands is available from freedesktop.org. Since this is a single key (no modifier), the command may actually not be needed.
I assume that the Keyboard Settings dialog of Gnome Shell will, in assigning keyboard shortcuts, differentiate between the '.' on the normal and numerical keypads. If it doesn't, try sxhkd
or xbindkeys
.
xdotool
, so I post that as an answer – vanadium Oct 08 '20 at 07:40