[How To] Make Script Run By Using Hardware Keys

peteralfonso

Premium Member
Premium Member
Developer
Joined
Mar 18, 2010
Messages
844
Reaction score
1
Ok, so it looks like my little trick was found so I guess it's time to explain myself. :icon_eek:

I came up with a way to use the hardware keys to make services (a.k.a. scripts) run. It was rumored that these options were already built into Froyo and/or used in Cyanogen Mod, neither being true. This is just one of those ideas I wake up with in my head. After playing with it a few minutes it worked flawlessly.

To add these options to your boot.img add the following lines to your preferred init script inside the ramdisk before compiling.


#shutdown options by pete
service poweroff /system/bin/shutdown
disabled
keycodes 107 211

service reboot /system/bin/shutdown -r
disabled
keycodes 107 114

service recovery /system/bin/shutdown -rr
disabled
keycodes 107 115


Obviously you can make these do different things other than shutdown. You can even choose different keys to make them run (hint dont use the half press camera button or people go crazy! lol)

As always please be respectful and atleast put idea by Pete or some sort of credit to make me feel happy if you use it.
 

B3y0ndD34th

Member
Joined
Mar 19, 2010
Messages
88
Reaction score
0
I want to edit mine to something like

#shutdown options by pete
service poweroff /system/bin/shutdown
disabled
keycodes 107 211 114

service reboot /system/bin/shutdown -r
disabled
keycodes 107 114

service recovery /system/bin/shutdown -rr
disabled
keycodes 107 115 211

because I don't know any of the other keys avail, but I guess if this works a lot of the problems will be resolved for me...
 

bad4u

Member
Joined
Nov 23, 2009
Messages
223
Reaction score
0
CREDIT to pete! Thats all im saying :) haha ........ too funny

I think imma change my reboot to like power plus x, had to delete it how it was though.
 

crpngdth2001

New Member
Joined
Jun 14, 2010
Messages
18
Reaction score
0
Location
Delaware, Ohio
Look in /system/usr/keylayout and you will see the files:

sholes-keypad.kl
qwerty.kl

I think the phone uses qwerty.kl as a default if no other is defined.

sholes-keypad.kl:

key 399 GRAVE
key 2 1 WAKE_DROPPED
key 3 2 WAKE_DROPPED
key 4 3 WAKE_DROPPED
key 5 4 WAKE_DROPPED
key 6 5 WAKE_DROPPED
key 7 6 WAKE_DROPPED
key 8 7 WAKE_DROPPED
key 9 8 WAKE_DROPPED
key 10 9 WAKE_DROPPED
key 11 0 WAKE_DROPPED
key 158 BACK WAKE_DROPPED
key 230 SOFT_RIGHT WAKE
key 60 SOFT_RIGHT WAKE
key 107 POWER WAKE_DROPPED
key 62 ENDCALL WAKE_DROPPED
key 229 MENU WAKE_DROPPED
key 59 MENU WAKE_DROPPED
key 139 MENU WAKE_DROPPED
key 217 SEARCH WAKE_DROPPED
key 228 POUND WAKE_DROPPED
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 211 FOCUS
key 212 CAMERA

key 16 Q WAKE_DROPPED
key 17 W WAKE_DROPPED
key 18 E WAKE_DROPPED
key 19 R WAKE_DROPPED
key 20 T WAKE_DROPPED
key 21 Y WAKE_DROPPED
key 22 U WAKE_DROPPED
key 23 I WAKE_DROPPED
key 24 O WAKE_DROPPED
key 25 P WAKE_DROPPED
key 26 LEFT_BRACKET WAKE_DROPPED
key 27 RIGHT_BRACKET WAKE_DROPPED
key 43 BACKSLASH WAKE_DROPPED

key 30 A WAKE_DROPPED
key 31 S WAKE_DROPPED
key 32 D WAKE_DROPPED
key 33 F WAKE_DROPPED
key 34 G WAKE_DROPPED
key 35 H WAKE_DROPPED
key 36 J WAKE_DROPPED
key 37 K WAKE_DROPPED
key 38 L WAKE_DROPPED
key 214 SEMICOLON WAKE_DROPPED
key 40 APOSTROPHE WAKE_DROPPED
key 14 DEL WAKE_DROPPED

