1

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!

1 Answers1

2

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

  1. Install 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).

  1. So create that folder first with your file manager or with the command mkdir ~/.local/macros.

  2. 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.

  1. Make the script executable by editing its properties using your file manager, or with the command: chmod +x ~/.local/macros/send_alt_a

  2. 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

  1. 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.

  2. 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.

  3. 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.

vanadium
  • 88,010
  • such a splendid answer! Thank you very much. Just one comment: you need to use the full path in the "Keyboard Shortcuts" in "Settings". Using ~/.local/send_alt_a did not work. I used /home/ubuntu/.local/send_alt_a instead. An I confirm that Gnome differentiate between the normal and numerical keypad '.'. Thank you very much again. – Chocksmith Oct 08 '20 at 10:49
  • Thank you very much for the detailled feedback. Indeed, because this script is not in the search path, you need to supply the full pathname. – vanadium Oct 08 '20 at 11:31