Does anybody know if it is possible to either conditionally block a Hardware Key Event or simulate the button press? I'd like to be able to use the "Hardware Key Event" trigger to catch the key events, run through some additional logic, and either block the event or allow it to continue depending on certain conditions.
Thanks.
Conditional Hardware Key Block or Simulate Key Press
Moderator: Martin
Re: Conditional Hardware Key Block or Simulate Key Press
I don't think there's a way to block incoming events, but you can have Automagic block any future events by checking the Block Event option in the Hardware Key Event trigger. You can have this trigger in one flow and have the conditions in another flow that will enable/disable the flow to block the events if the conditions are met.
As for simulating button key presses, you can use the Execute Root Command action with "input keyevent <key code>".
You can find more info about what number each key corresponds to here. Just note that this requires root.
As for simulating button key presses, you can use the Execute Root Command action with "input keyevent <key code>".
You can find more info about what number each key corresponds to here. Just note that this requires root.
Hope my post was helpful
Device: OnePlus 5T running crDroid, rooted with Magisk
Device: OnePlus 5T running crDroid, rooted with Magisk
Re: Conditional Hardware Key Block or Simulate Key Press
To add up, you can still do it without root. But you have to switch to automagic keyboard first and then use Control UI to send the key.
The idea is, use the hardware key event to block the key, so it is intercepted only by Automagic. Do your script and calculate the logic. If the result is to pass the key to the OS, then switch to Automagic keyboard, use Control UI, sendKey() to send the key and then switch back to default keyboard. You can switch the keyboard without root, using Set System setting. But this introduce a big latency, can be up to 1 seconds. Since you have to switch the keyboard first before using sendKey().
The idea is, use the hardware key event to block the key, so it is intercepted only by Automagic. Do your script and calculate the logic. If the result is to pass the key to the OS, then switch to Automagic keyboard, use Control UI, sendKey() to send the key and then switch back to default keyboard. You can switch the keyboard without root, using Set System setting. But this introduce a big latency, can be up to 1 seconds. Since you have to switch the keyboard first before using sendKey().
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Conditional Hardware Key Block or Simulate Key Press
@Desmanto
I like your idea of blocking and letting Automagic handle every hardware key event. However, I don't think Automagic keyboard is necessary since Control UI already has many of the functions for simulating physical/on-screen buttons except for the volume keys I suppose (but you could just use the Store Audio Volumes action, do calculation on the value and then use the Set Audio Volumes action to set the new volume level).
I like your idea of blocking and letting Automagic handle every hardware key event. However, I don't think Automagic keyboard is necessary since Control UI already has many of the functions for simulating physical/on-screen buttons except for the volume keys I suppose (but you could just use the Store Audio Volumes action, do calculation on the value and then use the Set Audio Volumes action to set the new volume level).
Last edited by Pepy on 22 Jun 2019 21:46, edited 1 time in total.
Hope my post was helpful
Device: OnePlus 5T running crDroid, rooted with Magisk
Device: OnePlus 5T running crDroid, rooted with Magisk
Re: Conditional Hardware Key Block or Simulate Key Press
@Pepy : If we want to press button or access certain UI Element (clickById(), checkById() ), then yes, Automagic keyboard is not needed. But since we want to simulate "key press" (A, B, C, DPAD, Volume button, etc), we must use Automagic keyboard to achieve it. Or it can be done using adb input, but require root. And adb input is very slow, especially when emulating keyboard typing, approx 2-3 keys/second
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.