[Q] KeyEvent Trigger not working - Other Tools & General Discussion

In my currentactivity I have been trying to trigger a keyevent using the following code:
Code:
this.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
but when this part of the code runs nothing happens and it doesn't simulate the back button being pressed. Before people recommend finish() or onBackPressed(), they will not work for my required implementation because I need both the home button and the recents button to be triggered too and that apparently can be done by triggering keyevents.
Anyone know whats going wrong here?
EDIT: I added:
Code:
this.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK));
to release the key and this worked but it wont work for KeyEvent.KEYCODE_HOME or KeyEvent.KEYCODE_APP_SWITCH. Do I need to declare permissions in my manifest to perform these?

Related

[GUIDE] How to Remap Hardkey Actions || Custom App Launching

This is really a low-level type of hack, as it just requires editing a few files.
------------------------------------------------------------------------------------------
Sick of the Hero not having a designated "camera" button?
Well then, remap the damn thing.
How to:
MAKE A BACKUP OF THE FILE BEFORE PROCEEDING
Firstly, we'll need to pull the file that controls the heroc keypad which is entitled "heroc-keypad.kl" in "system/usr/keylayout".
To pull the file:
Code:
adb remount
adb pull system/usr/keylayout/heroc-keypad.kl heroc-keypad.kl
Now the file will appear in your Android SDK tools folder so you can edit it.
I recommend using Notepad++ but any kind of text editing tool will work.
Now open the file and it should look a little something like this(minus the "unuse" keys):
Code:
key 102 HOME
key 139 MENU WAKE_DROPPED
key 158 BACK
key 127 SEARCH
key 231 CALL
key 107 ENDCALL WAKE_DROPPED
key 191 DPAD_CENTER
key 115 VOLUME_UP WAKE
key 114 VOLUME_DOWN WAKE
As you can see, there are different attributes assigned to each key.
Specific application/action launchers:
Code:
HOME #Launches "Home"
MENU #Launches "Menu"
BACK #Takes you back to the last activity
SEARCH #Launches "Universal Search"
CALL #Launches the "Phone" activity and corresponding .apk or initiates a call
ENDCALL #Ends a call
CAMERA #Launches "Camera" activity and corresponding .apk
FOCUS #Initiates Auto-Focus while using the Camera
VOLUME_UP #Self explanatory
VOLUME_DOWN #^
And attributes saying if it should wake the phone at button push to complete the action, or if it should just complete the action without waking the screen.
Code:
WAKE #Completes the action without waking the screen
WAKE_DROPPED #Wakes the phone to complete the action
NOTE: "CAMERA" can't utilize the "WAKE_DROPPED" attribute since it's an attempt to launch an activity without initializing anything else.
Anyways you can assign any of these attributes to any of the keys.
Personally, I remap the Phone button to launch the Camera, and the Search button to activate Auto-Focus:
Code:
key 231 CAMERA
key 127 FOCUS
Then when I'm using the Camera, I just hold down the "SEARCH" button to focus and push the "TALK" button to take a snapshot.
After you're done with your edits, you'll need to save the file properly(NO .txt files!), and then you'll have to push it back to the phone.
Code:
adb remount
adb push heroc-keypad.kl /system/usr/keylayout
Reboot your phone, and then long press the selected button to see if your edits worked!
Enjoy!
UPDATE!!!!
Code:
--------------------------------------------------------------------
key 200 MEDIA_PLAY_PAUSE #Pauses Music
key 201 MEDIA_PLAY_PAUSE #^
key 166 MEDIA_STOP #Stops the media
key 163 MEDIA_NEXT #Plays next media
key 165 MEDIA_PREVIOUS #Plays previous media
key 168 MEDIA_REWIND #Rewinds the media
key 208 MEDIA_FAST_FORWARD #Fast Forwards the media
The second half is from the AVRCP.kl which controls media actions on our device. But as you can see the keys aren't correctly mapped as we don't have that many(or those key numbers) at our disposal.
What you can actually do is take these attributes and map them in heroc-keypad.kl
Code:
key 102 HOME
key 139 MENU WAKE_DROPPED
key 158 BACK
key 127 MEDIA_PLAY_PAUSE WAKE
key 231 CALL
key 107 ENDCALL WAKE_DROPPED
key 191 DPAD_CENTER
key 115 VOLUME_UP WAKE
key 114 VOLUME_DOWN WAKE
This maps the attribute "MEDIA_PLAY_PAUSE" at the "SEARCH" key. By pushing it, you can pause media with the first push and play it with a successive push. The added attribute "WAKE" allows it to complete the action without waking the phone.
__________________________________________________________________________________________________
I want to thank Geniusdog254 for the heads up regarding not having to edit AVRCP.kl
CHECK OUT HIS FREE APP: Search2Play(Hero/Evo support!)
and
CHECK OUT HIS REMAPPING MOD FOR THE G1
Big thanks!
NOTE: You can also use Root Explorer or any other Root File Manager that has Text Editing
Custom app launching
Ok, so with some inspiration from BuglessPete's How to make script run by using hardware keys. I've devised an 'idea' as to how to custom launch an activity with keypad push.
Currently, you can launch any activity from shell by just using am.
Here's an example of launching the browser using am in the shell:
Code:
am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity
Which results in:
Code:
Starting: Intent { act=android.intent.action.MAIN cmp=com.android.browser/.BrowserActivity }
And the program launches!
But if you put this into a script, even a basic linux shell script, you can call it quickly just by running the script! So in theory if you map this script to a keycode, you can call the script by a button push.
How?
Well first, before you compile the ramdisk, you need to create a service that contains the script necessary for the intent activity you are trying to accomplish.
Second, you have to add the proper keycodes in an init script of your choice:
Code:
#example
service <activity> /path/to/yourservice
oneshot
disabled
keycodes 107 127
Which maps the activity to the search button after launching the service with the endcall button
This is currently just a theory as I haven't tested it out myself(busy with other things).
But if you would like to attempt it, I'd love feedback.
Quick Service Creation Tutorial: http://developerlife.com/tutorials/?p=356
Little error.. heroc_keypad.kl is in /system/usr/keylayout/heroc_keypad.kl.
EDIT: And it's heroc-keypad and not heroc_keypad.
HeroMeng said:
Little error.. heroc_keypad.kl is in /system/usr/keylayout/heroc_keypad.kl.
Click to expand...
Click to collapse
Nice catch, lol.
Always forget something simple.
EDIT: I really need to start posting stuff while using my laptop.
nice
thanks man this is awesome.
im just "learning" linux. how would i set up the search button for an intent(sp) like opening the browser.apk
feefeeboomboom said:
thanks man this is awesome.
im just "learning" linux. how would i set up the search button for an intent(sp) like opening the browser.apk
Click to expand...
Click to collapse
Well "SEARCH" essentially launches the browser by linking it automatically to google search.
But, in regards to assigning it to launch a different(unlisted) activity, I'm not sure. That's something I'm actually looking into myself, and I think I'm making a little bit of head way .
Haha great work [HOPE]maybe the hero development won't die[/HOPE]
I'm putting this in my sig if you don't mind?
thatguythatdid said:
Haha great work [HOPE]maybe the hero development won't die[/HOPE]
Click to expand...
Click to collapse
As long as there are people there willing to learn, development for the Hero will never die.
[RANT]
I'll make a post in the General Section with all the bookmarked dev'ing related resources that I've found over the year. Then people can just jump in and start reading/tinkering.
What I don't like about the HeroCDMA forum is that most of the community here doesn't share much of HOW they did/do things. Hopefully that will change.
=D
[/RANT] (Please don't respond to this part, haha)
almost forgot what program are you using to open the kl file? Mine always comes out in a horizontal line instead of a vertical like yours?
Edit: Nevermind wordpad does it great
notepad++ is the sh!-|-
feefeeboomboom said:
notepad++ is the sh!-|-
Click to expand...
Click to collapse
I'm a dumbass. I didn't read the entire post before I asked my question and thought that nevermind. Yes notepad is the s
Good work, thanks for putting together a very easy to read how-to.
Thanks for this, the trackball is so annoying for pictures. I made the changes just as it states to but the zoom won't work on the search button, I hold it down and it does nothing, any idea why that may be? And the search button no longer responds on the homescreen, which makes sense but why not in the camera app?
chrish03 said:
Thanks for this, the trackball is so annoying for pictures. I made the changes just as it states to but the zoom won't work on the search button, I hold it down and it does nothing, any idea why that may be? And the search button no longer responds on the homescreen, which makes sense but why not in the camera app?
Click to expand...
Click to collapse
Zoom? Do you mean auto-focus?
I want to do this but I cant get my phone to remount. I have never had a problem before.
cd c:\android-sdk-windows\tools
adb remount
doesn't remount says "no devices found"
CarbonKang said:
I want to do this but I cant get my phone to remount. I have never had a problem before.
cd c:\android-sdk-windows\tools
adb remount
doesn't remount says "no devices found"
Click to expand...
Click to collapse
Heh, is your phone plugged in? USB cable damaged? USB port damaged? Hole plugged? Bears?
If it's none of those, do this:
Code:
adb kill-server
adb start-server
then
Code:
adb remount
If that doesn't work, start from the top again.
Decad3nce said:
Zoom? Do you mean auto-focus?
Click to expand...
Click to collapse
LOL, reading comprehension FTW! I got FOCUS and ZOOM confused. Don't play with your phone late at night!
Decad3nce said:
Heh, is your phone plugged in? USB cable damaged? USB port damaged? Hole plugged? Bears?
If it's none of those, do this:
Code:
adb kill-server
adb start-server
then
Code:
adb remount
If that doesn't work, start from the top again.
Click to expand...
Click to collapse
none of that worked. And there is nothing wrong with the ports at all. I think its Darchdroid.. It has something defective every time I use it lol.
CarbonKang said:
none of that worked. And there is nothing wrong with the ports at all. I think its Darchdroid.. It has something defective every time I use it lol.
Click to expand...
Click to collapse
Do you have USB debugging enabled?
(I haven't had any problems with darchs build)
Decad3nce said:
Do you have USB debugging enabled?
(I haven't had any problems with darchs build)
Click to expand...
Click to collapse
ya, trust me I know what I'm doing.
It just doesn't work
I would love to show you a logcat... but i cant adb remount LOL
Can someone make a flashable zip so i can have a designated camera button as search? I want to be able to click it to take a snap shot of my phone with dro cap.
Thanks

Re-mapping keys / Creating or re-assigning keyevent

OK, I've looked around but can't find an answer. Or at least an answer that I can understand. Basically what I'm trying to do is add the ability to quit/exit an app. I've read all about the differing opinions on quitting an app versus pressing back. However, just for my own self-teaching purposes, I want to learn how to do this. I'd like to be able to long-press or double tap a key to either immediately exit an app, or bring up an alternate pop-up menu that allows you to choose an action.
I am thinking specifically in relation to the Browser. The quit option was more necessary pre-CM6 because often times, it would take forever to load the home screen after pressing "home" in order to stop using the browser. A simple exit/quit option that some apps have, usually acts much quicker. Everyone knows that if you've been browsing through a bunch of webpages, hitting the back button repeatedly is a pain in the ass. The other option is to hit menu-->windows-->then close all the open windows-->then hitting the back button once the new window pops up because browser automatically opens a new page once all open windows have been closed.
Another annoyance is not being able to quickly get to your home page. Is there a way to remap/reassign/whatever, keys so that on long-press or double-tap of say, menu, or trackball, a menu pops up which has a "exit/quit" option and a "home page" option?
Another option is to add to the menu (when you hit menu), a "quit/exit" or "homepage" option.
Any help would be appreciated.
So much for a "supporting community". Way to help each other out.
What your trying to do should be located in the /system/usr folder. It has the key information you are trying to edit.
bubonik said:
So much for a "supporting community". Way to help each other out.
What your trying to do should be located in the /system/usr folder. It has the key information you are trying to edit.
Click to expand...
Click to collapse
Yeah, most people are probably trying to figure out a way to tell me I posted in the wrong section or that I need to use the search function. Thanks for your answer but I am familiar with the /system/usr files...I don't see anything in there relating to an action that quits/exits an app. Is there a specific action that is called when someone presses menu while using an app, and the menu brings up options including quit/exit?
Really? Nobody?
The keymap files are stored in /system/usr/keylayout, open them up and have a look at the things you can assign to keys.
Pull-edit-push the correct version for your handset hardware and reboot, changes will take effect. Obviously Magics are sapphire-keypad.kl and G1s are one of the trout files. Most G1s are trout-keypad-v3.kl though you can confirm your specific hardware version with getprop.
Have a search for "keymap" and "keylayout", you'll find there's already a bit of work been done of this, for example this auto key-changer.
I appreciate the help but I guess I'm not explaining myself properly. I have looked at the files in /system/usr/. I know how to remap a key so that, say...volume down = pause music, or change the menu key to have it end a call if I wanted...I know I'm not using the correct terminology all the time but when looking at the various .kl files, there are various "actions" that can be attributed to a particular key. For instance, keys 107 & 62 = Endcall, key 158 = Back, key 10 = the number 9.
In the column next to the numerical keycode in each of the .kl files, there is an "action" that results from pressing the particular key. The action I am looking for is a "quit" and/or "exit" action to apply to a particular key. Let's say I wanted to have key 231 in the sapphire keypad, kill the app I am using. Right now, pressing key 231 = CALL button. Is there a keyevent such as Kill_app or something to that affect that I could put in place of the CALL action so that key 231 = Kill app?

[Q] Non-Touch compactible rom?

Hi guys,
My digitizer has died, and till the new one comes I was thinking of how I could use my T7272, I can write the SMS fine, but I can't send them out, cause the button is on the screen itself... is there a rom I could use freely w/o using the touchscreen?
P.S.
Is the digitizer hard to replace?
You could check out AE Button; it has some options like button presses that will activate soft buttons. I suspect you could send sms's using it. You could also try using mortscripts with AE button that will do stuff you need. There are some pretty simple scripts that will simulate screen taps, and you could assign them to a button push. I'd rather have a working touchscreen, though.
Here are some of the commands:
# 91: startmenu (on some devices it might be home button)
# 92: back key (not the backspace key but back key for closing applications which is available on some devices such as diamnd or blackstone)
# 93: menu key
#112: left softkey
#113: right softkey
#114: accept call (green button)
#115: hang up (red button)
#117: volume up
#118: volume down
#126: data disconnect
#127: toggle speaker
#133: devicelock
#223: power off
I use one to lock the device. Basically, you just put this:
Code:
sendspecial(133)
in a .txt file, and change the extension to .mscr. I call it Lock.mscr, and I have it assigned to a few different actions (like when a call comes in, a script locks the phone). So, sendspecial(112) and sendspecial(113) might help you out. There's also one for hitting 'Ok' in popups, which would probably work for you. I can't find it, though (google 'sendspecial' and you'll find it, it's all on msdn).
Anyway, if you install mortscript (maybe you already have it) as well as AE Button, you could assign button pushes to carry out those actions. Just stick the scripts somewhere easy, like the start menu, and it will be easy to set up.
If you want to get more complicated, there are also mortscript commands that simulate button pushes on the screen. You could set one up that would do just about anything. Also, SK Schema does similar stuff. You can write fairly simple sequences of button pushes that will do just about anything. This is one that I use that runs SK Tools Pim backup (I have it scheduled to run every night in the middle of the night).
#r(\windows\sktstart.exe) #p(STH:20)
#tap(146;602) #sleep(15000)
#tap(110;533) #sleep(500)
#tap(339;455) #sleep(500)
#tap(126;604) #sleep(500)
#tap(114;84) #sleep(500)
#tap(146;99) #sleep(5000)
#tap(310;254) #sleep(90000)
#tap(433;602) #sleep(10000)
#pwr() #sleep(10000)
Click to expand...
Click to collapse
Basically, the backup tool gets launched in line 1, then there are a bunch of screen taps (w/ delays, to make sure everything is ready) in the menus to get the right options selected, followed by turning the device off.
I`m not sure... But i saw somewhere app that emulate a mouse (cursor) and you will be able to control this mouse with your D-pad... But I can be wrong...
I can't install that mortscript w/o the touchscreen though..damn it..: )..
Get MyMobiler, and use it to run your device off of a pc. You should be able to get that working.

[Q] [ubuntu] How to map search key to alt?

I'm happily running Ubuntu on my TF-101 now. Thanks to lilstevie and everyone else who helped make that possible!
However I'd like to make the search key on the dock act as an alt key. I know how to remap modifier keys using xmadmap, but xev doesn't seem to report any X events when pressing the search key so I can't get its code . The home key next to it is reported as "keycode 180 (keysym 0x1008ff18, XF86HomePage)", but absolutely nothing for the search key.
When you press the search key a "search for files" window pops up, so the key press is being recognised somewhere in the system, but I guess whatever that is then suppresses the normal X KeyPress event.
Anyone have any ideas about how to fix this? I guess in the meantime I'll try using the home key instead.
Ah, just figured it out. First disable the system-wide usage of the search key:
Go to System -> Preferences -> Keyboard Shortcuts
Scroll down to the Desktop section and click on "Search"
Press backspace to disable any shortcut for that function
Then xev reports the keypress as "keycode 225 (keysym 0x1008ff1b, XF86Search)" so the following command will make it act as an Alt key:
xmodmap -e "add mod1 = XF86Search"​
Hope someone finds this as useful as I do - it's nice having the keys in the right place!

Disable Capacitive Buttons (functions)

This is to show you how to disable the capacitive buttons so they will no do anything other then light up if you so please.
Generally this would be used with the onscreen NAV keys like that in the Galaxy Nexus.
Code:
I am not responsible if this causes your phone to
make first contact and bring forth a race of beings that kills us all.
I am also not responsible if this damages your phone in any way, at all.
I have done this on my SGSII LTE (Skyrocket) i727R and suffered NO issues.
I am using this on the AOKP Milestone 6 ROM.
I suspect that this would work with other ROMS and even other phones with no issues.
STEPS:
NANDROID/OTHER BACKUP!!
Using Root Explorer (or other file explorer) go to /system/usr/keylayout
MAKE A BACKUP OF "melfas_touchkey.kl"
Edit "melfas_touchkey.kl"
Add a # in front of each line, there should only be four.
Save the file and reboot your phone.
Code:
Original:
Key 158 BACK Virtual
Key 139 MENU Virtual
Key 172 HOME Virtual
Key 217 SEARCH Virtual
Code:
Altered:
#Key 158 BACK Virtual
#Key 139 MENU Virtual
#Key 172 HOME Virtual
#Key 217 SEARCH Virtual
Adding a # in front of the line disables that line of code and the function.
Now if you want the lights gone too, the only way I know of so far is to try an app that inst 100% compatible called "Keep the lights on".
The app will add a widget that you can disable the lights with.
For me, they just turn on again when coming out of standby.
[Edit]So this is also posted in RootzWiki, found it after posting.
http://rootzwiki.com/topic/31065-tu...acitive-buttons-lights-and-use-on-screen-nav/
Personally I don't see a reason to disable them but maybe you could alter this to change the function of certain keys?
ceasee said:
This is to show you how to disable the capacitive buttons so they will no do anything other then light up if you so please.
Generally this would be used with the onscreen NAV keys like that in the Galaxy Nexus.
Code:
I am not responsible if this causes your phone to
make first contact and bring forth a race of beings that kills us all.
I am also not responsible if this damages your phone in any way, at all.
I have done this on my SGSII LTE (Skyrocket) i727R and suffered NO issues.
I am using this on the AOKP Milestone 6 ROM.
I suspect that this would work with other ROMS and even other phones with no issues.
STEPS:
NANDROID/OTHER BACKUP!!
Using Root Explorer (or other file explorer) go to /system/usr/keylayout
MAKE A BACKUP OF "melfas_touchkey.kl"
Edit "melfas_touchkey.kl"
Add a # in front of each line, there should only be four.
Save the file and reboot your phone.
Code:
Original:
Key 158 BACK Virtual
Key 139 MENU Virtual
Key 172 HOME Virtual
Key 217 SEARCH Virtual
Code:
Altered:
#Key 158 BACK Virtual
#Key 139 MENU Virtual
#Key 172 HOME Virtual
#Key 217 SEARCH Virtual
Adding a # in front of the line disables that line of code and the function.
Now if you want the lights gone too, the only way I know of so far is to try an app that inst 100% compatible called "Keep the lights on".
The app will add a widget that you can disable the lights with.
For me, they just turn on again when coming out of standby.
[Edit]So this is also posted in RootzWiki, found it after posting.
http://rootzwiki.com/topic/31065-tu...acitive-buttons-lights-and-use-on-screen-nav/
Click to expand...
Click to collapse
Hey man i seen your method and i tried it but, it didn't work for me and i checked the file after a reboot and the buttons still work even thought I am trying to disable it.
I figured this out a couple months ago when I was only using virtual buttons. XD
CoogiMane1996 said:
Hey man i seen your method and i tried it but, it didn't work for me and i checked the file after a reboot and the buttons still work even thought I am trying to disable it.
Click to expand...
Click to collapse
Did you save the file? And as the right name?
Sent from my SAMSUNG-SGH-I727 using xda app-developers app

Categories

Resources