How to Use ADB to Control Keypress events on Android

Android

You might be wondering why on earth would someone want to control his Android phone using the ADB commands. Well, as long as all your device hardware keys are working fine and the touch screen panel works flawlessly, you won’t find the article of any use.. until the day arrives when one of the back or menu buttons go kaput. That’s when you’ll visit your bookmarks to look up this article (hint: bookmark this!).

I will be covering how you can control your Android using virtual hardware keys on some of the applications on your device later in a separate post. But before that I will have to make arrangements so that you can install those apps on your device even when the keys are not working. Come on, no one keeps such apps installed on their Android beforehand, right? This post is for the users who already have non-functioning Android hardware keys.

Before we continue, install Android SDK on your computer and enable ADB Platform tools. You can have a look at our article on Chrome for Android debugging where we have discussed it in the first two steps. Having done that, add the path of ADB files to Windows Environment Variables. If you don’t know how to do that, refer to out article on Windows keyword and have a look at steps 3 to 6. This makes sure you can use the ADB command throughout Windows. Also make sure that your device drivers are installed as well.

Waking Up Phone.

Adb Reboot

Before we use any of the key events, you will have to wake up your phone first and with the power button not working, it would not be an easy task. Sadly I was not able to find any command that could wake the phone but you can always reboot your phone using the command adb reboot and once the phone reboots, use the following keypress events to install the applications.

Use Key Events

After the phone wakes up, you can use the following syntax to control: use the command adb shell input keyevent .

Adb Shell Input

Just replace the keycode with the numbers corresponding to the events you would like to perform as mentioned in the table.

Key Code

Events

0

KEYCODE_UNKNOWN

1

KEYCODE_MENU

2

KEYCODE_SOFT_RIGHT

3

KEYCODE_HOME

4

KEYCODE_BACK

5

KEYCODE_CALL

6

KEYCODE_ENDCALL

7

KEYCODE_0

8

KEYCODE_1

9

KEYCODE_2

10

KEYCODE_3

11

KEYCODE_4

12

KEYCODE_5

13

KEYCODE_6

14

KEYCODE_7

15

KEYCODE_8

16

KEYCODE_9

17

KEYCODE_STAR

18

KEYCODE_POUND

19

KEYCODE_DPAD_UP

20

KEYCODE_DPAD_DOWN

21

KEYCODE_DPAD_LEFT

22

KEYCODE_DPAD_RIGHT

23

KEYCODE_DPAD_CENTER

24

KEYCODE_VOLUME_UP

25

KEYCODE_VOLUME_DOWN

26

KEYCODE_POWER

27

KEYCODE_CAMERA

28

KEYCODE_CLEAR

29

KEYCODE_A

30

KEYCODE_B

31

KEYCODE_C

32

KEYCODE_D

33

KEYCODE_E

34

KEYCODE_F

35

KEYCODE_G

36

KEYCODE_H

37

KEYCODE_I

38

KEYCODE_J

39

KEYCODE_K

40

KEYCODE_L

41

KEYCODE_M

42

KEYCODE_N

43

KEYCODE_O

44

KEYCODE_P

45

KEYCODE_Q

46

KEYCODE_R

47

KEYCODE_S

48

KEYCODE_T

49

KEYCODE_U

50

KEYCODE_V

51

KEYCODE_W

52

KEYCODE_X

53

KEYCODE_Y

54

KEYCODE_Z

55

KEYCODE_COMMA

56

KEYCODE_PERIOD

Conclusion

The above trick will help you if you have broken the hardware keys of your device. Don’t forget to tune in soon when we see how we can map virtual hardware keys on an Android phone even when the hardware keys are broken.

Last updated on 03 February, 2022

The above article may contain affiliate links which help support Guiding Tech. However, it does not affect our editorial integrity. The content remains unbiased and authentic.