Call of Duty mobile keymapper using adb

Hello there. Recently, my friends and I reinstall call of duty mobile back. Unfortunately, I am bad at playing games on mobile phone. Playing a fps game with only two thumb is literally a disaster to me. Before that, I was playing codm on Bluestack emulator. But now, 69% of my disk space is used by installing Genshin Impact and there is no enough space to install emulator.

To overcome this problem, I came up two solution , learn four finger control and develop a keymapper. At first, I watch some tutorial video about four finger control and practice about it. However, after some trying about four finger control, I gave up and decided to develop a keymapper.

What is the requirement of keymapper

To make a prefect keymapper for codm, I make a list of requirement that keymapper must achieve.

  • low latency (~15ms)
  • able to preform most of the control in codm
  • low cpu usage on phone side
  • high percision of mouse movement

How the keymapper works

The keymapper is made up of two side, a Java server on phone and a C++ client on PC. The connection between them is entablished using ADB(Android Debug Bridge) USB forwarding.

Problem encountered

How to run background program on Android

To develop a program on Android, I install a Android SDK (not Android Studio) and create an incomplete app using gradle. The reason for me to create an incomplete app is because it give me access to Android api without GUI. To run it, using normal method to start is not compatible. We need to use ADB (Android Debug Bridge) to start a shell and directly execute its apk file using app_process command.

How keymapper simulate touch event

At first, I try to write directly to /dev/event0 because it is the easiest and fastest method. Unfortunately, this method require root access of Android phone. Luckily, there is an open source Android mirror software, scrcpy has method to simulate touch event without root access. To understand how it works, I prefer you to read its code because I am not familiar with Java and has no idea about its principle.

I will explain the development in next blog