hufrea / keysh

Handle volume buttons on Android
Apache License 2.0
60 stars 1 forks source link

Double volume key press / power button #10

Closed Gordalf closed 1 month ago

Gordalf commented 1 month ago

Hi

First of all thanks for your awesome app. I have been looking for years for something like your app.

I have two questions.

Also I would like to donate to the project - is that possible?

hufrea commented 1 month ago

Hi.

Is it possible to use the power key

No.

would it then be possible to press volume up and volume down at the same time and turn on/off the flashlight?

Yes, you can write something like this:

Code ```sh set -eu torch_state="on" torch_on_off() { torch $torch_state [ "$torch_state" = "off" ] && torch_state="on" || torch_state="off" } on_down() { read key [ "$key" = "$RELEASE_DOWN" ] && { volume current down return } torch_on_off } on_up() { read key [ "$key" = "$RELEASE_UP" ] && { volume current up return } torch_on_off } loop() { while read key; do wakelock acquire 5000 case "$key" in "$PRESS_UP" ) on_up ;; "$PRESS_DOWN" ) on_down ;; esac wakelock release done } ### vibrate() { # echo "vibrate $*"; } wakelock() { # acquire|release [timeout_ms] echo "wakelock $*"; } volume() { # music|notification|ring|call up|down| echo "volume $*"; } torch() { # on|off echo "torch $*"; } loop ```
Gordalf commented 1 month ago

Cool. That code works as intended. Last thing i promise. How do i incorporate the torch code with media controls?

Below is the code I want to use:

Code

set -eu # Up 300ms -> next track # Down 30ms -> prev track TO=0.300 DUR_S=25 WL_MAX=1500 on_up() { read -t $TO key && { volume music up return } media next vibrate $DUR_S } on_down() { read -t $TO key && { volume music down return } media play_pause vibrate $DUR_S } loop() { while read key; do wakelock acquire $WL_MAX case "$key" in "$PRESS_UP" ) on_up ;; "$PRESS_DOWN" ) on_down ;; esac wakelock release done } ### Supported commands DELIM="|+|" vibrate() { # echo "vibrate $*"; } wakelock() { # acquire|release [timeout_ms] echo "wakelock $*"; } media() { # play_pause|next|previous|rewind|forward|stop echo "media $*"; } volume() { # music|notification|ring|call|current up|down| echo "volume $*"; } torch() { # on|off echo "torch $*"; } notify() { # -c -t # -i <id> -l <timeout_ms> ARGS="" for arg in "$@"; do ARGS="${ARGS}${DELIM}${arg}" done echo ":${DELIM}:notify${ARGS}"; } intent() { # -a <action> # -t service|broadcast|activity # -p <package/.Component> # -d <data> -m <mimetype> -c <category> # -e <extra_key>:<extra_value> # -e <extra_key>:{:<delimiter>:<ex_val1><delimiter><ex_val2>} ARGS="" for arg in "$@"; do ARGS="${ARGS}${DELIM}${arg}" done echo ":${DELIM}:intent${ARGS}"; } permission() { # BACKGROUND_ACTIVITY # STORAGE|TERMUX_RUN_COMMAND echo "permission $*"; } loop </p> </details> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/hufrea"><img src="https://avatars.githubusercontent.com/u/135158507?v=4" />hufrea</a> commented <strong> 1 month ago</strong> </div> <div class="markdown-body"> <details><summary>Code</summary> ```sh set -eu TO=0.300 torch_state="on" torch_on_off() { torch $torch_state [ "$torch_state" = "off" ] && torch_state="on" || torch_state="off" } on_down() { read -t $TO key || { media previous return } case $key in "$RELEASE_DOWN") volume current down ;; *) torch_on_off ;; esac } on_up() { read -t $TO key || { media next return } case $key in "$RELEASE_UP") volume current up ;; *) torch_on_off ;; esac } loop() { while read key; do wakelock acquire 5000 case "$key" in "$PRESS_UP" ) on_up ;; "$PRESS_DOWN" ) on_down ;; esac wakelock release done } ### media() { echo "media $@" } vibrate() { echo "vibrate $*"; } wakelock() { echo "wakelock $*"; } volume() { echo "volume $*"; } torch() { echo "torch $*"; } loop ``` </details> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/Gordalf"><img src="https://avatars.githubusercontent.com/u/60934027?v=4" />Gordalf</a> commented <strong> 1 month ago</strong> </div> <div class="markdown-body"> <p>Thanks a lot. I will recommend your app to everyone i know who might be interested</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>