The xmodmap(1) man page has an example for exactly this
!
! Swap Caps_Lock and Control_L
!
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
but if you want to finish doing it the way you started, I think you need to add at least the remove
and add
lines
remove Lock = Caps_Lock
remove Control = Control_L
keycode 37 = Caps_Lock
keycode 66 = Control_L
add Lock = Caps_Lock
add Control = Control_L
I'm guessing that's the case based on this paragraph
add MODIFIERNAME = KEYSYMNAME ...
This adds all keys containing the given keysyms to the indi‐
cated modifier map. The keysym names are evaluated after all
input expressions are read to make it easy to write expressions
to swap keys (see the EXAMPLES section).
which makes it sound like modifier changes (shift, control, etc.) don't get applied until you run that too.
(And logically the same with remove
)
The keycode
version has the advantage of being idempotent, meaning that the effect won't change if xmodmap is run multiple times.
There are a lot of players between your keyboard and the process that finally handles the keyboard event. Among the major pieces of the landscape are the fact that the X system has its own keyboard-handling layer, and X associates different "keycodes" with keys than your Linux base system does. The showkey
command is showing you the keycodes in Linux-base-system lingo. For xmodmap
you need the X keycodes, which are what xev
is displaying. So long as you're planning to work in X and do your key rebinding with xmodmap
, then, ignore showkeys
and just listen to what xev
says.
What you want to look for in your xev
output are blocks like this:
KeyPress event, serial 27, synthetic NO, window 0x1200001,
root 0x101, subw 0x0, time 6417361, (340,373), root:(342,393),
state 0x0, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 27, synthetic NO, window 0x1200001,
root 0x101, subw 0x0, time 6417474, (340,373), root:(342,393),
state 0x8, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
xev
tends to generate a lot of output, especially when you move your mouse. You may have to scroll back a while to find the output you're looking for. In the previous output, we see that the keysym Alt_L
is associated with the X keycode 64
.
Best Answer
That's not possible with xmodmap. I don't think it's possible with XKB either, but I'm not sure.
Is your aim to have a key that's always identical to pressing Ctrl+C (e.g. in a terminal, it would interrupt the running program), or to have a clipboard copy key? If the latter, try
The
XF86Copy
keysym is intended for a copy-to-clipboard key, but I don't know how many applications have that shortcut out-of-the-box.If you're on Ubuntu, and possibly even if you aren't, the recommended method to set up additional (“multimedia”) keys is keytouch.
If you really want the key to be equivalent to Ctrl+C, your desktop environment or window manager may let you bind the keysym to a command that generates key press and release events for that key combination. If you prefer or must use a DE/WM-agnostic method, you can use xbindkeys to bind an arbitrary shell command to a key, and xmacro to manufacture key events to send to a window. You'll still need to have a keysym associated with the key; a good choice is
F13
(or wherever the numbered function keys on your keyboard leave off). Then put this in your~/.xbindkeysrc
:You'll need to start
xbindkeys
with your X session — from your~/.xinitrc
or~/.xsession
if you have one, or from the appropriate configuration interface in your DE/WM.