Android: cancel back

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Android: cancel back

Post by Arclamp »

Hi,

How do you cancel the app minimising when the Back button is pressed (but also then minimise it when need)


I can get the key code, but returning positive doesn't handle it, how to please?
zerosang
Posts: 2
Joined: Sat May 23, 2009 12:39 pm

Re: Android: cancel back

Post by zerosang »

in CIrrDeviceAndroid.cpp around line 510

change

Code: Select all

                
case AINPUT_EVENT_TYPE_KEY:
{
    // irr things
 
    device->postEventFromUser(event);  // this line
}
 
to

Code: Select all

                
case AINPUT_EVENT_TYPE_KEY:
{
    // irr things
 
    status = device->postEventFromUser(event);  // this line
}
 
and you need return "true" in OnEvent

Code: Select all

        
if (event.EventType == irr::EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown && event.KeyInput.Key == irr::KEY_BACK)
{
    // your code
 
    return true;
}
 
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Android: cancel back

Post by Arclamp »

Oh! That's brilliant, thankyou!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android: cancel back

Post by CuteAlien »

You could also try if you can replace the InputHandler after the device was created. You got already the android_app* pointer in your app. It should have an onInputEvent member variable which is of type:
int32_t (*onInputEvent)(struct android_app* app, AInputEvent* event);

So if you backup a pointer to the old onInputEvent you can put int your own function pointer in that structure (it will use the current function pointer in android_app in each call to IrrlichtDevice:run()). And then basically copy some code from CIrrDeviceAndroid::handleInput by calling AInputEvent_getType and checking for AINPUT_EVENT_TYPE_KEY and then return 1 for that specific key. In all other cases call the old onInputEvent function from Irrlicht.

Note - I did not test this, that just should work in theory...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Android: cancel back

Post by Arclamp »

Got to love theory!

On the previous... It use's the Backspace key, so added a flag that could check for when softkeyboard is active in case the Backspace was needed.

But, theoretically there's a better method now!


Cheers
Post Reply