Skip to main content

Converts getevent (ADB) into sendevent/binary, output can be saved, loaded and executed. Execution speed can be defined.

Project description

Sending touch/swipe events to BlueStacks/Android sounds easy but actually it isn't

There are some "common ways"

1st way:

The standard version on a not rooted system is:

adb shell input tap x y

Unfortunately, this method is very slow and unreliable since it calls the Java layer of the android framework:

https://stackoverflow.com/a/38806872/15096247

2nd way:

If your cell phone / BlueStacks instance is rooted, you can use:

adb shell sendevent /dev/input/event2 3 0 x

adb shell sendevent /dev/input/event2 3 1 y

adb shell sendevent /dev/input/event2 1 330 1

adb shell sendevent /dev/input/event2 0 0 0

adb shell sendevent /dev/input/event2 1 330 0

adb shell sendevent /dev/input/event2 0 0 0

This method is a lot better than "input tap" since it is more reliable and slightly faster.

But when you use "sendevent" like in the example above, you won't even get a decent swipe, because

the break between the ADB shell calls just takes too long.

Even using:

adb shell "sendevent1 ; sendevent2 ; sendevent3 ; …"

doesn’t improve the executing speed much.

3rd way:

If your cell phone / BlueStacks instance is rooted, you can also use:

adb shell dd bs=filesize_in_bytes if=./file of=/dev/input/eventX

This method is very reliable and very very very fast… unfortunately too fast for the Android touch screen.

sendevent-getevent aims to offer a solution for the execution speed problem.

Features:

  • You can record getevents directly from python, once you are done you press the hotkey (default=“ctrl+x”) to exit the recording session.

  • It converts the output into all possible formats: hex - int - sendevent with int - binary data and returns a Pandas DataFrame

  • You can define the playback speed of the recorded session (speed 4 is about close to the "original speed")

  • You can change the playback speed afterwards

  • It is possible to save/load recorded sessions

  • You can manually change the DataFrame

  • It sends chunked data to the device/emulator using adb shell dd bs=filesize_in_bytes if=./file of=/dev/input/eventX , and sleeps after each chunk

Tested against Windows 10 / Python 3.9.13 / BlueStacks 5

It should also work with any rooted Android device, the only problem might be the "bluestacks_divider".

https://stackoverflow.com/a/73733261/15096247

But changing the code (if necessary) shouldn't be a big thing.

Since my cell phone is not rooted, and I have no intention of rooting it, I cannot test it with an physical Android device. (I would be grateful for any feedback)

Take a look at the video to see what the code below does:

YT

https://www.youtube.com/watch?v=BNDtruH6frI

$pip install getevent-sendevent



from getevent_sendevent import GetEventSendEvent

import pandas as pd



# creating an instance 

getsend = GetEventSendEvent(

    adb_path="C:\\Users\\Gamer\\AppData\\Local\\Android\\Sdk\\platform-tools\\adb.exe",

    deviceserial="localhost:5735",

    sdcard="/storage/emulated/0/",  # it is probably better to pass the path, not the symlink

    temfolder_on_sd_card="AUTOMAT", # if the folder doesn't exist, it will be created

    bluestacks_divider=32767,

    exit_keys="ctrl+x", # stop the recording session

)



# connect to adb

getsend.connect_to_adb()



# start a recording session 

df = getsend.record_events_and_convert_to_df(playbackspeed=3)



# execute the recorded command

getsend.execute_recorded_events(

    df,

    structfolder="struct",

    additional_end_command=True,

    remove_temp_files_from_device=False,

)



# increasing the execution speed

df_fast=pd.DataFrame()

for speed_ in range(4,16):

    df_fast = getsend.change_playback_speed(df, playback_speed=speed_)

    getsend.execute_recorded_events(

        df_fast,

        structfolder="struct",

        additional_end_command=True,

        remove_temp_files_from_device=False, # Repeated execution will be faster, but you should clean the folder /storage/emulated/0/AUTOMAT every once in a while

    )





# executing the same command over and over again without creating a new DataFrame

for speed_ in range(4,16):

    getsend.execute_recorded_events(

        df_fast,

        structfolder="struct", # binary data

        additional_end_command=True,

        remove_temp_files_from_device=False,

    )





# Saving the recorded session 

getsend.save_recorded_data_on_hdd(df, path="f:\\testfoldersendevent\\saveddata.txt")



# Loading it again and redefine the playback speed

dfloaded = getsend.load_recoded_data(

    path="f:\\testfoldersendevent\\saveddata.txt", playback_speed=16

)



# Executing the loaded session

getsend.execute_recorded_events(

    dfloaded,

    structfolder="struct",

    additional_end_command=True,

    remove_temp_files_from_device=False,

)



