How to make xmodmap changes permanent?

While using xmodmap to remap meta key with the following command:

xmodmap -e 'keycode 133 = F14'

The change is not permanent, especially on system sleep, resume and reboot

Reboot

On the setting panel (KDE/GNOME) there is a startup section where application can be added to startup session, xmodmap can be added there

Resume

Xmodmap does not keep the changes after sleep/resume, here is how to set xmodmap on system resume with systemd: (non systemd user can use this)

Note about export DISPLAY=:0 and sleep 10: Depending on the configuration this may be useful, this service is run as root by systemd, xmodmap apply the configuration to x (graphical interface) and thus export DISPLAY=:0 permit to indicate that the setting is applied to display 0, this may be required if the current user is not root. As the service is called on resume after sleep, sleep 10 is there to make sure everything is loaded, let say if you use an external bluetooth keyboard and the kernel module is not yet loaded or similar case, sleep 10 will give it extra time to load before applying the settings.

Share this post on:

Related posts:

How to remove a systemd's service?
Monitor a process or a service on a KDE Desktop