How to catch the back event in an android application built in Defold

Good afternoon. I am making a game for Sber devices (All Sber technologies are here). The game should work on consoles or on TVs. Management occurs through the remote control.

Since the devices are rather weak, html5 is not suitable, and the apk generated by Defold gives a stable 60 fps

I have a problem with the back key. it is not defined as KEY_BACK, but gives a message to the “back” system

In html5 I would do this:

    window.history.pushState({name: "start"}, "");
        window.addEventListener("popstate", e => {
           e.preventDefault();
           console.log("state:" + e.state);
           if (e.state == null) {
               jsToDef.send("KeyPressed", {
                   key: event.keyCode
                   type: "back"
               })
               window.history.pushState({name: "start"}, "");
           }
        }, true);

And how can I do this in Defold for android:

I think that my problem is not so rare because a lot of games are made for TVs, and there is a similar situation with the back key.

Hello there and welcome!

You can of course provide back navigation for Android.
Have a look eg. here:

You set the keys in the input bindings:

1 Like

Looks like this here (Defold 1.3.6). But yes, you choose the “Back” key in the “input” section of “Key Triggers”, under “Action” you give the action any name you like.

Edit:
just spotted it in the image you posted. You do not set the keys in the file “all.input_binding” from the builtins.
Scroll a bit further down, there you’ll find another folder called “input” with the default game.input_binding file that is created with every new project. That is the file where you set the keys for your game.
This is an image from an empty project:
image832

4 Likes

All as said, thank you very much for your help! :+1:

3 Likes