[Nexus S General] olorin86:
I know a lot of people out there are doing this already, but it didn't seem like there was a guide or anything out there for the NS. So, here we go.

(Please, make sure you know what you're doing BEFORE you apply this modification. I can't be responsible if you somehow manage to brick, or make brick-like your phone while following this guide.)

-You can do this using either adb, Terminal, or apps like Root Explorer. Since I'm trying to make this as easy as possible, I'll explain how to do this using the "File Manager" app, which can be installed via Market for FREE.

First, you need a rooted phone. If your phone is not rooted, there is extensive existing literature on how to get this done. (It's awfully easy on our Nexus S ;) )

Run File Manager, hit Menu > More > Settings, scroll way~~ down, and make sure that "Root Explorer" and "Mount System Folders" are checked.

Navigate your way to

/system/usr/keylayout

(you'll have to move Up a step or two to find 'system' folder at root level.)

[BACKUP THE ORIGNIAL FILE WE'RE ABOUT TO MODIFY]

Long-press the file 'cypress-touchkey.kl'

Select 'Copy'

Hit 'Paste', on the upper left corner of app.

You'll be asked to rename the file. Rename it to something reasonable. (like, cypress-touchkey.kl.bakup)

Hit 'Ok'

Make sure the file you just created exists.

[START MODIFICATION]

Long-press 'cypress-touchkey.kl' (again)

Hit 'Permissions'

Make sure that ALL THREE boxed under "Write" are checked, and hit OK.

Hit 'cypress-touchkey.kl' (yet, again)

Select Text > Text Editor

Here, you'll see something like,

key 139 MENU VIRTUAL
key 102 HOME VIRTUAL
key 158 BACK VIRTUAL
key 217 SEARCH VIRTUAL

as you've guessed, the first part,

key ###

is telling which key this command (event) is for.

So we can intuitively tell that the number for our capacitive 'Back' button is probably 158.

the next section, 'MENU, HOME, BACK, SEARCH' tells Android what these buttons should actually do.

And a pretty good list of what an Android CAN do on a key-press is listed here: http://goo.gl/vrCvJ

From the list, lookup anything that starts with KEYCODE_ and you'll find a pretty good description of what that command ('event') makes Android do.

Just add this keycode, WITHOUT the KEYCODE_ part of the code, to where the current cypress-touchkey.kl reads 'MENU, HOME, BACK, SEARCH' (according to what you want which button to do, that is)

So, for example, I've remapped my 'Search' button to bring up the App Switcher (Recent Apps). (Long-pressing the Home button just didn't cut it for me :p)

So, my 'cypress-touchkey.kl' looks like this:

key 139 MENU VIRTUAL
key 102 HOME VIRTUAL
key 158 BACK VIRTUAL
key 217 APP_SWITCH VIRTUAL

Now, save your modified 'cypress-touchkey.kl' by selecting,

Menu > Save, and the exit by selecting Menu > Exit.

To be safe, let's set the permissions back to what they were.

From the File Manager App, long-press 'cypress-touchkey.kl' > Permissions,

and un-check the lower two check-boxes under the 'Write' column, and hit "OK"

Now, reboot your phone, and see if all went well ;)

I actually tried this mod on a ICS rom, expecting the ICS app switcher to pop up, but somehow, the APP_SWITCH event seems to bring out the GB Recent App thingy.

Functionally, it still works pretty well for me. But if there's anyone out there who has any information on how to bring out the all-new ICS App switcher with a key-event, I'd really appreciate it ;)

Hope this makes someone's life easier! :D