3

Using Kubuntu on a Macbook there is no delete key. Delete can be done with Backspace+Fn, but there is only one Fn on the farthest corner from Backspace, so that a delete action requires both hands.

I don't use CapsLock for uppercase, I use Shift for that, so CapsLock could be used for delete. I can make it act as a Backspace with the keyboard advanced settings, but this new Backspace doesn't work with Fn in order to delete.

How could I make CapsLock work as a key for "Backspace+Fn=delete" or simply turn it into a Delete key?

cipricus
  • 3,444
  • 2
  • 34
  • 85
  • Editing the xkb layout files certainly could cut it (assign Delete to <CAPS). On a PC keyboard, that probably has to be changed in /usr/share/X11/xkb/symbols/pc (key <CAPS> { [ Delete ] };, but I have no idea where to change that for an apple keyboard. – vanadium Apr 28 '22 at 11:50

2 Answers2

1

For both X11 and Wayland, you can use the remapper deamon keyd for this purpose. See this answer for installation, usage and tips.

After installation, use this config:

[ids]

[main]

capslock = delete

Rasmus
  • 8,375
0

X11 solution:

Here and here I have found that the keycode for Capslock is 66. From here I've got the command to remap Caps Lock as Delete:

xmodmap -e "keycode 66 = Delete"

After testing that it worked I have made it run at startup by creating the file ~/.config/autostart/capslock-delete.desktop (based on last link) with the lines:

[Desktop Entry]
Exec=sh -c 'xmodmap -e "keycode 66 = Delete"'
Name=capslock is delete
Terminal=false
Type=Application

It may happen that the Capslock key continues to trigger lock-uppercase beside doing delete. It needs to be disabled as said here, or in KDE, under keyboard settings - Advanced - Capslock behavior - Disable...

Update:

In case the solution of the said above desktop file or command to run at startup is not working, following this answer, this seems to work in Kubuntu 22.04:

  • create a file ~/.Xmodmap containing the keycode setting: keycode 66 = Delete

  • create a script like for example ~/bin/capslock.delete.sh:

     #!/bin/bash           
    sleep 1;               
    echo "running xmodmap" 
    xmodmap ~/.Xmodmap   
    
  • make the .sh file executable

  • add the same script file to be executed at startup


In case one still wants a key or key combination to lock the upper keys (the CapsLock key default behavior), the following command - involving xdotool - which can be associated with shortcut like Super+Delete or Alt+Delete (where the key pressed for Delete is of course the real/former CapsLock) - will do:

xdotool key Caps_Lock

Install xdotool:

sudo apt install xdotool

I have associated Alt+CapsLock with the command sh -c 'xdotool key Caps_Lock'.

(One would expect that xdotool might be used in the first place to get the delete action with a command like: xdotool key Delete, but that doesn't seem to work very well, as said here; I have been able to use it - sort of - with Ctrl+D, but that only deletes text to the right without deleting files.)

A good alternative to get the delete action (as well as others that I haven't tested) is to use AutoKey, described here, about the delete action:

enter image description here


Solution for Wayland:

I haven't tested because I don't use Wayland, but I have found here that xremap and modmap should work as alternatives to xmodmap. Also, see the other answer on keyd.

cipricus
  • 3,444
  • 2
  • 34
  • 85