Since there doesn't seem to be a lot of stuff on here about xmodmap (besides people posting their configs or some simple remappings) , I thought I'd post what I've learned from using it. It's all pretty basic, but I thought it might help someone, and I already had most of this written as a reference for myself.
For remapping in Linux you have primarily two options: xkb (X KeyBoard extension) and xmodmap.
From the Arch Linux Wiki:
"xmodmap is not directly related to XKB, it uses different (pre-XKB) ideas on how keycodes are processed within Xorg. Generally it is not recommended to use xmodmap, except maybe for the simplest tasks."
If you just want to get a custom keyboard layout that is not offered by linux (you're using something like QGMLWY) or add some basic capslock navigation functionality, xmodmap is a good solution. You can write the commands for what you want even before installing linux, put them in a document on usb drive for, and simply paste them into the terminal or load them from a file after the installation. Using xmodmap may be a good intermediate stage if you want your custom layout immediately and plan on messing with xkb later. This obviously isn't a problem if you're using colemak (since linux already has it available.. you can use xmodmap though: https://colemak.com/Unix), but if you want capslock navigation immediately before messing with xkb, it is very easy to set up. For me, setting up basic navigation with xmodmap and colemak looks like this (NoSymbol is unnecessary; it just gets rid of any keysym that was there before.. i.e. if you had "aacute" for altgr it would erase that) :
keycode 66 = Mode_switch (Mode_switch)*
keysym e = e E Up NoSymbol NoSymbol NoSymbol
keysym n = n N Down NoSymbol NoSymbol NoSymbol
keysym h = h H Left NoSymbol NoSymbol NoSymbol
keysym i = i I Right NoSymbol NoSymbol NoSymbol
keysym o = o O Prior NoSymbol NoSymbol NoSymbol
keysym k = k K Next NoSymbol NoSymbol NoSymbol
keysym l = l L Home NoSymbol NoSymbol NoSymbol
keysym u = u U End NoSymbol NoSymbol NoSymbol
keysym y = y Y BackSpace NoSymbol NoSymbol NoSymbol
keysym w = w W Escape NoSymbol NoSymbol NoSymbol
keysym s = s S Shift_L NoSymbol NoSymbol NoSymbol
keysym a = a A Alt_L
*adding another Mode_switch allows you to use normal shift and still get up, down, left, etc. Even without this, using capslock+s will still give you shift up, down, left, etc., but using normal shift will just give you the capital letter.
Xmodmap could also be considered an easy portable solution if you ever counter a situation where you have to use linux on another computer (probably unlikely) as you can easily reverse what you have done or simply restart. Entering these commands in this way is temporary and will be undone after restart. You can specify 6 levels with xmodmap:
Level 1:
1. normal
2. shift
Level 2: (obtained with a Mode_Switch key)
3. whatever your mode switch key is (capslock)
4. shift + above (This is now working for me; I'm not sure what I was doing wrong before)
Level 3: (obtained with ISO_Level3_Shift)
5. altgr (or key defined as ^)
6. shift altgr
You can define more layers after this without xmodmap complaining to you, but I don't know if you can actually get them to work. For example, ISO_Level5_Shift is valid, but it doesn't work and does very screwy things (I wouldn't recommend trying it; you might have to restart)
Changing Your Mappings
The basic format is as follows:
keycode or keysym (code or sym) = 1 2 3 4 5 6
!This is a comment
To use this temporarily, you can put it in a file and load it from the terminal by going to the directory where it is saved and entering the command "xmodmap filename" To undo your changes, you will either have to restart or load another file that reverses the changes made. Another way to do this is to type the commands directly into the terminal like this:
xmodmap -e "keycode 40 = s S" ; xmodmap -e "another command" ; etc.
To have it load automatically, you can create .Xmodmap file in your /home/user directory. This will work for some DEs. Otherwise you will have to add something to your xinitrc (see arch wiki). I wouldn't recommend testing changes with a file that automatically loads. If you mess up something, it may be hard to change it back.
Useful Terminal Commands
xmodmap -pke gives you your current mappings
xmodmap -pm gives you your current modifiers (you can have 4 keys for each modifier)
xev will give you they keycodes for your keys
xmodmap /path/to/dir to load a config file (exactly the same syntax as in terminal, jut no xmodmap -e; ! is comment)
Something I've never used...
xmodmap -e "<KEYCODE> <MODIFIER> = <behaviour> <behaviour_with_modifier>"
Also for control you have to add (and maybe remove) to get a key working as control (i.e. mapsomething = Control L.. on next line: add control = Control_L... same for other things listed under -pm; add mod2 = ...)
Stuff that WILL work:
•Multimedia keys (ex: XF86AudioMute; see /usr/include/X11/XF86keysym.h)
•Any of these will work: http://wiki.linuxquestions.org/wiki/Lis … by_Xmodmap
•You can do an ISO_Level3_Lock (*see below for more info on locks)
What WON'T work:
•Keeping corresponding xkb symbols for any keysyms or keycodes remapped
•I don't think you can make dead keys
•I have not been able to map control, lock keys, or the windows key (super) to inside a caps layer. Control DOES work, but results in a glitch that makes the first level of that key also control.
CapsLock Navigation
You just define caps as a Mode_switch key (which goes under mod5) and then capslock will act as a modifier to access whatever you have defined on level 3. Shift works fine. Control is very buggy for me. I've tried adding it in multiple ways, and it works, but control will be randomly pressed when you are normally typing even without holding down CapsLock; this results in a whole bunch of unwanted "ctrl o"s, "ctrl t"s, "ctrl n"s, and pretty much makes things unusable. I'm not really sure why this happens, and most of the documentation I've read on xmodmap has been lacking. Again, it isn't the most elegant solution, but it's hypothetically an okay way to temporarily get some functionality.
AltGr Layers and Unicode
To specify that it is a unicode symbol, type U then the code.
This won't work:
keycode 23 = q Q Tab NoSymbol ⁂ ❄
This will work:
keycode 23 = q Q Tab NoSymbol U2042 U2744
Also note that symbols like semicolon and brackets cannot be written like ";" or "[". "," is comma, ";" is semicolon, "[" is bracketleft, "\" is backslash, "$" is dollar, etc. See the link above for valid keysyms or use xev to find them.
Locks**
I just found out that you can also do locks. Can be nice if you're going to be using a layer for a while and don't want to hold a modifier. The only lock I've gotten working at this point is "ISO_Level3_Lock"
Something that should be noted about it is that it will work flawlessly when mapped to a key like numlock. It will not work in a layer, but it will work if mapped to something like grave when done in a certain way:
keycode 77 = ISO_Level3_Lock (you can do a lock key like this)
keycode 49 = ISO_Level3_Lock NoSymbol NoSymbol NoSymbol ISO_Level3_Lock
(this is for a normal key)
If you don't do this, you can turn it on but not off (.. which may result in you having to restart your computer). This is because, once you turn it on, pressing the key again will
result in the level 3 output of that key. If not defined as the same thing, it won't switch back.
Setting a lock to a level that doesn't have necessary keys for typing or navigation, which would essentially serve as a keyboard lock (especially if you have nothing defined for that layer except for the lock key). Right now, I don't necessarily see how this fact would really benefit anyone. It certainly doesn't serve as a replacement to a screenlocker, but I can only imagine the frustration of someone who stole my laptop after finding that none of the keys work. Assuming they did manage to get past the lock screen and figure out how to turn off this layer lock, I can only imagine how frustrated they would be to find that I'm using colemak... Colemak, a surefire way to mess with anyone who steals your things. Hopefully no one's things get stolen though.
There is also a Shift_Lock, but I couldn't get it to do anything. I don't know if there is a lock for level 2 (Mode_switch), but Mode_lock (or Lock) does not work (not a valid name) nor does ISO_Level2_Lock.
Glitches
I have come across a lot of glitches. If you're going to experiment with heavily with stuff not listed here be prepared to have to restart.
There seem to be glitches between levels and their shifted states. For example, if shift in an extend layer is held for a while and the shifted version of the shift key in the extend layers is Z (keysym s = s S Shift_L Z) it will type ZZZZ. I assume this has something to do with repeating. There will be no such glitch if you don't have anything defined on the next level, and even if you do, it's still usable (takes long enough for the ZZs to pop up to use shift for what you need). I don't really see the point in defining something for the shifted state of shift though.
You can also have two shifts on a level, but it doesn't seem that you can use both of them at the same time to shift two levels up.
To Test
Whether you can embed Mode_Switch or ISO_Level3_Shift in a higher level. I might have tested this, but I do not remember. I doubt it will work.
**Note, you can do a lot of other things by using more than just Xmodmap. If you like remapping look into the following (I use about half of these happily):
xbindkeys, sxhkd, xchainkeys, and actkbd for binding stuff
dual key functionality (release vs held down):
xcape (and space2ctrl and keydouble) for modifiers to something on release (i.e. Escape or BackSpace on control release)
Don't be mislead by these. None of them work to turn a normal key (i.e. space) into a modifier (i.e. control). Typing will be a disaster.
at home modifier- the best software currently on linux for using normal keys (i.e. s, space, etc.) as modifiers; has a fast type feature that prevents some accidental keypresses, but I have not found it to be totally useable
faking mouse/keyboard input ; controlling stuff:
xvkbd, xdo, xdotool, xsendkey, xsendkeycode, xautomation (xte), wmctrl
random other stuff:
pyuserinput
etc.