Android Hardware Keys

Hello, is there a way to query the volume up and down button on mobile devices?
Greetings Markus

2 Likes

Hat niemand eine Idee?

Tried to solve the problem with Javascript. I can define the volume up and down buttons. But since I’m not very familiar with Javascript (I only know the basics of C++) I can’t query the keys. Maybe someone can help.
I have a screenshot. I have problems with the last query.
The code works except for the last query. This shows me the fact that when I start it on my phone, the default function of the down key is non-functional.

I just have no idea how to query it in javascript.

The scene variable starts with 0.
I only used it for testing.
Perhaps one could create an extension from “onVolumeDownKeyDown” and from “volumeupKeyDown”.
Or maybe you could extend the BackButton function.

Hello, recently solved the problem myself to some extent. Have a javascript code that queries the “Volume Up button” and “Volume down button”.
In the project I created two global variables for this.
“var_VolumeDown” and “var_VolumeUP”
By pressing one of the two keys, the result “1” is returned, i.e. key pressed.

Here is the javascript code:
(Actually simple, maybe someone wants to write an official extension out of it…)

// -- Volume down button --
document.addEventListener("volumedownbutton", onVolumeDownKeyDown, false);


function onVolumeDownKeyDown() {
    // Handle the volume down button
    runtimeScene.getGame().getVariables().get("var_VolumeDown").setNumber(1);
    
}

// -- Volume up button  --
document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false);

function onVolumeUpKeyDown() {
    // Handle the volume up button
   runtimeScene.getGame().getVariables().get("var_VolumeUP").setNumber(1);
   
}
3 Likes

Here is a small example.
Sorry the text is in German.

ScreenRecorder_20220927-152017

p.s. needed the functionality for an Android tool that should appear in the Play store soon.
Of course nothing speaks against using it in games.
Maybe I could help someone with this post.

2 Likes