AutoInput Using a bluetooth remote to launch Tasker tasks (V2.0 with long press detection now available)

Discussion in 'Guides / Examples / Ideas Forum' started by Scottoo, Jul 29, 2015.

  1. Scottoo

    Scottoo New Member

    Joined:
    Jul 17, 2015
    Messages:
    8
    Likes Received:
    3
    I had a Bluetooth remote that came with a selfie stick lying around the house a while back (don't ask) and I wondered if it'd be possible to use it to launch Tasker tasks.

    After a bit of frustration I worked out a pretty straightforward method that uses Autoinput.

    Some potential uses for this that I've come up with are:
    • Launching Google voice search, since my phone doesn't wake up reliably when I say "OK, Google"
    • Liking or disliking a song
    • Finding out the Artist and title of song that's currently playing
    • Any activity you'd normally launch with a voice command if you're on public transport or in a quiet area

    This should work with most bluetooth devices with buttons that can connect with your phone (such as selfie stick remotes, car stereos, audio receivers, video game controllers, etc).

    Setting up your profile and finding your keycodes

    Create a new profile that has a single condition in it of Event > Plugin > Autoinput > Key. You can keep all of the settings the way they are for now.

    Next you'll need to create a task. The first action is Alert > Flash. In the text, put You just pressed %aikeycodename. When you push a button, it'll show you the code of the button you pushed and its name.

    Create a second action of Plugin > Autoinput > Modes and choose Key Suppress > disable. Without doing this the buttons on your device (and your phone itself) may stop doing what they're meant to do.

    Back out of tasker to save your changes, then press a button on your device. Take note of the keycode and key name that are displayed for each button.

    Setting the individual buttons to monitor

    Go back into your profile and go into the Autoinput Key configuration. Put a checkmark next to the keys that you want to use - any other keys will be ignored.

    Go back into your task. If you don't want the button to perform its normal action, add an action called Plugin > Autoinput > Modes and choose Key Suppress > Enable. (That means if you are using the Volume Up key, for example, hitting the key won't affect the volume. ) Then click Keys and put a check next to the keys you want to react to. Move this action to the first spot in your task.

    Assigning tasks to run

    After that you can disable the Flash we set up earlier and insert a task to launch by adding an action Task > Perform Task and choosing the task(s) you want to run. Make sure the Disable Key Suppress action is the last one in your task.

    Things to note
    • Your phone can't tell where a keycode has come from - so it'll see the Volume Up button on your phone, car stereo, and wired headset as the same command. So choose the buttons that you use carefully. If you're using the Volume up button and turn on key suppression, the Volume up button on your phone won't turn the volume up either.
    • You can add a second condition to your profile like BT Connected to make sure it only fires when you're connected to a particular BT device.
    • You can react to multiple buttons in the same task by putting an if condition on the individual actions so that it only runs if the correct %aikeycodename is created.
    Link to project

    Edit: Version 2.0 now available.

    This version puts the Key suppression and release in its own task, making it fire more reliably than when we suppress as the first step in our task. I've set the task to fire when BT is connected to the specific device we're using, and the key suppression is disabled as an exit task.

    Now onto the good part. If you have volume up and volume down buttons you'd like to map, for example, but you don't want to lose the button's normal functionality, you can set separate tasks for a regular button press and a long button press.

    The way it works is that one task fires when a button enters the down state, and we write the time that it happens into a variable. Another task runs when the button is released - this task grabs the time when it's released and compares the two numbers to see how long it was held down for. If the button was held down for more than 1000 milliseconds, it runs a task in the long press section. If it was held down for less than 999 milliseconds it runs a task in the regular click section.

    As long as you can replicate what the button normally does with a Tasker action, you won't lose the button's normal functionality.
     
    Last edited: Aug 3, 2015
    joaomgcd and Daniel D like this.
  2. MikeW

    MikeW Member

    Joined:
    Feb 16, 2015
    Messages:
    113
    Likes Received:
    9
    Scottoo and joaomgcd like this.
  3. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    8,488
    Likes Received:
    720
  4. MikeW

    MikeW Member

    Joined:
    Feb 16, 2015
    Messages:
    113
    Likes Received:
    9
    Go right ahead. I'm happy to give something back.
     
  5. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    8,488
    Likes Received:
    720
  6. MikeW

    MikeW Member

    Joined:
    Feb 16, 2015
    Messages:
    113
    Likes Received:
    9
    Great!
     
  7. easiuser

    easiuser Member

    Joined:
    Mar 7, 2015
    Messages:
    50
    Likes Received:
    4
    I had been using Tasker's Media Button events to control my phone while in the car but was constantly having issues with grabbing control. I decided to give this method a try. It works great as long as the screen is on. If the screen is off, no profile will fire. Tasker's Media Button event is not effected by the screen.

    Do you experience a similar restriction with autoinput?

    Galaxy S4 i337
    Rooted
    Stock Android 4.4.2
     
  8. easiuser

    easiuser Member

    Joined:
    Mar 7, 2015
    Messages:
    50
    Likes Received:
    4
    I just found an entry in this forum that states autoinput won't work with the screen off (even hardware keys) so I guess it is back to the media button events. :(
     
  9. Rui Rodrigues

    Rui Rodrigues New Member

    Joined:
    Oct 28, 2015
    Messages:
    2
    Likes Received:
    0
    Joaomgcd, is it possible to change this in future releases of Autoinput?
    Thanks
     
  10. thedivision

    thedivision New Member

    Joined:
    Nov 11, 2015
    Messages:
    1
    Likes Received:
    0
    Thanks for the tutorial! I will try to use this for my steering wheel controls with my Nexus 7 car install.

    You mentioned long presses. Would it be possible to have it perform an action until you release the button? For example, push the volume up button, and it increases the volume by one step. Hold the volume up button, and it increases the volume until you let go.
     
  11. MikeW

    MikeW Member

    Joined:
    Feb 16, 2015
    Messages:
    113
    Likes Received:
    9
    There are probably a lot of ways to do something like that, but here's a simple one. I chose to use the "Media Rewind" keycode to lower the system's media volume because it made sense in the physical layout of the Bluetooth Gamepad I was using, but you can, of course, use any key you want. To make a companion way to increase the volume, just copy the profiles and tasks and rename them with "Up" instead of "Down" in the names and change the "-1" in line A1 of the first task to a "+1". You'll also need to modify the IF clause in line A3 so that it checks for a maximum value rather than a minimum.

    Profile: Vo!umeDownStart (437)
    Event: AutoInput Key [ Configuration:Keys: Media Rewind
    Key Action: Key Down ]
    Enter: VolDown (436)
    A1: Media Volume [ Level:%VOLM-1 Display:Off Sound:Off ]
    A2: Wait [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ]
    A3: Goto [ Type:Action Number Number:1 Label: ] If [ %VOLM > 0 ]

    Profile: VolumeDownStop (438)
    Priority: 11
    Event: AutoInput Key [ Configuration:Keys: Media Rewind
    Key Action: Key Up ]
    Enter: VolDownStop (439)
    A1: Stop [ With Error:Off Task:VolDown ]

    A couple of things to note: The first profile triggers on the Key Down event and the second one triggers on Key Up. Be sure you bump up the priority for launched tasks in the second profile; it needs to be greater than the the task it's trying to stop. You'll also need to run AutoInput's KeySupress function before you use these profiles and then disable key suppression when you're done. The 250 ms delay in line A2 seems to give a nice response ramp, but if you want something a little faster, just decrease that value.

    Hope this is useful.
     
  12. Evil Genius

    Evil Genius Member

    Joined:
    Mar 5, 2015
    Messages:
    112
    Likes Received:
    9
    On my stereo I have a button I can press to get the radio to listen for commands (unfortunately it isn't an android radio) However, can I find a way to map this button anyways? If I press this button it will listen, then I can say a name of who to call and then it calls that person on my phone over the speakers.

    I have yet to buy a stereo with an android OS, this is what I have for now. Is this do-able? Ultimately what I want is to press the button and autovoice to start listening instead of the radio. I have found an app called SMART BLUETOOTH HEADSET but don't really know how to use it.
     
  13. MikeW

    MikeW Member

    Joined:
    Feb 16, 2015
    Messages:
    113
    Likes Received:
    9
    You could try this profile:

    Profile: ShowKeys (307)
    Event: AutoInput Key [ Configuration:Key Action: Key Down ]
    Enter: ShowKeys (4)
    A1: Flash [ Text:%aikeycodename Long:Off ]

    If you get a flash alert on your phone when you push the radio button, you should be able to remap the displayed key with AutoInput.
     
  14. Scottoo

    Scottoo New Member

    Joined:
    Jul 17, 2015
    Messages:
    8
    Likes Received:
    3
    Mike, this is great! I'd seen that controller before and it's good to know it works so well.

    How do you get around the issue where AutoInput won't detect the button presses if the phone's screen is off?
     
  15. MikeW

    MikeW Member

    Joined:
    Feb 16, 2015
    Messages:
    113
    Likes Received:
    9
    I'm afraid I don't deal with that. I use the controller exclusively with my Digital Dash project, where the screen is always on.

    Glad you liked the post, though. Thanks.

    I would point out that if you need screen off button responses, you could get a flic (https://flic.io/). They're a little pricey, but they do work with the screen turned off. You can read my full review of them here: http://mikesgeneralblog.blogspot.com/2015/09/flic-bluetooth-button-review.html
     
    Last edited: Nov 20, 2015
  16. surge919

    surge919 New Member

    Joined:
    Aug 6, 2016
    Messages:
    14
    Likes Received:
    0
    @MikeW
    Can you share your Tasker Profiles and Tasks?
    I've tried the items listed in this thread and I do get the feedback showing which buttons were pressed. I am also able to get a button intercepted and turned into a simulated button press on the screen. The simulated button press on the screen works while in the Tasker screen, but not on any other screen.
    I'm specifically trying to get a button press to click on the Mic icon in the lastest version of the Android Auto app.
    Any ideas?
    thanks
     
  17. MikeW

    MikeW Member

    Joined:
    Feb 16, 2015
    Messages:
    113
    Likes Received:
    9
  18. surge919

    surge919 New Member

    Joined:
    Aug 6, 2016
    Messages:
    14
    Likes Received:
    0
    I received the remote you mention in your post - got it for 3.99 shipped
    So now I'm ready to set this up. Android Auto added "OK Google" so I no longer need to send simulated screen presses.
    I tried your steps a while ago but ran into some trouble. It was a while ago so I'll try again.
    I know your setup may not be the same as others but can you post your profile and task xml files?
    There are a lot of knobs to turn in order to set up tasker and autoinput and while your profile may not be an exact drop in solution, it would give others a good head start.

    Also, when the remote is connected, the onscreen keyboard doesn't appear. Is it possible to have both?
     
  19. MikeW

    MikeW Member

    Joined:
    Feb 16, 2015
    Messages:
    113
    Likes Received:
    9
    Sorry, but I don't have easy access to those routines any more; I purged them this summer to keep the Tasker environment clean. The profiles should be pretty easy to create though, if you can post what you have and what isn't working, I'll try to help you get them sorted out.
     

Share This Page