How to define 'Power Button' (the key that is used to lock and unlock screen with single click) for android ?

For ‘Back Button’, that i have got to know is KeyCode.Escape. If while scripting ‘Back Button’ is defined by ‘Escape’, how ‘Power Button’ is defined while scripting for android in unity? I really need help in this, as i am submitting my app on samsung appstore, it’s giving the failure issue like: Timer is run after interrupting by Power Button. Thanks in advance.

As far as I know, currently there is no key code assigned in Unity for power key.

Currently I do not have Unity with me but you can check for the keycode through Event.keyCode to check if any keycode is assigned to the power key. I guess there will no keycode available for the power key.

To receive the key code for the power key you have to use the native programming for Android to receive power key event and work accordingly.

But to use plug-in you will need Unity Pro.

Find below some links that may help you with the same.

  1. How to hook into the Power button in Android?

  2. Building Plugins for Android

To handle the demands of the Samsung App Store regarding turning off audio when the power button is long pressed, just do this…

void OnApplicationFocus(bool focusStatus) {
	if(focusStatus == true){
		//turn on sound
	}else{
		//turn off sound
	}
}