Linux Key Customization¶
Disabling Default Key Functions¶
In Linux, key functions are handled by systemd-logind. You can disable or customise key behaviour by editing its configuration file.
# Edit the logind configuration
sudo nano /etc/systemd/logind.conf
# Uncomment and modify the following lines as needed
HandlePowerKey=ignore
HandleSuspendKey=ignore
HandleHibernateKey=ignore
HandleLidSwitch=ignore
# Restart the service for changes to take effect
sudo systemctl restart systemd-logind
Note
- Desktop version: The user key (e.g., power button) typically opens the logout dialogue by default. This can also be disabled in the desktop environment settings.
- Server version: The user button triggers a system shutdown by default. The configuration above ignores the event entirely.
Listening to Key Events¶
After disabling the default actions, applications can listen for key events via the input event devices:
# List all input devices
cat /proc/bus/input/devices
# Monitor key events (replace eventX with the actual device)
sudo hexdump /dev/input/event1
Example output: