Double Click Volume Up in Chrome To Share Page

Learn how to react to the volume keys so that you can share your currently opened web page in Chrome

  1. joaomgcd

    STEP 1 - CREATE NEW CHROME PROFILE


    • Create a new profile with the App->Chrome condition


    STEP 2 - ENABLE KEY SUPPRESS MODE


    • In the Task, add a new "AutoInput Modes" action
    • In the action, enable the "Key Surpress" option
    • Go back to Tasker
    (i) Enabling Key suppress mode allows you to block the normal function of hardware keys. In this example you're making the volume keys not perform their original function of changing volume, but will share the current page on double click instead


    STEP 3 - DISABLE SUPPRESS ON CHROME EXIT


    • Long click the Entry Task of your new profile and select "Add Exit Task"
    • In the task once again add the "AutoInput Modes" action
    • Disable Key suppress with this action
    (i) This will make the volume keys behave normally whenever you're not using Chrome.


    STEP 4 - VOLUME UP CONDITION


    • Create a new profile with the event->plugin->"AutoInput Key" condition
    • In the "Key" field, select "Volume Up"
    • In the "Key Action" field select "Key Down".
    (i) By selecting "Key down" you'll make this profile trigger only when the volume key is pressed down and not when it's released. If you did not select it, the profile would trigger twice for each button press (once when pressing down on the key and another time when releasing the key)


    STEP 5 - INITIALIZE %LASTSECONDS


    (i) In the task we're going to react to a double click of the Volume Up key. We'll need to make sure that the key is pressed twice in rapid succession, so we'll need to check when it was last pressed and compare that to the current time. If less then 3 seconds have passed between presses, we will consider it a double click.

    • Add a new "Variable Set" action.
    • In the "Name" field write %LASTSECONDS
    (i) This variable will control how much time has passed between each press of the volume up key
    • In the "To" field, write 0
    (i) We need to set the variable to 0 if it doesn't have a value. You'll add the "If" condition in the next step.


    STEP 6 - ONLY IF %LASTSECONDS ISN'T SET


    • Press the plus sign in the "If" line
    • In the Left field of the If, write %LASTSECONDS and in the middle button select "Isn't Set"
    (i) This will make %LASTSECONDS be set to 0 only if it didn't have a value before. This will only happen the first time you run this Task, because of the end of the task we'll be setting this value.


    STEP 7 - CHECK THE DIFFERENCE


    (i) We now want to calculate the difference between the time the button was last pressed and the current time

    • Add a "Variable Set" action
    • Set the Name to %difference
    • Set the "To" field to %TIMES - %LASTSECONDS
    (i) %TIMES is the cucrrent system time in seconds
    (i) %LASTSECONDS is the time that the volume key was last pressed in seconds


    STEP 8 - DO MATHS


    • Check the "Do Maths" option
    (i) This will make Tasker calculate the difference between one value and the other
    • Go back to the Task


    STEP 9 - CHECK IF THE CALCULATION IS CORRECT


    • Insert a "Flash" action
    • In the text field write "Difference is %difference seconds"
    (i) This will allow you to easily check if the calculation above is correct


    STEP 10 - SET %LASTSECONDS TO NOW


    • Add a "Variable Set" action
    • In the "Name" field write %LASTSECONDS
    • In the "To" field write %TIMES
    (i) This will make the %LASTSECONDS variable be set with the current time in seconds.
    (i) The idea is that with every press of the volume up key, you check the difference between "now" and the last button press, then set the last button press to "now" so you can check it again when you press the key again


    STEP 11 - TEST TIMINGS


    • Test the task a few times by pressing the play key with different intervals
    (i) You can see that the first time you run the app the difference will be huge, because there was no "last time". The second time you run it, the difference will be just a few seconds though.


    STEP 12 - ADD IF


    • Add an "If" action above the last "Variable Set" action
    • Make the condition %diffence < 3
    (i) This will make Tasker enter this part of the task whenever the value of %difference is lower than 3


    STEP 13 - END IF


    • Add an "End If" action just below the "If" action


    STEP 14 - ADD UI QUERY ACTION


    • Add an "AutoInput UI Query" between the "If" and "End If" actions
    • Select the "Variable Setup" option


    STEP 15 - FIND URL VARIABLE


    • Open Chrome and navigate to any web page
    • Make sure that the URL bar is visible, pull down the notification panel, and press the "Accept" button in the AutoInput notification
    • Go back to Tasker and select your URL
    • Give this variable the name "url" (no quotes)
    • Accept these settings and go back to the Task


    STEP 16 - FLASH FOR CONTROL


    • Add a "Flash" action for control.
    • In the text field wite "sharing url %url"


    STEP 17 - OPEN URL ON PC


    /!\ To complete this step you need to have the AutoRemote Chrome Extension installed and set up.

    • Add an "AutoRemote Message" action
    • In the "Recipient" field select your Chrome "device"
    • In the "Message" field write %url
    • Accept settings and go back to the Task


    STEP 18 - ADD CHROME CONDITION TO AUTOINPUT PROFILE


    • Go back to the profiles Tasker screen and add another condition to the AutoInput profile
    • Select the "App->Chrome" condition
    This will make the volume key only do the sharing on double press if the Chrome app is open and not anywhere else.
    • Back out of Tasker so everything's saved.


    STEP 19 - TEST


    • Open Chrome and press the Volume Up key once.
    (i) You'll see that a flash will appear showing the difference between the last 2 presses
    • Make sure that the url address bar is showing and double press the volume key.
    (i) You'll first see 2 flashes, each indicating its own difference and then a 3rd flash showing the url. The url should now open on your PC's Chrome
    For more information, check out the AutoInput category page.

    #Georg likes this.