key 44 Z WAKE_DROPPED
key 45 X WAKE_DROPPED
key 46 C WAKE_DROPPED
key 47 V WAKE_DROPPED
key 48 B WAKE_DROPPED
key 49 N WAKE_DROPPED
key 50 M WAKE_DROPPED
key 51 COMMA WAKE_DROPPED
key 52 PERIOD WAKE_DROPPED
key 53 SLASH WAKE_DROPPED
key 28 ENTER WAKE_DROPPED

key 56 ALT_LEFT WAKE
key 100 ALT_RIGHT WAKE
key 42 SHIFT_LEFT WAKE
key 54 SHIFT_RIGHT WAKE
key 15 TAB WAKE_DROPPED
key 57 SPACE WAKE_DROPPED
key 150 EXPLORER
key 155 ENVELOPE

key 12 MINUS WAKE_DROPPED
key 13 EQUALS WAKE_DROPPED
key 215 AT WAKE_DROPPED
 

B3y0ndD34th

Member
Joined
Mar 19, 2010
Messages
88
Reaction score
0
Look in /system/usr/keylayout and you will see the files:

sholes-keypad.kl
qwerty.kl

I think the phone uses qwerty.kl as a default if no other is defined.

sholes-keypad.kl:

key 399 GRAVE
key 2 1 WAKE_DROPPED
key 3 2 WAKE_DROPPED
key 4 3 WAKE_DROPPED
key 5 4 WAKE_DROPPED
key 6 5 WAKE_DROPPED
key 7 6 WAKE_DROPPED
key 8 7 WAKE_DROPPED
key 9 8 WAKE_DROPPED
key 10 9 WAKE_DROPPED
key 11 0 WAKE_DROPPED
key 158 BACK WAKE_DROPPED
key 230 SOFT_RIGHT WAKE
key 60 SOFT_RIGHT WAKE
key 107 POWER WAKE_DROPPED
key 62 ENDCALL WAKE_DROPPED
key 229 MENU WAKE_DROPPED
key 59 MENU WAKE_DROPPED
key 139 MENU WAKE_DROPPED
key 217 SEARCH WAKE_DROPPED
key 228 POUND WAKE_DROPPED
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 211 FOCUS
key 212 CAMERA

key 16 Q WAKE_DROPPED
key 17 W WAKE_DROPPED
key 18 E WAKE_DROPPED
key 19 R WAKE_DROPPED
key 20 T WAKE_DROPPED
key 21 Y WAKE_DROPPED
key 22 U WAKE_DROPPED
key 23 I WAKE_DROPPED
key 24 O WAKE_DROPPED
key 25 P WAKE_DROPPED
key 26 LEFT_BRACKET WAKE_DROPPED
key 27 RIGHT_BRACKET WAKE_DROPPED
key 43 BACKSLASH WAKE_DROPPED

key 30 A WAKE_DROPPED
key 31 S WAKE_DROPPED
key 32 D WAKE_DROPPED
key 33 F WAKE_DROPPED
key 34 G WAKE_DROPPED
key 35 H WAKE_DROPPED
key 36 J WAKE_DROPPED
key 37 K WAKE_DROPPED
key 38 L WAKE_DROPPED
key 214 SEMICOLON WAKE_DROPPED
key 40 APOSTROPHE WAKE_DROPPED
key 14 DEL WAKE_DROPPED

key 44 Z WAKE_DROPPED
key 45 X WAKE_DROPPED
key 46 C WAKE_DROPPED
key 47 V WAKE_DROPPED
key 48 B WAKE_DROPPED
key 49 N WAKE_DROPPED
key 50 M WAKE_DROPPED
key 51 COMMA WAKE_DROPPED
key 52 PERIOD WAKE_DROPPED
key 53 SLASH WAKE_DROPPED
key 28 ENTER WAKE_DROPPED

key 56 ALT_LEFT WAKE
key 100 ALT_RIGHT WAKE
key 42 SHIFT_LEFT WAKE
key 54 SHIFT_RIGHT WAKE
key 15 TAB WAKE_DROPPED
key 57 SPACE WAKE_DROPPED
key 150 EXPLORER
key 155 ENVELOPE

key 12 MINUS WAKE_DROPPED
key 13 EQUALS WAKE_DROPPED
key 215 AT WAKE_DROPPED

Freakin awesome thanks... now if only I could get /init.sholes.rc to go r/w and can get it to chmod to edit :/
 

bad4u

