{"id":17128326,"url":"https://github.com/cartucho/android-touch-record-replay","last_synced_at":"2025-04-07T15:08:30.371Z","repository":{"id":41067026,"uuid":"146739293","full_name":"Cartucho/android-touch-record-replay","owner":"Cartucho","description":"How to record and replay touchscreen events on an Android device.","archived":false,"fork":false,"pushed_at":"2023-06-08T17:31:17.000Z","size":1364,"stargazers_count":243,"open_issues_count":15,"forks_count":51,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-31T12:09:02.587Z","etag":null,"topics":["android","automation"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cartucho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-30T11:22:26.000Z","updated_at":"2025-03-23T00:18:10.000Z","dependencies_parsed_at":"2024-10-31T14:03:21.397Z","dependency_job_id":"7134acf5-d1bd-4a72-8866-a67a8c10ea55","html_url":"https://github.com/Cartucho/android-touch-record-replay","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cartucho%2Fandroid-touch-record-replay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cartucho%2Fandroid-touch-record-replay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cartucho%2Fandroid-touch-record-replay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cartucho%2Fandroid-touch-record-replay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cartucho","download_url":"https://codeload.github.com/Cartucho/android-touch-record-replay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","automation"],"created_at":"2024-10-14T19:06:46.334Z","updated_at":"2025-04-07T15:08:30.343Z","avatar_url":"https://github.com/Cartucho.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Record and Replay Touchscreen Events on Android\n\n[![GitHub stars](https://img.shields.io/github/stars/Cartucho/android-touch-record-replay.svg?style=social\u0026label=Stars)](https://github.com/Cartucho/android-touch-record-replay)\n\nHow to record and replay touchscreen events on an Android device.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/15831541/44855448-f4e1a080-ac62-11e8-8b7d-4e48cc80a269.gif\"/\u003e\n\u003c/p\u003e\n\n\n## Table of contents\n\n- [Prerequisites](#prerequisites)\n- [Quick start](#quick-start)\n- [Easy method](#easy-method)\n- [Step-by-step method and Explanation](#step-by-step-method-and-explanation)\n- [Outputting Data](#output-data-to-csv)\n- [Authors](#authors)\n\n## Prerequisites\n\nYou need to:\n\n- Install ADB in your computer (`sudo apt install adb`)\n- Enable `USB Debugging` in your Android device (`Settings \u003e Developer Options \u003e USB Debugging`)\n\nNow, connect your device to your computer, via a USB cable, and run the following bash script in a terminal:\n\n    ./find_touchscreen_name.sh\n\nif you get the output message `\"Touchscreen device found!\"`, then you can use the [Easy method](#easy-method). Otherwise, you need to use the [Step-by-step method](#step-by-step-method-and-explanation).\n\nOptional:\n\n- It is easier for you to visualize where you touched the screen by turning one of the following (1) `Show touches` or (2) `Pointer location` (In your phone go to `Settings \u003e Developer Options \u003e Input \u003e Show touches`)\n\n\n## Quick start\nTo start using the mAP you need to clone the repo:\n\n```\ngit clone https://github.com/Cartucho/android-touch-record-replay\n```\n\n## Easy method\n\n1. Record touch events with timestamps:\n\n    `./record_touch_events.sh`\n\n2. Replay those touch event:\n\n    `./replay_touch_events.sh`\n\n## Step-by-step method and Explanation\n\nAndroid uses the Linux kernel so it processes input events the same way as any other Linux system.\nWith the android's [getevent](https://source.android.com/devices/input/getevent) tool we can record the live dump of kernel input events and use that recording to replay the same touch events.\n\n1. Connect your phone via a USB cable to your computer.\n2. Find out the name of the touchscreen's device (should look something like `/dev/input/event\u003cyour_index\u003e`). There a couple of ways of doing this:\n    - Use the command `adb shell getevent -lp` and figure out which of the input devices contains events with the `ABS_MT_TOUCH_MAJOR` textual label;\n    - Another option is to try the command `adb shell getevent | grep event\u003cyour_index\u003e` with the different possible values for `\u003cyour_index\u003e` until you see that the terminal is printing events exactly when you move your finger over the phone's touchscreen.\n\nIn my case, my touchscreen's name is `/dev/input/event7` which I will be using from now forward. Don't forget to change this in the following step's commands!\n\n3. Using the touchscreen's device name we can now record events using the command `adb shell getevent -t /dev/input/event7 \u003e recorded_touch_events.txt`. Using the `-t` option we also record the timestamps (so that later we can replay the recorded input with the proper delay between events). The content on this file should look something like:\n\n        ...\n        [   53890.813990] 0000 0000 00000000\n        [   53890.828065] 0003 0035 000001be\n        [   53890.828065] 0003 0036 00000258\n        [   53890.828065] 0003 0030 0000001f\n        [   53890.828065] 0003 0032 0000001f\n        [   53890.828065] 0003 0039 00000000\n        ...\n\n    , where each line represents an event's `[   timestamp] type code value`.\n\n4. We now push those recorded events into the phone using the command `adb push recorded_touch_events.txt /sdcard/`\n\n5. In order to replay those events we will use the `mysendevent` executable, which will read the `recorded_touch_events.txt` file line by line and inject those events in the kernel input. To do this we need to push this executable to the phone by using the following command `adb push mysendevent /data/local/tmp/`\n\n    Note: In case you want to modify the file `mysendevent.c` you have to recompile it (for android, e.g., use `arm-linux-gnueabi-gcc -static -march=armv7-a mysendevent.c -o mysendevent`) and re-push `mysendevent` to the phone.\n\n6. Finally, we can replay the previous recording by running the command `adb shell /data/local/tmp/mysendevent /dev/input/event7 /sdcard/recorded_touch_events.txt`\n\n## Outputting Touch Data\n\nYou may want to export and anyalse the touch screen data.\n\nAs mentioned in the previous section the touch data is in the following format\n\n| Timestamp         | Type | Code | Value    |\n| ----------------- | ---- | ---- | -------- |\n| [   53890.813990] | 0000 | 0000 | 000005b0 |\n| [   53890.828065] | 0003 | 0035 | 000001be |\n| [   53890.828065] | 0003 | 0036 | 00000258 |\n| [   53890.828065] | 0003 | 0030 | 0000001f |\n| [   53890.828065] | 0003 | 0032 | 0000001f |\n| [   53890.828065] | 0003 | 0039 | 00000000 |\n\n### Timestamp\n\nAccording to the [android documentation](https://source.android.com/devices/input/getevent) the timestamp data is in the following format:\n\n\u003e getevent timestamps use the format $SECONDS.$MICROSECONDS in the CLOCK_MONOTONIC timebase.\n\n[CLOCK_REALTIME vs. CLOCK_MONOTONIC](https://stackoverflow.com/questions/3523442/difference-between-clock-realtime-and-clock-monotonic)\n\nThis dataformat is not ideal as it is relative to an arbitrary time in the system.\n\nWe will not use this data in our data collection script.\n\n### Type \u0026 Code\n\nCurrently we have output these as their codes, we can use the `-l` argument to output these codes as descriptive labels.\n\nFor example:\n\n`adb shell getevent -lt /dev/input/event7 \u003e recorded_touch_events.txt`\n\nwould now output:\n\n| Timestamp         | Type   | Code               | Value    |\n| ----------------- | ------ | ------------------ | -------- |\n| [   46112.124651] | EV_ABS | ABS_MT_TRACKING_ID | 000005b0 |\n| [   46112.124651] | EV_ABS | ABS_MT_POSITION_X  | 0000010f |\n| [   46112.124651] | EV_ABS | ABS_MT_POSITION_Y  | 00000479 |\n| [   46112.124651] | EV_ABS | ABS_MT_PRESSURE    | 0000005f |\n| [   46112.124651] | EV_ABS | ABS_MT_TOUCH_MAJOR | 0000005f |\n| [   46112.124651] | EV_SYN | SYN_REPORT         | 00000000 |\n| [   46112.173948] | EV_SYN | 0004               | 0000b420 |\n| [   46112.173948] | EV_SYN | 0005               | 0a5db877 |\n\n### Value\n\nThe value is currently being output as hexadecimal. We will convert the value into an integer when we collect the data in our script later.\n\nThe following command will display the `min` and `max` values for each input:\n\n`adb shell getevent -lp /dev/input/event7`\n\n```\n  name:     \"Melfas MMSxxx Touchscreen\"\n  events:\n    ABS (0003): ABS_MT_SLOT           : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0\n                ABS_MT_TOUCH_MAJOR    : value 0, min 0, max 30, fuzz 0, flat 0, resolution 0\n                ABS_MT_POSITION_X     : value 0, min 0, max 720, fuzz 0, flat 0, resolution 0\n                ABS_MT_POSITION_Y     : value 0, min 0, max 1280, fuzz 0, flat 0, resolution 0\n                ABS_MT_TRACKING_ID    : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0\n                ABS_MT_PRESSURE       : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0\n  input props:\n    INPUT_PROP_DIRECT\n```\n\n### Output data to CSV\n\nThe `human_readable_data.py` script will convert all of the touch data into a more readable format and output it to a csv file.\n\n**Usage:** `python human_readable_data.py arg1 arg2`\n\n| Argument | Value               | Example                             |\n| -------- | ------------------- | ----------------------------------- |\n| arg1     | touchscreen device  | /dev/input/event7                   |\n| arg2     | csv output location | /Users/$user/Desktop/touch_info.csv |\n\nThis will create a csv file containing the following information:\n\n| **Timestamp**                  | **Type** | **Code**           | **Value** |\n| ------------------------------ | -------- | ------------------ | --------- |\n| **2019-02-13 10:30:41.558271** | EV_ABS   | ABS_MT_TRACKING_ID | 1804      |\n| **2019-02-13 10:30:41.558557** | EV_ABS   | ABS_MT_POSITION_X  | 805       |\n| **2019-02-13 10:30:41.558797** | EV_ABS   | ABS_MT_POSITION_Y  | 848       |\n| **2019-02-13 10:30:41.559035** | EV_ABS   | ABS_MT_PRESSURE    | 51        |\n| **2019-02-13 10:30:41.559245** | EV_ABS   | ABS_MT_TOUCH_MAJOR | 51        |\n| **2019-02-13 10:30:41.559453** | EV_SYN   | SYN_REPORT         | 0         |\n| **2019-02-13 10:30:41.697711** | EV_SYN   | 4                  | 66179     |\n| **2019-02-13 10:30:41.701748** | EV_SYN   | 5                  | 233329954 |\n\n## Authors:\n\n* **João Cartucho**\n\n    Feel free to contribute\n\n    [![GitHub contributors](https://img.shields.io/github/contributors/Cartucho/android-touch-record-replay.svg)](https://github.com/Cartucho/android-touch-record-replay/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcartucho%2Fandroid-touch-record-replay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcartucho%2Fandroid-touch-record-replay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcartucho%2Fandroid-touch-record-replay/lists"}