Change functionality of hardware buttons in Fairphone 1

I’ve just realized that instructions for different versions of Android might differ slightly. My Fairphone runs the unofficial KitKat ROM. I’ve tried to make the instructions as generic as possible to avoid problems. If you encounter any differences, please let me know.


It has always been irritating to me that the left hardware button on Fairphone 1 shows the symbol for the app switcher but it is linked to the Menu action.

Additionally, I much more often use the app switcher than the menu.

I know that the app switcher is accessible by long pressing on the Home button. However, having it available with a single short touch is much nicer.

So I set out to change the left button to display the app switcher instead of the menu.

:warning: I don’t take any responsibility if this breaks your phone. :warning:
It works for me but I can’t guarantee anything.


These instructions are based on Ubuntu 15.10. The overall idea probably works on other systems too. However you probably need to use some other tools (e.g. sed is not available on Windows).


Install adb on your computer

$ sudo apt-get install android-tools-adb

Enable USB debugging on your Fairphone 1

1 . Go to developer options
2. Tick the optione Enable USB debugging

Get keylayout file from phone

  1. Connect your Fairphone 1 to your computer using a USB cable
  2. Copy the following file from your Fairphone 1 to your computer
$ mkdir keylayout
$ adb pull /system/usr/keylayout/Generic.kl keylayout/

Backup copied file

Make a backup to be able to go back to the original files if something goes wrong.

$ cp -r keylayout/ keylayout.bak/

Change keylayout

The only change I want to make is to replace the Menu function with the App Switcher function. You can try to change other stuff but you need to find out how on your own.

sed -iE 's/^(key 139\s+)MENU/\1APP_SWITCH/' keylayout/Generic.kl

This replaces all occurrences of key 139 MENU with key 139 APP_SWITCH in the keylayout file.

Copy the file back to the phone

Mount the system partition as writeable

For that you need root privileges.

$ adb root
$ adb remount

… and copy the file back to your Fairphone 1

$ adb push keylayout/ /system/usr/keylayout/

Finally: Reboot your phone

$ adb reboot

This should be it. Now your Fairphone 1 is vastly improved :smiley:


Why not simply use Gravity Box?

I used it to make:

  • Button 1 tap: menu
  • long tap: Settings
  • double tap: Gravity Box
  • Button 2 tap: Home
  • long tap: recent apps
  • Button 3 tap: back
  • long tap: switch to previous App
  • double tap: Power Menu

Because I’ve never installed the XPosed framework. I don’t want the additional attack surface.

1 Like

As long as you only install well-known and tested-by-millions (exaggeration) modules (and I think Gravity Box is among the top 3) there is no additional risk for attacks.


I tried to change “short tap” of the menu button, but you cannot customize this in Gravity Box. So @jftr provides the only way so far. Thanks!

Edit: Looking at the files in the directory /system/usr/keylayout, I’d assume the only file, which has to be changed is mtk-kpd.kl. (I guess that “mtk” stands for Mediatek.) @jftr, Maybe you can verify, if you find the time. I can’t try it now.


Yes, that was also my thought. However, this file has three occurrences of MENU and if I do it properly, I will only need to change one of them. However finding that out takes even more time (because each time I need to reboot). I might look into it later today.

1 Like

I changed all occurences with Amaze File Explorer, and after a reboot, the left button shows this:

Not the usual app launcher though… :frowning:

Interesting :smile:

Unfortunately I don’t have a clue what’s happening here. I mean it looks like some kind of app switcher. But your system looks so thoroughly different, that my guess is that it might be caused by anything :smiley:

Does it happen everywhere? Regardless of what app you are in when you press the button?

Have you changed occurrences in all files or only in the Mediatek key layout?

1 Like

So when you press the button now, this appears?

Gravity-boxified :sunglasses:

Yes. I found out when I was in New Pipe, which doesn’t have a menu button in its UI… :stuck_out_tongue:

In all of them, so I also can’t say, which it was. I didn’t even think, that it would work, when I do it with Amaze, given that I did not mount the system partition as writeable…


I’m also looking into which files exactly we need to change. So far I can only say that it is not the mtk-*.kl file.

I’ll report back later.

1 Like

What I’ve found out so far:

First the good news :wink:

  • Generic.kl is the file which needs to be modified (possibly because it is “consulted” last and changes in previously consulted files are overwritten?)
  • key 139 is the only entry that needs to be changed.

Now the bad news :wink:

  • Documentation says one should not modify Generic.kl. :scream:
  • /data/system/devices/keylayout/Generic.kl does not exist on my FP1. Although it is listed after /system/usr/keylayout/Generic.kl, it doesn’t override it if I create it.

Now some random other news:

Not a lot of stuff works on Android. getevent is available though.

  • device 1: /dev/input/event0 (name: "mtk-kpd") are the hardware buttons (power and volume).
  • add device 3: /dev/input/event3 (name: "mtk-tpd") registers any touch input (both screen and soft keys below screen)
  • add device 4: /dev/input/event2 (name: "hwmdata") almost certainly is the light/proximity sensor
  • I can’t trigger any events on /dev/input/event4 (name: "mtk-tpd-kpd") and /dev/input/event1 (name: "ACCDET")

Touch inputs on /dev/input/event3 (touchpad) only convey location information (X and Y). Some driver probably translates that to keypress events. Unfortunately that seems to be opaque to us.


The only option I see for the moment is sticking to the initial idea: Changing /system/usr/keylayout/Generic.kl.

I’ll update the howto with my above findings.

1 Like

Great! I was wishing to do this on my mother’s FP for some time now without installing additional stuff (like you can on CM), because it’s hard to explain the availability of a menu without any indication on the screen. “There might be more stuff you can do with this app by pressing the left button” is not an explanation I’d like to give and not something she’d think of when I’m not around. So thank you very much for this tutorial!

One question: Does it automatically show the “…” (software) button when I don’t have a MENU key anymore?

AFAIK the software button is already present in most (all?) apps. The three dots are the menu in Android. However, I’m possibly unaware of cases where the overflow menu does not equal the menu you can reach with the menu button.

1 Like

I haven’t used a phone with a MENU key very often but I thought it was either the “…” menu or the MENU key. That’s good news and it worked as you said when I just tried it by assigning a MENU key on CM: “…” menu is still there.
So is there any functionality lost by not assigning a MENU key on FPOS? Changing the background or something like this? I did that by hitting the MENU key if I recall correctly.

I use Google Now Launcher. There I can long press the background to get to settings. Does that also work with the Fairphone Launcher?

In New Pipe you cannot reach the menu at all, without the left hardware button… :stuck_out_tongue: (I assigned “Menu” to long pressing the right hardware button now, using Gravity Box.)

However I still don’t understand, why this other App Switcher comes up, when I press the left button…