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.

Android: cancel back

Postby Arclamp » Fri Nov 10, 2017 10:39 pm

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?
Arclamp
 
Posts: 46
Joined: Thu Oct 10, 2013 7:45 pm

Re: Android: cancel back

Postby zerosang » Sat Nov 11, 2017 3:35 am

in CIrrDeviceAndroid.cpp around line 510

change
cpp Code: Select all
               
case AINPUT_EVENT_TYPE_KEY:
{
    // irr things
 
    device->postEventFromUser(event);  // this line
}
 


to
cpp Code: Select all
               
case AINPUT_EVENT_TYPE_KEY:
{
    // irr things
 
    status = device->postEventFromUser(event);  // this line
}
 


and you need return "true" in OnEvent
cpp Code: Select all
       
if (event.EventType == irr::EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown && event.KeyInput.Key == irr::KEY_BACK)
{
    // your code
 
    return true;
}
 
zerosang
 
Posts: 2
Joined: Sat May 23, 2009 12:39 pm

Re: Android: cancel back

Postby Arclamp » Sat Nov 11, 2017 5:10 am

Oh! That's brilliant, thankyou!
Arclamp
 
Posts: 46
Joined: Thu Oct 10, 2013 7:45 pm

Re: Android: cancel back

Postby CuteAlien » Sat Nov 11, 2017 11:31 am

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.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8365
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Android: cancel back

Postby Arclamp » Sun Nov 12, 2017 10:05 pm

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
Arclamp
 
Posts: 46
Joined: Thu Oct 10, 2013 7:45 pm


Return to Beginners Help

Who is online

Users browsing this forum: random_anonymouse and 1 guest