I figured this was probably something that people might find useful as when searching for a possible solution myself I came across a massive Google groups post with no good on how to remap the power button on an Android device! Basically, the other day my Nexus S Power button randomly gave up on me leaving no way to turn my device on or off. Of course, this is an issue because I also couldn't lock my screen meaning accidental button presses and massive power drainage. So! After looking around, and then thinking for a bit I have a solution by remapping your volume key to your power button which I figure is a decent trade off seeing as sound can still be controlled via the Settings menus. As you would expect however, there are a few limitations but I'll come back to those later. In order to remap the Android power button a rooted phone is needed.

First of all, ensure your device is both rooted and you have a suitable file manager installed which can edit your system files. The tool I used for this is named Root Explorer (but any tool which can use root writes is fine). Next, you need to open your file explorer and browse into the following directory:


This is where it differs slightly for each device. You need to locate the .kl file which is controlling the function of your buttons. On a Nexus S, it's the herring-keypad.kl file. You can also change the touch key functions if you desire. The correct file will look something like the following depending on your available buttons:


When you've located that file, open it in a text editor (this can probably be done easily through your file explorer) and change the button's current function to the function you wish it to have. The following image is what I decided to go with; changing the Volume Up key to act as a Power button. As you can see, you simply change the value of the button to POWER:


To make this active, your device needs to be restarted. This can be done either by removing the battery and reinserting (using your charging cable to start up) or via adb reboot. Once it's restarted your chosen button should function as your power button!

Due to the fact that the .kl file isn't read until the device is booted up, you can't use your new "Power" button to start your device, only to lock/unlock and power off. To start up your device you'll need to connect your charging cable and it'll start up. If the battery is completely dead it may be necessary to charge the battery for a few minutes then remove and replace the cable to get it started up. On certain devices there may also be the issue of not being able to use the volume keys to scroll up and down in the bootloader menu properly either - but of course you can't confirm any of the options anyway so this doesn't really matter.

Anyway, hopefully that'll help those of you bridge the gap until you can afford/want to buy a new device!