[How To] Make Script Run By Using Hardware Keys

Search This thread

BuglessPete

Senior Member
Feb 1, 2010
412
868
Ok, so it didn't take long before my little trick was found in my Droid ROM so I guess it's time to explain myself and share it here for the Evo.

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
oneshot
disabled
keycodes 107 211

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

service recovery /system/bin/shutdown -rr
oneshot
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: those keycodes are for droid).

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. :D
 
Last edited:

neckface

Senior Member
Feb 8, 2010
637
10
Ok, so it didn't take long before my little trick was found in my Droid ROM so I guess it's time to explain myself and share it here for the Evo.

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: those keycodes are for droid).

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. :D

Genius. Expect a donation from me.
 

vboyz103

Senior Member
Apr 9, 2006
878
141
Thanks Pete for the tutorial, so I see two keys assigned to a script, so is it a combo press or just a single press?
 
D

dehelflix

Guest
glad i donated to this guy, hes a smart cookie. hopefully, you're close to having enough for an evo!
 

Decad3nce

Retired Forum Mod / Inactive Recognized Developer
Feb 19, 2010
2,086
2,762
Applied your 'how to' to an idea of launching any application(or intent) by hardkey press(Custom App Launching). Let me know what you think.
 

alnov

New member
Mar 11, 2016
4
0
Ok, so it didn't take long before my little trick was found in my Droid ROM so I guess it's time to explain myself and share it here for the Evo.

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
oneshot
disabled
keycodes 107 211

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

service recovery /system/bin/shutdown -rr
oneshot
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: those keycodes are for droid).

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. :D

hi bro, i follow u doing this, i modified init.rc and add some line like this

Code:
service calculator /system/bin/calc
    oneshot
    disabled
    keycodes 139

keycodes 139 is a code of a menu hardware button, and also i add a .txt file to /system/bin , that is

Code:
#! /system/bin/sh
am start -a android.intent.action.MAIN -n co.fira.dialogapplication/.DialogActivity

but nothing happens when i touch the menu button, any idea?
 

davek17

Member
Jun 19, 2007
42
2
www.raptorhub.com
Hi there, so i'm trying to do this exact thing, mapping the camera button to run an app. However when I press the button nothing happens!! I have tried with all my button codes, 114, 115, 212 etc and used the exact code above at the end of my init.rc file. I use Android Image kitchen toi crack open the boot.img and re-pack it. flashing works fine and I know these buttons work because if I change the .kl files I have test mapped them to pre-defined functions like CAMERA or FOCUS.

So the device runs 4.4.2 so it should support the services and keycodes commands in the init.rc.

I can see the init.rc file in the root folder on the device has the new code in it. It simply just doesn't work and i'm tearing my hair out now!

Does simply adding the service with the keycodes above actually run or install the service ready for the button press? Or do I have to actually run the service somewhere later in the init.rc file?

Any help would be greatly appreciated.

Dave