# Change functionality of hardware buttons in Fairphone 1

**URL:** <https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066>\
**Category:** Fairphone 1\
**Tags:** buttons\
**Created:** [January 10, 2016, 5:12pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066 "2016-01-10T17:12:50Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jftr](https://forum.fairphone.com/user_avatar/forum.fairphone.com/jftr/32/39738_2.png) [@jftr](https://forum.fairphone.com/u/jftr)\
**Post date:** [January 10, 2016, 5:12pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/1 "2016-01-10T17:12:50Z")

</div>

**UPDATE:**  
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.

# Motivation

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.

 ![](https://forum.fairphone.com/uploads/default/original/2X/4/4dc70ace4678b8f9d0cfe1cc26a2b9ea7670b474.png)

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.

* * *

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

# Instructions

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).

## Preparations

### Install [adb](https://forum.fairphone.com/t/pencil2-fairphone-forum-dictionary/5309/2) on your computer

```auto
$ sudo apt-get install android-tools-adb

```

### Enable USB debugging on your Fairphone 1

1 . Go to [developer options](https://forum.fairphone.com/t/pencil2-fairphone-forum-dictionary/5309/29)  
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

```auto
$ 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.

```auto
$ 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](https://source.android.com/devices/input/key-layout-files.html).

```auto
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.

```auto
$ adb root
$ adb remount

```

### … and copy the file back to your Fairphone 1

```auto
$ adb push keylayout/ /system/usr/keylayout/

```

## Finally: Reboot your phone

```auto
$ adb reboot

```

* * *

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

---

<div class="post-metadata">

**Author:** ![paulakreuzer](https://forum.fairphone.com/user_avatar/forum.fairphone.com/paulakreuzer/32/35401_2.png) [@paulakreuzer](https://forum.fairphone.com/u/paulakreuzer)\
**Post date:** [January 10, 2016, 5:58pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/2 "2016-01-10T17:58:33Z")

</div>

Why not simply use [Gravity Box](https://forum.fairphone.com/t/pencil2-fairphone-forum-dictionary/5309/9?u=paulakreuzer)?

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

---

<div class="post-metadata">

**Author:** ![jftr](https://forum.fairphone.com/user_avatar/forum.fairphone.com/jftr/32/39738_2.png) [@jftr](https://forum.fairphone.com/u/jftr)\
**Post date:** [January 10, 2016, 6:09pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/3 "2016-01-10T18:09:21Z")

</div>

> [@paulakreuzer](#):
>
> Why not simply use Gravity Box

Because I’ve never installed the XPosed framework. I don’t want the [additional](https://plus.google.com/115581258997167602343/posts/b7E9FYSwyVB) [attack surface](http://blog.itsnotfound.com/2013/04/xposed-framework/).

---

<div class="post-metadata">

**Author:** ![paulakreuzer](https://forum.fairphone.com/user_avatar/forum.fairphone.com/paulakreuzer/32/35401_2.png) [@paulakreuzer](https://forum.fairphone.com/u/paulakreuzer)\
**Post date:** [January 10, 2016, 6:15pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/4 "2016-01-10T18:15:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stefan](https://forum.fairphone.com/user_avatar/forum.fairphone.com/stefan/32/4254_2.png) [@Stefan](https://forum.fairphone.com/u/Stefan)\
**Post date:** [January 11, 2016, 12:24am UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/5 "2016-01-11T00:24:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jftr](https://forum.fairphone.com/user_avatar/forum.fairphone.com/jftr/32/39738_2.png) [@jftr](https://forum.fairphone.com/u/jftr)\
**Post date:** [January 11, 2016, 10:07am UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/6 "2016-01-11T10:07:39Z")

</div>

> [@Stefan](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Stefan](https://forum.fairphone.com/user_avatar/forum.fairphone.com/stefan/32/4254_2.png) [@Stefan](https://forum.fairphone.com/u/Stefan)\
**Post date:** [January 11, 2016, 12:12pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/7 "2016-01-11T12:12:10Z")

</div>

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

 ![](https://forum.fairphone.com/uploads/default/original/2X/1/144c908a039c9ecefcbfa889c8f0f1561582bf34.png)

Not the usual app launcher though… ☹

---

<div class="post-metadata">

**Author:** ![jftr](https://forum.fairphone.com/user_avatar/forum.fairphone.com/jftr/32/39738_2.png) [@jftr](https://forum.fairphone.com/u/jftr)\
**Post date:** [January 11, 2016, 1:10pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/8 "2016-01-11T13:10:20Z")

</div>

> [@Stefan](#):
>
> after a reboot, the left button shows this:

Interesting 😄

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 😃

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?

---

<div class="post-metadata">

**Author:** ![Stefan](https://forum.fairphone.com/user_avatar/forum.fairphone.com/stefan/32/4254_2.png) [@Stefan](https://forum.fairphone.com/u/Stefan)\
**Post date:** [January 11, 2016, 1:19pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/9 "2016-01-11T13:19:17Z")

</div>

> [@jftr](#):
>
> I mean it looks like some kind of app switcher.

So when you press the button now, this appears?

 ![](https://forum.fairphone.com/uploads/default/original/2X/2/2d7436a8ab72a56b65e372a26b6b95ec1c8173e6.png)

> [@jftr](#):
>
> But your system looks so thoroughly different, that my guess is that it might be caused by anything 😃

Gravity-boxified 🕶

> [@jftr](#):
>
> Does it happen everywhere? Regardless of what app you are in when you press the button?

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

> [@jftr](#):
>
> Have you changed occurrences in all files or only in the Mediatek key layout?

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…

---

<div class="post-metadata">

**Author:** ![jftr](https://forum.fairphone.com/user_avatar/forum.fairphone.com/jftr/32/39738_2.png) [@jftr](https://forum.fairphone.com/u/jftr)\
**Post date:** [January 11, 2016, 1:23pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/10 "2016-01-11T13:23:46Z")

</div>

> [@Stefan](#):
>
> So when you press the button now, this appears?

Yes.

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.

---

<div class="post-metadata">

**Author:** ![jftr](https://forum.fairphone.com/user_avatar/forum.fairphone.com/jftr/32/39738_2.png) [@jftr](https://forum.fairphone.com/u/jftr)\
**Post date:** [January 11, 2016, 2:27pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/11 "2016-01-11T14:27:12Z")

</div>

What I’ve found out so far:

**First the good news 😉**

- `Generic.kl` is the file which needs to be modified (possibly [because it is “consulted” last](https://source.android.com/devices/input/key-layout-files.html#location) and changes in previously consulted files are overwritten?)
- `key 139` is the only entry that needs to be changed.

**Now the bad news 😉**

- Documentation says [one should not modify `Generic.kl`](https://source.android.com/devices/input/key-layout-files.html#generic-key-layout-file). 😱
- `/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.

**Conclusion**

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.

---

<div class="post-metadata">

**Author:** ![fai8753](https://forum.fairphone.com/letter_avatar/fai8753/32/6_449c533f586939b6e5f246632a46421f.png) [@fai8753](https://forum.fairphone.com/u/fai8753)\
**Post date:** [January 11, 2016, 3:12pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/12 "2016-01-11T15:12:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jftr](https://forum.fairphone.com/user_avatar/forum.fairphone.com/jftr/32/39738_2.png) [@jftr](https://forum.fairphone.com/u/jftr)\
**Post date:** [January 11, 2016, 3:19pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/13 "2016-01-11T15:19:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fai8753](https://forum.fairphone.com/letter_avatar/fai8753/32/6_449c533f586939b6e5f246632a46421f.png) [@fai8753](https://forum.fairphone.com/u/fai8753)\
**Post date:** [January 11, 2016, 3:31pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/14 "2016-01-11T15:31:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jftr](https://forum.fairphone.com/user_avatar/forum.fairphone.com/jftr/32/39738_2.png) [@jftr](https://forum.fairphone.com/u/jftr)\
**Post date:** [January 11, 2016, 4:31pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/15 "2016-01-11T16:31:27Z")

</div>

> [@fai8753](#):
>
> Changing the background or something like this?

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

---

<div class="post-metadata">

**Author:** ![Stefan](https://forum.fairphone.com/user_avatar/forum.fairphone.com/stefan/32/4254_2.png) [@Stefan](https://forum.fairphone.com/u/Stefan)\
**Post date:** [January 11, 2016, 5:13pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/16 "2016-01-11T17:13:40Z")

</div>

> [@jftr](#):
>
> 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.

> [@Stefan](#):
>
> New Pipe, which doesn’t have a menu button in its UI… 😛

In New Pipe you cannot reach the menu at all, without the left hardware button… 😛 (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](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/7) comes up, when I press the left button…

---

<div class="post-metadata">

**Author:** ![paulakreuzer](https://forum.fairphone.com/user_avatar/forum.fairphone.com/paulakreuzer/32/35401_2.png) [@paulakreuzer](https://forum.fairphone.com/u/paulakreuzer)\
**Post date:** [April 30, 2017, 3:15pm UTC](https://forum.fairphone.com/t/change-functionality-of-hardware-buttons-in-fairphone-1/12066/17 "2017-04-30T15:15:55Z")

</div>