Here is the DataFrame:



     aa_time  aa_device aa_type    aa_code  aa_value aa_device_name  aa_value_int aa_code_int aa_type_int  aa_time_difference_start  aa_time_diff_actions  aa_real_coords aa_send_event aa_send_event_real_ccords  aa_time_new  aa_struct aa_struct_real  aa_struct_size  aa_struct_real_size aa_struct_together aa_struct_real_together struct_tmp_hdd_full_path struct_tmp_hdd struct_tmp_folder struct_filename struct_real_tmp_hdd_full_path struct_real_tmp_hdd struct_real_tmp_folder struct_real_filename struct_copy_dv struct_real_copy_dv  random_sleep aa_copy_struct_to_hdd aa_copy_struct_real_to_hdd struct_folder_android struct_real_folder_android struct_file_android struct_real_file_android aa_copy_struct_to_hdd_success

0  30922....  /dev/i...  EV_ABS  ABS_MT...  0000769f  BlueSt...          30367            53           3         0.0                       0.0                   889       sendev...     sendev...                         1    b'\x01...  b'\x03...            352             352            b'\x01...          b'\x03...               C:\Use...                C:\Use...      tmpcgn...         struct...       C:\Use...                     C:\Use...           tmpqeh...              struct...            dd bs=...      dd bs=...                 0.0     __main...             __main...                  /stora...             /stora...                  /stora...           /stora...                     True                   

1  30922....  /dev/i...  EV_ABS  ABS_MT...  00005974  BlueSt...          22900            54           3         0.0                       0.0                   377       sendev...     sendev...                         1    b'\x01...  b'\x03...            352             352                 <NA>               <NA>               C:\Use...                     <NA>      tmpcgn...              None       C:\Use...                          <NA>           tmpqeh...                   None                 <NA>           <NA>                 0.0           NaN                   NaN                  /stora...             /stora...                        NaN                 NaN                      NaN                   

2  30922....  /dev/i...  EV_SYN  SYN_MT...  00000000  BlueSt...              0             2           0         0.0                       0.0                     0       sendev...     sendev...                         1    b'\x01...  b'\x03...            352             352                 <NA>               <NA>               C:\Use...                     <NA>      tmpcgn...              None       C:\Use...                          <NA>           tmpqeh...                   None                 <NA>           <NA>                 0.0           NaN                   NaN                  /stora...             /stora...                        NaN                 NaN                      NaN                   

3  30922....  /dev/i...  EV_SYN  SYN_RE...  00000000  BlueSt...              0             0           0         0.0                  0.012315                     0       sendev...     sendev...                         1    b'\x01...  b'\x03...            352             352                 <NA>               <NA>               C:\Use...                     <NA>      tmpcgn...              None       C:\Use...                          <NA>           tmpqeh...                   None                 <NA>           <NA>            0.012315           NaN                   NaN                  /stora...             /stora...                        NaN                 NaN                      NaN                   

4  30922....  /dev/i...  EV_ABS  ABS_MT...  0000769f  BlueSt...          30367            53           3    0.012315                       0.0                   889       sendev...     sendev...                         1    b'\x01...  b'\x03...            352             352                 <NA>               <NA>               C:\Use...                     <NA>      tmpcgn...              None       C:\Use...                          <NA>           tmpqeh...                   None                 <NA>           <NA>                 0.0           NaN                   NaN                  /stora...             /stora...                        NaN                 NaN                      NaN                   

5  30922....  /dev/i...  EV_ABS  ABS_MT...  00005974  BlueSt...          22900            54           3    0.012315                       0.0                   377       sendev...     sendev...                         1    b'\x01...  b'\x03...            352             352                 <NA>               <NA>               C:\Use...                     <NA>      tmpcgn...              None       C:\Use...                          <NA>           tmpqeh...                   None                 <NA>           <NA>                 0.0           NaN                   NaN                  /stora...             /stora...                        NaN                 NaN                      NaN                   

....

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

getevent_sendevent-0.10.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

getevent_sendevent-0.10-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file getevent_sendevent-0.10.tar.gz.

File metadata

  • Download URL: getevent_sendevent-0.10.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for getevent_sendevent-0.10.tar.gz
Algorithm Hash digest
SHA256 22275fbd2fa174e6d0e0cc5badd1d0a5b42fb24b6ef65afcae19b276ff91f73f
MD5 53cc8642b5b197cbbcf89a8ca43d6530
BLAKE2b-256 2512fcfb6d5b4547bc6cb30aeb956a38e259ae2da57a804fa9285b33d0590174

See more details on using hashes here.

File details

Details for the file getevent_sendevent-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for getevent_sendevent-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 d65261002db9eca31f2ed566222f2d8cfaa53a555627e95120629fa18f2fc7d2
MD5 2ab3aee26aa7701097d8c115f59b7875
BLAKE2b-256 ef145190c646733422bc66603650520285d8ee7b46500033087e044bef0a4d29

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page