Member
Joined
Nov 23, 2009
Messages
223
Reaction score
0
Since i deleted that shutdown script, can someone post it or tell me how to pull it from the update.zip.

much thanks

NM found the file. trying to break my phone right now. :p
 

ashkev843

Member
Joined
Nov 22, 2009
Messages
321
Reaction score
0
Can someone write one. To use the volume up and down to skip tracks on the music player when long pressed. :heart:
 

bad4u

Member
Joined
Nov 23, 2009
Messages
223
Reaction score
0
can we edit the shutdown script in root explorer?

I opened it in text editor and now im officially lost. Any one feel like helping?


Actually it might be a good idea for some one to post a howto and claim no responsibility before this becomes a "can i have, can you make me a..." thread.
 

B3y0ndD34th

Member
Joined
Mar 19, 2010
Messages
88
Reaction score
0
I don't mind sharing what I find as of right now I'm trying to figure out how to edit the fella.

sysrw doesn't help, chmod doesn't help, godmode doesn't help for now I don't know how to edit the file... I don't mind sharing what I come up with but I am by no means looking for a project but I will help as much as I can to steer you in the right directions, but I'm not writing anything for anyone other than myself atm.
 

Se7enLC

Active Member
Joined
Nov 16, 2009
Messages
1,262
Reaction score
0
Ok, so it looks like my little trick was found so I guess it's time to explain myself. :icon_eek:

I came up with a way to use the hardware keys to make services (a.k.a. scripts) run. It was rumored that these options were already built into Froyo and/or used in Cyanogen Mod, neither being true. This is just one of those ideas I wake up with in my head. After playing with it a few minutes it worked flawlessly.

To add these options to your boot.img add the following lines to your preferred init script inside the ramdisk before compiling.

Aha, inside the ramdisk! It all makes sense now...

So unfortunately, to make a change to this means recompiling a kernel, which means that most people won't do it :p

Guess it's about time I learn how to compile an android kernel (can't be that different from std linux, right?)
 

bad4u

Member
Joined
Nov 23, 2009
Messages
223
Reaction score
0
Are you opening with text editor in root explorer? I did and was lost at that point. If i was to know which part I am supposed to edit I would do it, but I saw nothing with the key codes for camera or volume. I also checked in the reboot script. That doesnt open right in text editor.
 

B3y0ndD34th

Member
Joined
Mar 19, 2010
Messages
88
Reaction score
0
This is the part you edit

#shutdown options by pete
service poweroff /system/bin/shutdown
disabled
keycodes 107 211

service reboot /system/bin/shutdown -r
disabled
keycodes 107 114

service recovery /system/bin/shutdown -rr
disabled
keycodes 107 115

it's in /init.sholes.rc

As stated above apparently we have to compile a kernel to fix this... All your need to do is specify different keys for the keycodes and viola, It's near the bottom. I use Astro to view the file as a text document and open it in a text editor the code is near the bottom even has the commented part about Pete's shutdown script, kinda hard to miss tbh.
 

crpngdth2001

New Member
Joined
Jun 14, 2010
Messages
18
Reaction score
0
Location
Delaware, Ohio
This is the part you edit

#shutdown options by pete
service poweroff /system/bin/shutdown
disabled
keycodes 107 211

service reboot /system/bin/shutdown -r
disabled
keycodes 107 114

service recovery /system/bin/shutdown -rr
disabled
keycodes 107 115

it's in /init.sholes.rc

As stated above apparently we have to compile a kernel to fix this... All your need to do is specify different keys for the keycodes and viola, It's near the bottom. I use Astro to view the file as a text document and open it in a text editor the code is near the bottom even has the commented part about Pete's shutdown script, kinda hard to miss tbh.

I don't believe any of the messages above meant to imply you needed to recompile the kernel to change the keystroke combination in init.sholes.rc. If you want to add other services (aka scripts) and then assign keycodes to them, you would have to recompile.

I believe you can simply change the keycodes in init.sholes.rc to change the combination (or comment them out to disable them). Pete has included poweroff, reboot, and recovery services in his compiled rom - if you wanted to add something like a media player script or overclock script that could be controlled by up/down volume and another key then you would need to write that script and include it in the compiled kernel, then define as above in init.sholes.rc.

This is my understanding, take it for what it's worth (esp. if it's wrong), LOL!

Edit: FYI - I can edit my init.sholes.rc just fine with root explorer, hit the r/w button, open in text edit, save, hit r/o, exit.
 
Top