XKB will be appropriate for Xwindows or Wayland GUIs. It will not affect virtual consoles, but GUI terminal emulators will be fine. For XKB background I'll point you to some (overview, system vs user) .. other (custom options) .. answers (custom rules).

The following will allow you to add a new option like caps:myf13 to an existing XKB layout with whatever tools you'd normally use (setxkbmap, localectl settings, GNOME panel, etc).


Defining the option

Existing XKB capslock options are listed in /usr/share/X11/xkb/rules/evdev.lst. Looking at the corresponding options in the .../rules/evdev file, you can see these options are all loaded from the file .../symbols/capslock. All of them are modifier keys, which probably aren't the best example, but caps:backspace might be a good comparison. Looking at the file, we find the stanza defining this option:

hidden partial modifier_keys
xkb_symbols "backspace" {
    key <CAPS> { [ BackSpace ] };
};

grep'ing through the other symbol files, we can see that the F13 symbol is simply F13. The new option stanza might look like this:

hidden partial modifier_keys
xkb_symbols "myf13" {
    key <CAPS> { [ F13 ] };
};

As you can see, we only changed the name of the option and the symbol assigned to the key.


Hooking it up

The only thing left to do is hook up the new stanza. On a basic Xwindows system, using commandline tools like setxkbmap and xkbcomp, a custom user location will do fine; for GNOME, KDE or a Wayland system you'll need to make your changes in the system XKB database.

As an example for system changes (you will need sudo access to create or edit these files):

  • Place the custom stanza in a new symbol file, eg /usr/share/X11/xkb/symbols/mycaps.

  • Add this to /usr/share/X11/xkb/rules/evdev just below the line for caps:backspace:

      caps:myf13   =   +mycaps(myf13)
    
  • ... add to /usr/share/X11/xkb/rules/evdev.lst:

      caps:myf13      Caps Lock is F13
    
  • ... add to /usr/share/X11/xkb/rules/evdev.xml:

          <option>
            <configItem>
              <name>caps:myf13</name>
              <description>Caps Lock is F13</description>
            </configItem>
          </option>
    
  • Finally, make backups of your .../rules/evdev* files, or create a patch file. Your changes will be overwritten whenever the xkb-data package is updated. If you saved your modification stanza into the .../symbols/capslock file, it will need to be backed up as well.

Once these changes are made, you should be able to set this option as if it were any other XKB option. You may need to restart any GNOME/KDE session for control panels to pick up the changes, but tools like setxkbmap should find it immediately: setxkbmap -option caps:myf13