### Integrate xmodmap with X Session Startup Source: https://context7.com/xorg/app/llms.txt Examples for invoking xmodmap during X session startup for automatic application of keyboard preferences. ```sh xmodmap ~/.xmodmaprc ``` ```sh echo "xmodmap ~/.xmodmaprc" >> ~/.xprofile ``` ```sh [ -n "$DISPLAY" ] && xmodmap ~/.xmodmaprc & ``` ```sh xmodmap -n ~/.xmodmaprc ``` ```sh xmodmap -pke > ~/keyboard-backup-$(date +%Y%m%d).xmm xmodmap -pm >> ~/keyboard-backup-$(date +%Y%m%d).xmm ``` ```sh xmodmap ~/keyboard-backup-20240101.xmm ``` -------------------------------- ### xmodmap Command-Line Usage Examples Source: https://context7.com/xorg/app/llms.txt Various ways to invoke xmodmap from the command line to inspect or modify keymaps. Use diagnostic flags to view current settings without making changes. ```sh # Show the current modifier map (default when no action flag is given) xmodmap ``` ```sh # Show all options xmodmap -help ``` ```sh # Show the expression grammar xmodmap -grammar ``` ```sh # Print the current keymap table (raw hex + name form) xmodmap -pk ``` ```sh # Print the keymap table as re-feedable xmodmap expressions xmodmap -pke ``` ```sh # Print the pointer button map xmodmap -pp ``` ```sh # Print the modifier map xmodmap -pm ``` ```sh # Target a specific X display xmodmap -display :1 ``` ```sh # Dry-run: show what would be done without applying changes xmodmap -n ~/.xmodmaprc ``` ```sh # Apply a mapping file xmodmap ~/.xmodmaprc ``` ```sh # Read expressions from stdin xmodmap - ``` ```sh # Print version and exit xmodmap -version # Output: xmodmap 1.0.11 ``` -------------------------------- ### Swap Caps_Lock and Control_L with xmodmap Source: https://context7.com/xorg/app/llms.txt This canonical example demonstrates the safe way to exchange two modifier-linked keys by removing them, swapping their keysym bindings, and re-adding them to their respective modifiers. ```sh xmodmap /path/to/swap.km ``` ```sh xmodmap -e "remove Lock = Caps_Lock" \ -e "remove Control = Control_L" \ -e "keysym Control_L = Caps_Lock" \ -e "keysym Caps_Lock = Control_L" \ -e "add Lock = Caps_Lock" \ -e "add Control = Control_L" ``` ```sh cat > ~/.xmodmaprc << 'EOF' ! ! 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 EOF xmodmap ~/.xmodmaprc ``` -------------------------------- ### Remap Keycode to Keysyms Source: https://context7.com/xorg/app/llms.txt Map a specific numeric keycode to one or more keysyms. Supports decimal, hex, and octal notation for keycodes. Can assign up to eight keysyms per keycode and clear all keysyms from a keycode. ```sh # Map keycode 22 (Backspace on many keyboards) to Delete xmodmap -e "keycode 22 = Delete" ``` ```sh # Map keycode 66 (CapsLock) to Control_L xmodmap -e "keycode 66 = Control_L" ``` ```sh # Assign multiple keysyms: unshifted=comma, shifted=less-than xmodmap -e "keycode 59 = comma less" ``` ```sh # Use hex keycode notation xmodmap -e "keycode 0x42 = Escape" ``` ```sh # Assign to any free keycode xmodmap -e "keycode any = XF86AudioPlay" ``` ```sh # Clear all keysyms from a keycode (pass no keysyms after =) xmodmap -e "keycode 999 = " ``` ```sh # Script file version — assign several keys at once cat > /tmp/remap.xmm << 'EOF' ! Remap function keys keycode 67 = F1 F11 keycode 68 = F2 F12 keycode 89 = Escape EOF xmodmap /tmp/remap.xmm ``` -------------------------------- ### Remap Keysym to Keycodes Source: https://context7.com/xorg/app/llms.txt Find keycodes associated with a keysym and apply a keycode operation. This is more portable than using raw keycodes. Can be used to add alternate symbols to existing keys. ```sh # Remap BackSpace key (found by its current keysym) to produce Delete xmodmap -e "keysym BackSpace = Delete" ``` ```sh # Add Meta_L as an alternate symbol on the Alt_L key xmodmap -e "keysym Alt_L = Meta_L Alt_L" ``` ```sh # Attach Meta to Multi_key without disturbing existing Multi_key behaviour xmodmap -e "keysym Multi_key = Multi_key Meta_L" ``` ```sh # Make shifted comma produce < and shifted period produce > cat > ~/.xmodmaprc << 'EOF' ! Fix angle brackets keysym comma = comma less keysym period = period greater EOF xmodmap ~/.xmodmaprc ``` -------------------------------- ### Add Keysyms to Modifiers with xmodmap Source: https://context7.com/xorg/app/llms.txt Use 'add' to assign keysyms to modifier slots. This is useful for making keys like Control_L act as the Control modifier or assigning Super keys to Mod4. ```sh xmodmap -e "add Control = Control_L" ``` ```sh xmodmap -e "add Lock = Caps_Lock" ``` ```sh xmodmap -e "add Control = Control_L Control_R" ``` ```sh xmodmap -e "add Mod4 = Super_L Super_R" ``` -------------------------------- ### Remap Pointer Buttons with xmodmap Source: https://context7.com/xorg/app/llms.txt The 'pointer' expression remaps physical button codes to logical button codes. Setting a code to 0 disables the button. 'pointer = default' resets the mapping. ```sh xmodmap -e "pointer = 3 2 1" ``` ```sh xmodmap -e "pointer = default" ``` ```sh xmodmap -e "pointer = 1 0 3" ``` ```sh xmodmap -e "pointer = 3 2 1 4 5" ``` -------------------------------- ### Add Keysyms to Modifier Slot Source: https://context7.com/xorg/app/llms.txt Adds keycodes mapped to specified keysyms into a modifier slot. Keysyms are resolved after parsing, ensuring safety in swap sequences. -------------------------------- ### Remove Keysyms from Modifiers with xmodmap Source: https://context7.com/xorg/app/llms.txt Use 'remove' to detach keysyms from modifier slots. Keysym names are resolved before the rest of the batch executes, allowing safe removal even if the key's symbol is changed later. ```sh xmodmap -e "remove Lock = Caps_Lock" ``` ```sh xmodmap -e "remove Control = Control_L" ``` ```sh xmodmap -e "remove Mod1 = Alt_L" ``` -------------------------------- ### Clear Modifier Slots Source: https://context7.com/xorg/app/llms.txt Removes all keycode entries from a specified modifier slot. This is often a prerequisite for reassigning modifiers to avoid conflicts. Supports Shift, Lock, Control, Mod1-Mod5. ```sh # Remove all keys from the Lock (CapsLock) modifier xmodmap -e "clear Lock" ``` ```sh # Remove all keys from Control xmodmap -e "clear Control" ``` ```sh # Clear Mod1 (usually Alt/Meta) xmodmap -e "clear Mod1" ``` ```sh # Clear multiple modifiers from a script cat > /tmp/clear_mods.xmm << 'EOF' clear Lock clear Mod2 EOF xmodmap /tmp/clear_mods.xmm ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.