I've come close but I still can't launch an action at the same time when two keys are pressed in combination like the way we do for taking a screenshot. Anyhow, you would need:
- AutoInput (for Android 4.3 and above) with Tasker, both are/have paid/7-day full trial, or
- Xposed Additions (needs root access) with Tasker to make key combination(s).
The inconvenience in this solution is that unlike pressing both keys at the same time you would have to do it in sequence. That is, press/hold Vol Up followed by Power button. The timing between these key-presses is flexible.
Single key-press
Use AutoInput with Tasker if you want to launch your action with single key presses combination i.e. only press a key one time but don't want to long-press the keys.
In Tasker create an Event based profile from Plugin → AutoInput → Key → Configuration:
- Keys: Volume Up
- Key Action: Key Down
Create a task in it named "AutoInput Volume Up
" and create following actions in it:
Variable → Variable Set:
- Task → Wait → Seconds:
1
Variable → Variable Set:
Explanation: When the single Vol Up press is detected the custom variable %Kset
would be initialized to a custom value 1
and then we would wait for one second (under this one second you would've to press the Power key). We're then initializing the variable to 0
because our solution demands it, otherwise, our main task of capturing a photo would be executed just by a single press of Power key.
- Repeat step 1 but select Power key instead of Volume Up key.
Create a task in it named "AutoInput Power
" and create following actions in it:
- Task → If → Condition:
%Kset
eq 1
Plugin → AutoInput → Modes:
Configuration:
- Key Suppress: Enable
- Keys: Power
- Timeout: None
- Optional action -- Alert → Flash → Text:
Commencing launch
- Media → Take Photo → customize it as per your needs.
- Repeat sub-step 2 of step 4 but do Key Suppress: Disable.
- Optional action -- Task → Else.
- Optional action -- Alert → Flash → Text:
Psst: You're too late Jim!
Explanation:
- In our first action we are checking whether the variable
%Kset
is set to 1 and if yes then the second action would block Power button press from getting passed to system since normally Power key-press would put the device to sleep and lock the screen.
- Optionally flash a custom toast signalling that combination was successful.
- Let the Tasker capture the image using the settings provided in that action.
- Disable Power key suppress since otherwise, you would never be able to use that button normally, as long as key suppress is not explicitly disabled or AutoInput's accessibility is running.
- Else statement is optional but could come handy since in the beginning your consecutive key-presses may not be in coordination so the custom toast in next action would hint you that the combination wasn't successful.
That's it. Go to Home screen or to any non-Tasker app, press the Vol Up key and then the Power key under a time period of one second (don't worry, you would get a hang of it, or else, change the wait period) and you would see Tasker opening its custom interface, a picture would be captured automatically and you would be taken back to what you're originally doing.
Hurray!
Long key-press
Some people may not like single pressing both the keys since they are not habitual or may feel odd to use them in that coordination. In that case, provided that you've root access and Xposed Framework installed, you can use Xposed Additions to set long key-press actions for your keys.
For custom action to be set to those keys we would need Tasker. Create the two tasks named "AutoInput Volume Up
" and "AutoInput Power
" explicitly in Tasker, only if you didn't follow Single key-press section.
- In that app go to Button → set Long press delay time → Add new key → tap Vol Up key → select the new key entry.
- Tap Add new Condition → Screen On → → select the new entry → check Long Press and tap on that entry → scroll down to Shortcut → Task Shortcut → AutoInput Volume Up.
- Repeat step 1 but do it for Power key.
- Repeat step 2 but select AutoInput Power under Task Shortcut.
Whenever Xposed Additions is enabled and activated in Xposed Framework, on any long-press of a button/key set under that app, you would feel a slight vibration. That vibration would help immensely to know when to release the first key and long-press the other key.
Try it because it's fun.