FORUMS
Remove All Ads from XDA
Honor 7x
Win an Honor 7X!

[How To] Make Script Run By Using Hardware Keys

412 posts
Thanks Meter: 875
 
Post Reply Email Thread
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.
 
 
19th June 2010, 07:21 PM |#2  
neckface's Avatar
Senior Member
Thanks Meter: 11
 
More
Quote:
Originally Posted by BuglessPete

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.

Genius. Expect a donation from me.
21st June 2010, 06:53 AM |#3  
Senior Member
Flag The Colony, Texas
Thanks Meter: 2
 
More
Bumping this cause it seems like it would be pretty useful...
21st June 2010, 07:09 AM |#4  
Senior Member
Thanks Meter: 130
 
More
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?
22nd June 2010, 01:10 AM |#5  
Senior Member
Flag Seattle Wa
Thanks Meter: 5
 
More
Thumbs up
That is awesome Pete good work and keep it up!!!!!!!
dehelflix
22nd June 2010, 01:24 AM |#6  
Guest
Thanks Meter: 0
 
More
glad i donated to this guy, hes a smart cookie. hopefully, you're close to having enough for an evo!
26th June 2010, 05:59 AM |#7  
neckface's Avatar
Senior Member
Thanks Meter: 11
 
More
Donated.

Confirmation number: 036688013H805551B
26th June 2010, 08:54 PM |#8  
Decad3nce's Avatar
Retired Forum Moderator / Recognized Developer
Thanks Meter: 2,774
 
More
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.
21st June 2016, 10:51 AM |#9  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by BuglessPete

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.

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?
22nd August 2017, 07:37 PM |#10  
Junior Member
Thanks Meter: 0
 
More
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
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes