#Fun with XKB

Fat Finger Suppression

I have long had this habit of accidentally hitting return when pressing single quote, particularly when touch-typing text and getting to a word with an apostrophe. You can use XKB to suppress this. It's a little arcane, but first thing is to create a key type called "FAT_FINGER":

xkb_types "complete" {
    virtual_modifiers NumLock,Alt,LevelThree,LAlt,RAlt,RControl,LControl,ScrollLock,LevelFive,AltGr,Meta,Super,Hyper,FatFinger;
...
    type "FAT_FINGER" {
        modifiers= Shift+FatFinger;
        map[FatFinger]= Level2;
        level_name[Level1]= "Base";
        level_name[Level2]= "Fat Finger";
    };

This essentially says that when the FatFinger virtual modifier is active (but Shift is not, so this doesn't apply to double quote), use the second keysym for a given key press. Next, have the apostrophe key activate this virtual modifier:

xkb_compatibility "complete" {
    virtual_modifiers NumLock,Alt,LevelThree,LAlt,RAlt,RControl,LControl,ScrollLock,LevelFive,AltGr,Meta,Super,Hyper,FatFinger;
...
    interpret apostrophe+AnyOfOrNone(all) {
        virtualModifier= FatFinger;
        action= SetMods(modifiers=FatFinger,clearLocks);
    };

This says "while apostrophe is pressed (along with anything else or nothing) turn on the FatFinger virtual modifier". Then, set it up so the return key maps to nothing when the FatFinger virtual modifier is active:

    key <RTRN> {
        type= "FAT_FINGER",
        symbols[Group1]= [          Return,        NoSymbol ]
    };

Finally, keys used to activate virtual modifiers need to map to a real modifier to be active in XKB (even if that real modifier isn't used anywhere, so Mod5 is my dumping ground for this kind of thing):

    modifier_map Mod5 { <AC11> };

where AC11 is the symbol for the apostrophe+double quote key code in my XKB config.

The only downside of this config is that it's a little aggressive. What I really want is to suppress the return key for only 50ms or so after apostrophe is pressed. This solution will often suppress return in natural typing in which you intend to hit return after a single quote, such as when writing Python or shell code, because when touch typing you will usually hit the next key before completely releasing the previous one. To me this is a reasonable trade-off: a little annoyance rarely vs. a lot of annoyance frequently.

aLtErNaTiNg cApS

To simplify trolling, you can use XKB to automatically alternate caps while typing. This makes clever use of the LatchMods function and the Action mechanism to toggle between levels upon each keypress when Scroll Lock is on.

xkb_types "complete" {
...
    type "KEYCRAP" {
        modifiers= Shift+Lock+ScrollLock;
        map[Shift]= Level2;
        map[Lock]= Level2;
        map[ScrollLock] = Level3;
        map[Shift+ScrollLock] = Level4;
        map[Lock+ScrollLock] = Level4;
        map[Shift+Lock+ScrollLock] = Level3;
        level_name[Level1]= "Base";
        level_name[Level2]= "Caps";
        level_name[Level3]= "AltBase";
        level_name[Level4]= "AltCaps";
    };

...

xkb_symbols "pc+us+inet(evdev)+altwin(meta_win)+capslock(ctrl_modifier)+compose(rwin)+shift(both_capslock_cancel" {
...
    key <AD01> {
        type= "KEYCRAP",
        symbols[Group1]= [               q,               Q,               q,               Q ],
        actions[Group1]= [ NoAction(), NoAction(), LatchMods(modifiers=Lock), NoAction() ]
    };
...repeat for every letter key...

    modifier_map Mod2 { <SCLK> };