Reputation: 83
I am using AOSP 13 source code.
adb shell input keyevent 4
4 is key code for back
I want to map back navigation via key code 141, so that i can use above command for back as
adb shell input keyevent 141
Is that possible ?
Upvotes: 0
Views: 196
Reputation: 83
I have found a solution.
As the keycode 141 is mapped to KEYCODE_F11 in frameworks/base/core/java/android/view/KeyEvent.java
Need to handle input event for KEYCODE_F11 in frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
Import files
import android.content.Context; import android.os.SystemClock; import android.view.InputEvent; import android.view.KeyEvent; import com.android.server.LocalServices; import com.android.server.input.InputManagerService; import android.hardware.input.InputManager;
// Handle special keys.
switch (keyCode) {
+ case KeyEvent.KEYCODE_F11:
+ long now = SystemClock.uptimeMillis();
+ if (down)
+ {
+ // Inject a key down event
+ KeyEvent downEvent = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK, 0);
+ InputManager.getInstance().injectInputEvent(downEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
+ }
+ else
+ {
+ // inject a key up event
+ KeyEvent upEvent = new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK, 0);
+ InputManager.getInstance().injectInputEvent(upEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
+ }
+ break;
case KeyEvent.KEYCODE_BACK: {
if (down) {
mBackKeyHandled = false;
Upvotes: 0