Access Hardware Buttons | KeyEvent?


#1

How can I access to the android hardware buttons?

I couldnt find a tutorial for that etc. I think I have to handle with the android KeyEvent
https://developer.android.com/reference/android/view/KeyEvent.html

I want to change the behaviour of a DPAD … e.g. KEYCODE_DPAD_CENTER

I found this https://ionicframework.com/docs/native/keyboard/ but that is only for the visual Keyboard I guess.

So, has anyone found a solution to change functionality of the hardware buttons?

I am using the latest version of Ionic.


#2

ok, I found out that the question is more related to Cordova.

from the cordova documentation I can see that only a few events are supported: http://cordova.apache.org/docs/en/7.x/cordova/events/events.html#searchbutton

e.g.

ionViewDidLoad(){
document.addEventListener(“volumedownbutton”, this.onVolumeDownKeyDown, false);
}

onVolumeDownKeyDown() {
// Handle the volume down button
alert(“Test”)
}

is working on android! Now the question is, how can i build my own events like volumedownbutton ? I think I have to duplicate some code in the cordova core files and adapt it, but this seems to be not a clean solution.