Page 1 of 1

Android: cancel back

Posted: Fri Nov 10, 2017 10:39 pm
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?

Re: Android: cancel back

Posted: Sat Nov 11, 2017 3:35 am
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;
}
 

Re: Android: cancel back

Posted: Sat Nov 11, 2017 5:10 am
by Arclamp
Oh! That's brilliant, thankyou!

Re: Android: cancel back

Posted: Sat Nov 11, 2017 11:31 am
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...

Re: Android: cancel back

Posted: Sun Nov 12, 2017 10:05 pm
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