I was hoping some flexibility in long-press timeout using AutoInput but the apps slows down my OS considerably to do anything with it.
Anyhow, all I suggest is to use Xposed Additions (free/paid; requires Xposed Framework; if you've Android 5.x, you would need to flash some files from custom recovery. See this XDA thread by rovo89 for such case).
We need Tasker (paid, 7 day free trial) too.
Instructions
(Tested on Android 5.0.2 and 5.1.1)
Install both the apps → activate Xposed Additions's module → launch Xposed Additions
Tap Buttons → set Long press delay slider to maximum (500ms) → Add new Key → press Power key to select it → Power
Tap Add new Condition → Screen Off → Screen Off → enable Long Press → Shortcut → Task Shortcut → New Task → name the task.
Note: You can try MacroDroid's MacroDroid Shortcut in place of Task Shortcut. The free version is restricted to one action per macro, so you wouldn't get any flexibility, but it is acceptable here.
For your task, action would be:
- Alert → Vibrate → Time: select the vibration time (in milliseconds)
It is possible that vibration for 1000ms would not be enough for you. In that case, add combination of actions. For example, in addition to last Vibrate action, you can also do:
Task → Wait → select MS or/and Seconds slightly greater than milliseconds selected in last Vibrate action
Wait is important because if you add continuous Vibrate actions then you would end up skipping almost of them except the first one. Tasker doesn't queue vibrate requests, as it seems to me.
- Now, add another Vibrate action and copy-paste the whole cycle as much as you want.
Select an icon for your task and there you go.
You can now test your solution.
Experimental
For users having AutoInput satisfactorily running, you can emulate long-press of a key. I tested my solution on Volume Up key and it worked perfectly. Well almost!
For Tasker:
Profile 1: Event → Plugin → AutoInput → Key → Configuration:
- select your key under Keys
- select Key Action to Key Down
Task 1: Actions:
- Variable → Variable Set → Variable:
%Set
→ To: 0
- Task → Wait → select MS or Seconds for your desired long-press timeout. Choose 1 Second for experimental purposes
- Task → If →
%Set
eq
0
- Alert → Vibrate → Time: 1000ms
Profile 2: Event → Plugin → AutoInput → Key → Configuration:
- select your key under Keys
- select Key Action to Key Up
Task 2: Actions:
- Variable → Variable Set → Variable:
%Set
→ To: 1
Use the action Key Suppress from Plugin → AutoInput → Modes, wherever feels necessary. Also, I didn't yet experiment with screen off state.
Now, the theory: The flow is in this manner:
- When your selected key (say Key-X) would be pressed, profile 1 would activate.
- When the key would be released, profile 2 would activate.
- We know that for long-press the key needs to be continuously pressed for some time.
- Now, if I long-press Key-X then for that time being profile 2 would not activate and so I can set
%Set
to 0
in profile 1 → wait for long-press timeout (slightly less) → check if %Set
is still 0
(%Set
would become 1
if key gets released) and then execute the Vibrate action.
Simple! Let me know if it works for Power key.