Disable Automatic Airplane Mode in Ubuntu 22.04 HP Laptop

For laptop user, there could be a quite annoying issue that the ‘Airplane Mode’ automatically turns on when lid closed, or when the screen is tilted sideways.

For HP laptops running Ubuntu, Fedora, or other Linux using systemd, there’s a workaround by mapping the HP e057 and e058 scancodes to 240 (no-op key). So it won’t automatically turn on Airplane Mode, while the option in ‘Wi-Fi’ settings and fn + F12 key combination still function.

NOTE: This tutorial is tested and works in my Ubuntu 22.04 on HP 246 laptop. It may or may not work in your machine.

1. Create service to remap the scancode:

1.) Firstly, press Ctrl+Alt+T on keyboard to open terminal. When it opens, run command to create a service file and edit via Gedit text editor:

sudo gedit /etc/systemd/system/hp-keycodes.service

When file opens, paste below lines and save it.

Description=HP setkeycodes fix

ExecStart=/usr/bin/setkeycodes e057 240 e058 240


As mentioned, this service will map e057 and e058 scancodes to no operation keycode 240.

2. Enable the service

2.) After that, reload and enable the service by running commands below one by one:

sudo systemctl daemon-reload
sudo systemctl enable hp-keycodes.service

And finally restart your computer and check the result!

Undo the changes:

If the method does not work for you, simply run the command in terminal (Ctrl+Alt+T) to disable the service:

sudo systemctl disable hp-keycodes.service

Next remove the file:

sudo rm /etc/systemd/system/hp-keycodes.service

Finally restart your machine to apply change.