I have an HP Spectre x360 convertible laptop and I'm running Ubuntu 18.04. Every time I turn the screen sideways or in tablet mode and back, 'Airplane Mode' is activated. In fact, when I boot up and login, I have to manually turn off 'Airplane Mode' and turn wifi back on. I don't want to disable the gnome rfkill plugin like so: 'gsettings set org.gnome.settings-daemon.plugins.rfkill active false' because then I can no longer use bluetooth. Also, for some godforsaken reason, even when I DO disable the plugin, the gnome shell turns on 'Airplane Mode' anyway, which means that I have to go turn wifi back on EVERY time I log in. This is so annoying, I really liked where 18.04 was going but this is seriously breaking the whole gnome shell experience.

  • 1
    Did the problem appear with 17.10? I have the same laptop, and I had the same problem with Ubuntu 17.04. What makes it worse in 17.10 is that the "airplane mode/F12" key does not work anymore, so I have to go to the top-right menu to enable it again. Do you have the same problem? Commented Oct 25, 2017 at 16:32
  • As far as I can tell, setting the keycodes correctly on startup also fixes the problem with the airplane mode f12 key not working. I am currently toggling the airplane mode key with joy because it finally works. It only became apparent to me after I first started actually using the gnome shell in 17.10, as I never used the Gnome spin. Commented Jun 23, 2018 at 1:56

4 Answers 4


In GNOME Shell, "Airplane Mode" is automatically activated on boot for many HP laptops, when the screen is tilted sideways, or when the lid is opened/closed. The following is a fix for HP laptops running Linux and using GNOME Shell. Keycode 240 is defined as KEY_UNKNOWN (a kind of no-op key) in /usr/include/linux/input-event-codes.h. Also your syslog will no longer prompt you to define the HP e057 and e058 codes, which can be remarkably annoying.

First is a fix using a classic SysV init script, placed in the init.d directory and symlinked accordingly (basically, we want it to run regardless of runlevel on anything except halt (0) or reboot (6)).

Second is a systemd service that is far more reliable and perhaps present with recent systemd changes, which also happens to work on Fedora 28 and other distribution platforms. On Fedora in particular, you will find an almost complete absence of scripts in the /etc/init.d directory, along with a little README detailing the transition from SysV to systemd.

The first method will work, but the second method is much more "future friendly", especially considering where Ubuntu is heading, and will also work in a slightly less... annoying way. systemd init scripts are actually quite handy, and fully implemented and used frequently in Ubuntu 18.04.

Old SysV method (type in a terminal):

sudo sh -c 'printf "#!/bin/sh\n/usr/bin/setkeycodes e057 240 e058 240\n" > /etc/init.d/hp-keycodes'
sudo chmod +x /etc/init.d/hp-keycodes
sudo ln -s /etc/init.d/hp-keycodes /etc/rc1.d/K01hp-keycodes
sudo ln -s /etc/init.d/hp-keycodes /etc/rc2.d/S01hp-keycodes
sudo ln -s /etc/init.d/hp-keycodes /etc/rc3.d/S01hp-keycodes
sudo ln -s /etc/init.d/hp-keycodes /etc/rc4.d/S01hp-keycodes
sudo ln -s /etc/init.d/hp-keycodes /etc/rc5.d/S01hp-keycodes
sudo reboot

New Recommended systemd Method (type in a terminal):

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

Paste the following lines or type them into the file:

Description=HP setkeycodes fix

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


Save and confirm the filename with Ctrl+x, y. Then, type in a terminal:

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

And that's it, no more annoying weird stuff when you tilt your screen or close/open the laptop lid!

  • 1
    this didn't work on ubuntu 17.10
    – nikhilweee
    Commented Feb 12, 2018 at 16:29
  • 3
    THANK YOU. This worked on my Spectre x360 when many other solutions did not.
    – Matt West
    Commented Sep 24, 2018 at 4:21
  • 1
    Worked for login and screen rotation airplane mode on my 2015 13" HP Spectre x360.
    – wakers01
    Commented Jan 31, 2019 at 1:18
  • 1
    Works perfectly for my HP Spectre 13-4110nd x360
    – Hugo
    Commented Feb 2, 2019 at 9:44
  • 2
    For some reason the second method stopped working for me after the upgrade to 22.04
    – 0x539
    Commented Aug 2, 2022 at 17:39

