[Android Software/Hacking General [Developers Only]] tweakradje:
Challenge: don't wake up you phone when I press any of the buttons!!! Only ENDCALL button (example is from Samsung i5500 with Froyo)

Finding the keycode for a button

Click all the hardware buttons (write down the sequence you pushed ;)

Find keycode with dmesg (rooted phone)

# dmesg|grep keycode:

dmesg|grep keycode:

<4>[ 6379.122037] key event (keycode:107, pressed:1), wlan_debug_step=0

<4>[ 6379.304589] key event (keycode:107, pressed:0), wlan_debug_step=0

<4>[ 6400.249157] key event (keycode:139, pressed:1), wlan_debug_step=0

<4>[ 6400.451860] key event (keycode:139, pressed:0), wlan_debug_step=0

<4>[ 6404.388724] key event (keycode:102, pressed:1), wlan_debug_step=0

<4>[ 6404.571092] key event (keycode:102, pressed:0), wlan_debug_step=0

<4>[ 6407.086125] key event (keycode:158, pressed:1), wlan_debug_step=0

<4>[ 6407.268522] key event (keycode:158, pressed:0), wlan_debug_step=0

<4>[ 6410.270504] key event (keycode:217, pressed:1), wlan_debug_step=0

<4>[ 6410.432657] key event (keycode:217, pressed:0), wlan_debug_step=0

<4>[ 6422.337047] key event (keycode:103, pressed:1), wlan_debug_step=0

<4>[ 6422.580344] key event (keycode:103, pressed:0), wlan_debug_step=0

<4>[ 6425.833795] key event (keycode:105, pressed:1), wlan_debug_step=0

<4>[ 6426.036509] key event (keycode:105, pressed:0), wlan_debug_step=0

<4>[ 6429.794280] key event (keycode:108, pressed:1), wlan_debug_step=0

<4>[ 6429.997194] key event (keycode:108, pressed:0), wlan_debug_step=0

<4>[ 6433.061290] key event (keycode:106, pressed:1), wlan_debug_step=0

<4>[ 6433.304629] key event (keycode:106, pressed:0), wlan_debug_step=0

<4>[ 6437.635529] key event (keycode:231, pressed:1), wlan_debug_step=0

<4>[ 6437.797985] key event (keycode:231, pressed:0), wlan_debug_step=0

<4>[ 6442.918039] key event (keycode:107, pressed:1), wlan_debug_step=0

<4>[ 6443.141397] key event (keycode:107, pressed:0), wlan_debug_step=0

So for Samsung i5500 the scan / keycode table looks like:

139	MENU

102	HOME

158	BACK

217	SEARCH

103	DPAD_UP

105	DPAD_UP

108	DPAD_DOWN

106	DPAD_RIGHT

232	DPAD_CENTER

231	CALL

107	ENDCALL

114	VOLUME_DOWN

115	VOLUME_UP

Which button definition file is in use

In a adb shell type: getprop hw.keyboards.0.devname

In my case it is europa_keypad0

cd /system/usr/keylayout

ls -l

-rw-r--r-- root root 349 2011-04-01 13:01 AVRCP.kl

-rw-r--r-- root root 1712 2011-04-01 13:01 europa_keypad0.kl

-rw-r--r-- root root 1697 2011-04-01 13:01 europa_headset.kl

-rw-r--r-- root root 1699 2011-04-01 13:01 qwerty.kl

This file looks like:

key 158 BACK WAKE_DROPPED	<<<REMOVE

key 230 SOFT_RIGHT WAKE

key 60 SOFT_RIGHT WAKE

key 107 ENDCALL WAKE_DROPPED	<<<REMOVE

WAKE:	When this key is pressed while the device is asleep, the device will wake up and the key event gets sent to the app.

WAKE_DROPPED: When this key is pressed while the device is asleep, the device will wake up and the key event does not get sent to the app.

So:

- system needs to be r/w mounted

- adb pull /system/usr/keylayout/europa_keypad0.kl

- adb shell chmod 666 /system/usr/keylayout/europa_keypad0.kl

- edit you file, remove any WAKE or WAKE_DROPPED from the keys

that you don't want the phone to wake up

(or do the opposite if you like your phone to wake on a specific button)

- adb push europa_keypad0.kl /system/usr/keylayout

- reboot

Cheers

ORG:

key 399 GRAVE
key 2 1
key 3 2
key 4 3
key 5 4
key 6 5
key 7 6
key 8 7
key 9 8
key 10 9
key 11 0
key 158 BACK WAKE_DROPPED
key 230 SOFT_RIGHT WAKE
key 60 SOFT_RIGHT WAKE
key 107 ENDCALL WAKE_DROPPED
key 62 ENDCALL WAKE_DROPPED
key 229 MENU WAKE_DROPPED
key 139 MENU WAKE_DROPPED
key 59 MENU WAKE_DROPPED
key 127 SEARCH WAKE_DROPPED
key 217 SEARCH WAKE_DROPPED
key 228 POUND
key 227 STAR
key 231 CALL WAKE_DROPPED
key 61 CALL WAKE_DROPPED
key 232 DPAD_CENTER WAKE_DROPPED
key 108 DPAD_DOWN WAKE_DROPPED
key 103 DPAD_UP WAKE_DROPPED
key 102 HOME WAKE
key 105 DPAD_LEFT WAKE_DROPPED
key 106 DPAD_RIGHT WAKE_DROPPED
key 115 VOLUME_UP WAKE
key 114 VOLUME_DOWN WAKE
key 116 POWER WAKE
key 212 CAMERA

MOD:

key 399 GRAVE
key 2 1
key 3 2
key 4 3
key 5 4
key 6 5
key 7 6
key 8 7
key 9 8
key 10 9
key 11 0
key 158 BACK
key 230 SOFT_RIGHT
key 60 SOFT_RIGHT
key 107 ENDCALL WAKE_DROPPED
key 62 ENDCALL WAKE_DROPPED
key 229 MENU
key 139 MENU
key 59 MENU
key 127 SEARCH
key 217 SEARCH
key 228 POUND
key 227 STAR
key 231 CALL
key 61 CALL
key 232 DPAD_CENTER
key 108 DPAD_DOWN
key 103 DPAD_UP
key 102 HOME
key 105 DPAD_LEFT
key 106 DPAD_RIGHT
key 115 VOLUME_UP
key 114 VOLUME_DOWN
key 116 POWER
key 212 CAMERA