How to remap bluetooth button based on context?

1,700 views
Skip to first unread message

Sinan Ghareb

unread,
Dec 11, 2014, 7:22:52 PM12/11/14
to tas...@googlegroups.com
Hello everyone,

I got a TomTom Bluetooth Remote. And after following an online article I was able to map the buttons as a media controller.

However, since we are on Android, I was hoping I can push it even further. I'm wondering if we can switch to different key mapping based on app context.
For example:

Google Play Music: load a media specific key mapping for controlling the music
Home Screen/Launcher: switch to D-Pad layout
Navigation: Zoom in/zoom out

Any help or ideas on this?

I'm using the remote in my car paired with a Nexus 7 2013 running Android 5. The setup so far is great. I love it.
But I would like to take it a step further.

Thanks.

Sinan Ghareb

unread,
Jul 14, 2015, 5:40:54 PM7/14/15
to tas...@googlegroups.com
Bumpty bump..

Mike Wilson

unread,
Jul 15, 2015, 9:20:33 AM7/15/15
to tas...@googlegroups.com
You can probably do this with the AutoInput plugin.  It allows you to arbitrarily remap keys. 

Sinan Ghareb

unread,
Jul 15, 2015, 12:21:48 PM7/15/15
to tas...@googlegroups.com
Thanks for the suggestion, Mike. I didn't know AutoInput can do such thing.
However, I should have provided more details because I like it be directly done through Tasker/Android because I'm planning on exporting the project as an app.

The file responsible for the mapping can be replaced easly, but you need a reboot to have it working.
Another idea I have been searching is to detect bluetooth key presses through Tasker.
So for example: current app= google maps & button pressesd= up -> zoom in etc.

I have not found anything in this regard yet.

easiuser

unread,
Jul 15, 2015, 3:33:01 PM7/15/15
to tas...@googlegroups.com
I don't have the hardware so I can't test it but you may be to have tasker intercept media button states and then relay the correct keyevent based on the application.  It may be difficult to play nice with a media player but it should be possible.
 
Set up your BT device to send media buttons.
Create profiles with the context STATE->Media Button(Play, Previous, etc) and an application other than a player.  Note if the application is a player, then it is doing what you want without Tasker interfering.
Tick Stop Event so the media button does not get passed along
For the entry task use Run Shell->"input keyevent 21" to simulate the depad left or any other relevent key for the application.  I think root is required for this.
 
You will have to experiment with the Grab and Stop Event options to get the results you desire.

Sinan Ghareb

unread,
Jul 16, 2015, 12:04:06 PM7/16/15
to tas...@googlegroups.com
Thanks easiuser. That sounds promising. I will test it today and see. I already have majority of the buttons mapped as media action. This is exciting.... will report back.

Sinan Ghareb

unread,
Jul 16, 2015, 2:14:50 PM7/16/15
to tas...@googlegroups.com
Oh wow...this works great!!! Thank you so much.

Sinan Ghareb

unread,
Jul 19, 2015, 2:16:38 PM7/19/15
to tas...@googlegroups.com
Ah...almost perfect. Google play music app is holding on to media buttons event like it's life depends on it. The only way to regain focus is to stop/pause the music.

I have even made an infinite loop to grab focus, but it still does not release the buttons focus.
So close....damn it.

Eric Sheep

unread,
Jul 19, 2015, 2:24:07 PM7/19/15
to tas...@googlegroups.com

I'm not sure what you are trying to do but for all my play pause and skip actions I use autoshare and send it to the specific audio appreciate dynamically based on what in listening to, Pandora podcasts etc...

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/v-THYiOXpBk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Sinan Ghareb

unread,
Jul 19, 2015, 2:32:10 PM7/19/15
to tas...@googlegroups.com
Hey Eric, what I managed to do so far is grabbing media button presses. So if I press the play button, it will flash " centre pressed ". But once Google Play Music is playing in foreground or background, then it grabs all media buttons presses. And the only way to release it's focus is by stopping of pausing the music.

Eric

unread,
Jul 19, 2015, 2:43:06 PM7/19/15
to tas...@googlegroups.com
We may be talking about two different things. Here is a description of the profile I'm talking about. I have a Bluetooth headset I use for podcasts at work. When I press the button autoinput captures the event and runs a task. In the task I use autoshare to send a play/pause command to beyondpod. So I never need to get the focus or grab the media controls.

Sinan Ghareb

unread,
Jul 19, 2015, 8:36:40 PM7/19/15
to tas...@googlegroups.com
I don't have these two plugins, and I try as much as possible to stay away from plugins because it adds up to response time.
I have been searching how to get higher media button event priority. And all I found so far is java codd which I have no idea how to run it through Tasker's run java code action.

Google play music is grabbing the media focus the minute a track is playing, which Pent mentioned it in the user guide. But regrabbing focus does not solve it nor release the focus from Play Music app.

If there is another way through Tasker to listen to bluetooth buttons other than media; I'm all ears.

Sinan Ghareb

unread,
Jul 23, 2015, 4:11:50 PM7/23/15
to Tasker, games...@gmail.com
Or if there is a way to get higher priority for Tasker to be the first to grab media button presses OR prevent Google Play Music app from receiving media button presses??

Anyone?

easiuser

unread,
Jul 27, 2015, 12:03:11 PM7/27/15
to Tasker, games...@gmail.com
Have you tried using a different music player?  Some play nicer than others.  You might search this forum for music player.

On Thursday, July 23, 2015 at 10:11:50 PM UTC+2, Sinan Ghareb wrote:
Or if there is a way to get higher priority for Tasker to be the first to grab media button presses OR prevent Google Play Music app from receiving media button presses??

Anyone?

On Sunday, July 19, 2015 at 6:36:40 PM UTC-6, Sinan Ghareb wrote:
I don't have these two plugins, and I try as much as possible to stay away from plugins because it adds up to response time.
I have been searching how to get higher media button event priority. And all I found so far is java codd which I have no idea how to run it through Tasker's run java code action.

Google play music is grabbing the media focus the minute a track is playing, which Pent mentioned it in the user guide. But regrabbing focus does not solve it nor release the focus from Play Music app. Sear

Sinan Ghareb

unread,
Jul 28, 2015, 5:46:42 PM7/28/15
to Tasker, ron.d....@gmail.com
Hey easiuser. Sure thee are other players, but I'm using Google Play Music as my main player. And I'm sure many users do too. I was planning on exporting this as an app but I ca not now. I will kerp looking for other ways to capture bluetooth button presses.
Reply all
Reply to author
Forward
0 new messages