0 votes

Hello, I am currently trying to invoke callback methods when the Volume Keys or a Hardware Key (Back, Home, Overview ) is pressed. Therefore, I started to implement a custom android module but atm, I am wondering how I can override these methods as they are part of the Activity class and not of GodotSingleton.

Is there a way to intercept presses of the Volume/SystemUI Buttons and execute my own code? I want something like this:

public class GodotInputHandling extends Godot.SingletonBase {
    private static final String TAG = "inputHandling_Activity";

    private Activity activity;
    private int instanceId = 0;

    static public Godot.SingletonBase initialize(Activity p_activity)
        return new GodotInputHandling(p_activity);

    public GodotInputHandling(Activity p_activity)
        registerClass("GodotInputHandling", new String[]
        activity = p_activity;

    public void initModule(int _instanceId) {
        //some init code here if needed

    //I want something like this, but it should override the metod in the activity
    public boolean dispatchKeyEvent(KeyEvent event) {
        //check which key it was and call method in gdscript like:
        // if(event == .... ){
        //     GodotLib.calldeferred(instance_id, "_on_volume_down_pressed", new Object[] { });
        // } else {
        //      GodotLib.calldeferred(instance_id, "_on_foo_pressed", new Object[] { });
        // }


    //Or something like this, but this method is also part of the activity
    public boolean onKeyDown(int keyCode) {

in Engine by (20 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.