How to create a keyboard shortcut to emulate a specific keystroke (not a command)?

I am using Ubuntu 19.10 on a Mac, and so I do not have a Delete key on my keyboard.

To emulate that key, I can do Fn + Backspace but I would like to choose another combination of keys like Super + Backspace. Is this possible?


This will do the job:

Firstly: edit the XKB /usr/share/X11/xkb/symbols/pc file by running the following command in the terminal:

sudo nano /usr/share/X11/xkb/symbols/pc

Secondly: find this line:

key <BKSP> {    [ BackSpace, BackSpace  ]   };

And comment it out by adding // before it like so:

//key <BKSP> {  [ BackSpace, BackSpace  ]   };

Thirdly: copy and paste the following code below the commented line in secondly above:

key <BKSP> {
    type= "PC_SUPER_LEVEL2",
    symbols[Group1]=  [ BackSpace, Delete ]
};

And save the file.

Fourthly: clear the XKB cache by running the following command in the terminal:

sudo rm -rf /var/lib/xkb/*

Finally: reboot your system to activate your new xkb configuration or reload the new xkb configuration by setting an xkb map layout using the following command in the terminal:

setxkbmap -layout us

and test your new key combination.


This solution should make pressing Super + Backspace work as pressing the Delete key.

To change the combination to Shift + Backspace you can change PC_SUPER_LEVEL2 to PC_SHIFT_LEVEL2 in thirdly above.


A command could emulate a specific keystroke. One way to do this is to create a custom shortcut to run xdotool (source) on Settings > Keyboard > Custom Shortcuts:

screenshot

  • Possible duplicate/related: here and here.
  • Another way