Device buttons

Hi. I'm really liking Juce so far; nice clean API, great docs. Awesome!


Is there any way to have Juce respond to Android device buttons - e.g. Back, Menu? I've searched a few times, but haven't found anything so far. Possibly I'm just using the wrong keywords :)


Any help greatly appreciated!

I'm totally new to Android dev, but perhaps KeyPressed() might return somthing useful? Otherwise you'll probably need to do this on the JAVA side.

This has been on my to-do-list.. I was rather hoping that someone using android would give me a helpful snippet that points me in the right direction... :)

Thanks guys.


I'll try Rory's suggestion, and see if I get anything from keyPressed. That would certainly be a sensible way for the device to report it, but I suspect Android might not be that sensible :) Otherwise I'll take a look around the Android docs and post here again if I find anything useful. If it does involve Java, my motivation to get it working may diminish somewhat ;)


Thanks again

I hear you. I'm currently pirouetting around JAVA obstacles like Nijinsky. I fear I've run out of stage however. Crash, thump, wallop. 

Btw, have you looked at this:

Might be of some help to you?

Fantastic, thanks Rory. I'll take a look.

How is the device buttons comming along? It's been a year so it might be done already for what I know.

Don't think we've got anything new, but Android is a big priority for us now, so I'll make sure this is in our backlog!

For support the back button of Android, my nasty solution is:

bool ComponentForSomething::keyPressed (const KeyPress& key)
    if (key == KeyPress::escapeKey)
        // ... make it disvisible, show pervious component,
        // deliver the escapeKey to parent component or something else

        return true;
    return Component::keyPressed (key);

I've been wondering how to get the back button working for Android... will try your escape key method, thanks

Is it that easy? Thank you, the back button is kind of important.

Glad to hear about the Android future, thanks

As Jules already said, this is in our backlog and we will implement it as soon as we have time.

How is the current status on this?

In our app it is a huge issue unfortunately that if you type text into a text editor and press the back button that the keyboard reappears, as the text editor natively doesn’t lose focus. This wouldn’t be a problem at all if I could unfocus everything on pres of the back button. Unfortunately the back button is not handled by the keyPressed event in any way!

1 Like

Still nothing, I guess…

I know this was 5 years ago, but I’m trying your method now and it doesn’t catch the back button on my Galaxy S10.

Oh wow! Just found out that the back button is managed in the ApplicationBase class

virtual bool backButtonPressed()

Another one on this bumpy road here:
I’d like to intercept volume rocker events.
While nothing(!) happens on android, it (sort of) works on windows (surface pro 7):
keyPressed() gets called, but the keyCode is always 0, while it should be 174(0xAE) or 175(0xAF).

I’m not into keycodes, unicode and implementation layers, but could it be a reason there is no Keypress::volumeUpKey implemented (yet)?
doKeyDown() (juce_win32_Windowing.cpp, line 3017) however runs into the switche’s default and tries translating it into unicode, but ToUnicode() obviously returns “0”
There are definitions for play, stop etc. in juce_keyPress.h though, and volume keys are listed at least in winUser.h…

Puhh, much info, hope it doesn’t confuse…
Maybe somebody can point me to the right direction?

I have an FR for just this. Voting on it would be better than digging up old threads! :smiley: