I am asking and answering my own question here in case it is useful to someone else, as it has taken me a long time to come up with a solution!
I have a Sun Microsystems Type 7 keyboard that has a set of 11 extra keys on the right hand side, and I would like to be able to program them to do something useful in kubuntu. But when System Settings is waiting for a keypress of the key to program, nothing happens for most of the keys when I press them. The exception is Cut, Copy and Paste: these three I can assign Ctrl+X, Ctrl+C and Ctrl+C to, and they work generally in applications (and, when I press them in System Settings, the correct key name is even displayed).
So how to get the other special keys to be recognised?
First, I noticed that various Sun keyboards are listed in System Settings/Input Devices/Keyboard/keyboard model. So I chose mine, Type 7, with a UK layout. Then I used
xev
and noticed that when I press any of the special keys, they are recognised and a keycode, the correct name and a keysym are displayed. Also poking around the various X11 keyboard files it is clear that Sun keyboard support is definitely supposed to be there, at least in X.After a lot of faffing around, in the end I used
xmodmap
to assign high-numbered function key values to the special keys. I put the commands in a script file I callsunkeys
, which contains:(I'll come to the sleep bit in a moment.)
The function keys F13 to F23 are not on the keyboard but are in the X system and kubuntu System Settings knows about them, and when they are pressed it allows things to be assigned to them. The
setxkbmap
line reprograms the right AltGraph key to be a right control key.But although running
sunkeys
from the command line programs the keys ok, when I putsunkeys
at the end of my~/.profile
file, the keys did not get programmed when I rebooted. It turns out for some reason there needs to be a delay before you runxmodmap
, hence thesleep
business in the script above. So at the end of my ~/.profile file I now have the lineThis makes the sunkeys script sleep for 15 seconds before it does the
xmodmap
commands. The&
at the end of thesunkeys
line tells the shell to continue booting whilesunkeys
sleeps. Without the&
, you type your password when logging in and then the system then appears to hang for 15 seconds.I now have all the extra keys doing the obvious useful functions. I assign Ctrl+S (= save in most applications) to the big Help key. And Ctrl++ and Ctrl+- for soom in and out to the unobvious Front and Props keys as they are next to each other.
As a bonus the Compose key actually does what it is supposed to with no further changes: to enter
café
I typec
a
f
Compose
e
'
.Update: I did a quick test booting from a kubuntu 20.04 USB stick and it appears that System Settings sees most of the special keys, and displays their names correctly, with the exception of Front and Props. So when I eventually upgrade I will still use this technique.