I face the very same problem with 17.10 on my HP Spectre x360. In fact, I face both Nicholas and Pierre-Antoine problems:

  • Airplane mode activated every time I login or flip to tablet mode;
  • Fn+F12 (Toggle Airplane Mode key) is no longer working.

To quickly toggle the wifi, I made a small script:

## Content of ~/scripts/wifi_toggle : ##
    str=`export LANGUAGE=en_GB ; nmcli r wifi`
    [ "$str" == "enabled" ] && nmcli r wifi off
    [ "$str" == "disabled" ] && nmcli r wifi on

I rarely use bluetooth, so it only handles wifi, but you can modify it easily to handle both bluetooth and wifi.

All this is a clear regression from 17.04 where everything worked flawlessly. I tried the 18.04 beta but it's the same situation than with 17.10.

Nicholas, Pierre-Antoine, I fill like filling two bug reports on these issues (on report per issue). Do you think you could had a comment in these reports whenever I'm done reporting? This would help confirming the bug status (more than one user affected).


  • To mark a bug report as affecting someone, they should click on the Does this bug affect you? link just below the bug title. Commented Mar 17, 2018 at 15:23
  • If you filed a bug please can you post a link here so that others who have this problem (including myself) can subscribe to it?
    – ec2011
    Commented Apr 17, 2018 at 12:43
  • Unfortunately, as far as I am aware, this is really an HP convertible notebook hardware thing that may not be present at all on most machines, so adding a special clause or init script in the official package repo may not be much of a solution at all. This appears to be a kernel and gnome-shell problem sorta mushed into one. I could attempt to file a bug report against the gnome-shell but they just switched over to that gitlab nightmare a short while back. The airplane mode key is fixed with the revised answer (systemd init script). Commented Jun 23, 2018 at 2:15
  • Antoine I did tried but didn't worked for me can you help me on this askubuntu.com/q/1146524 Commented May 28, 2019 at 13:41
  • Worked like a charm on HP Omen 15
    – Sudhanshu
    Commented Oct 21, 2020 at 15:21

Thank you so very much!

I can confirm that @Nicholas's fix also works on my Huawei Matebook D15 (non-convertible), which seemed to loose all connectivity after suspend.

After checking the file


I could ascertain that in my system the key 240 was also marked as KEY_UNKNOWN, so I decided to give his "Systemd" solution a shot... and it worked! Obviously, I changed the name of the new file to reflect my system ("huawei-keycodes.service"), and also changed the description of the service within the file, but everything else was just a copy/paste job. Thanks again and I hope my experience helps other people with similar issues who aren't necessarily on HP machines.

Edit: Just realised it only works when I actively suspend the computer, it doesn't work when the computer gets automatically suspended when closing the lid... I'll need to do some more research still...


As a follow on to Nicholas Stommel's answer, udev is able to set keycodes as well from the hwdb for the appropriate hardware. In fact, systemd's udev hwdb is the culprit of this brokenness in the first place. I have the following snippet in /etc/udev/hwdb.d/70-keyboard.hwdb:

# systemd's udev hwdb breaks our keyboard tablet mode switcheroo thing.  Fix it.

 KEYBOARD_KEY_ab=unknown    # emitted by brightness keys
 KEYBOARD_KEY_d7=f22        # normal mode - turn touchpad on
 KEYBOARD_KEY_d8=f23        # tablet mode - turn touchpad off

Setting these keys to F22 and F23 will make GNOME show a touchpad on/off icon when switching from/to tablet mode. The ab definition is to silence a kernel warning whenever either brightness down/up key is pressed.

I don't know whether the selector here is too restrictive, but it works on my 2015 model laptop. The relevant product name in the selector can be found by running sudo dmidecode.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .