getevent-sendevent


Namegetevent-sendevent JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/getevent_sendevent
SummaryConverts getevent (ADB) into sendevent/binary, output can be saved, loaded and executed. Execution speed can be defined.
upload_time2022-11-25 04:19:52
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords bluestacks adb touch tap getevent sendevent
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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://github.com/hansalemaos/screenshots/raw/main/bluestacksauto.png)](https://www.youtube.com/watch?v=BNDtruH6frI)

[https://www.youtube.com/watch?v=BNDtruH6frI]()

```python

$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                   

....

```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/getevent_sendevent",
    "name": "getevent-sendevent",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "bluestacks,adb,touch,tap,getevent,sendevent",
    "author": "Johannes Fischer",
    "author_email": "<aulasparticularesdealemaosp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/25/12/fcfb6d5b4547bc6cb30aeb956a38e259ae2da57a804fa9285b33d0590174/getevent_sendevent-0.10.tar.gz",
    "platform": null,
    "description": "\n# Sending touch/swipe events to BlueStacks/Android sounds easy but actually it isn't \n\n\n\n\n\n### There are some \"common ways\"\n\n\n\n##### 1st way:\n\n\n\nThe standard version on a not rooted system is:\n\n**adb shell input tap x y**\n\nUnfortunately, this method is very slow and unreliable since it calls the Java layer of the android framework:\n\n[https://stackoverflow.com/a/38806872/15096247]()\n\n\n\n##### 2nd way:\n\n\n\nIf your cell phone / BlueStacks instance is rooted, you can use: \n\n**adb shell sendevent /dev/input/event2 3 0 x**\n\n**adb shell sendevent /dev/input/event2 3 1 y**\n\n**adb shell sendevent /dev/input/event2 1 330 1**\n\n**adb shell sendevent /dev/input/event2 0 0 0**\n\n**adb shell sendevent /dev/input/event2 1 330 0**\n\n**adb shell sendevent /dev/input/event2 0 0 0**\n\n\n\nThis method is a lot better than \"input tap\" since it is more reliable and slightly faster.\n\nBut when you use \"sendevent\" like in the example above, you won't even get a decent swipe, because\n\nthe break between the ADB shell calls just takes too long. \n\n\n\nEven using: \n\n**adb shell \"sendevent1 ; sendevent2 ; sendevent3 ; \u2026\"**\n\ndoesn\u2019t improve the executing speed much.\n\n\n\n##### 3rd way:\n\n\n\nIf your cell phone / BlueStacks instance is rooted, you can also use: \n\n\n\n**adb shell dd bs=filesize_in_bytes  if=./file of=/dev/input/eventX**\n\n\n\nThis method is very reliable and very very very fast\u2026 unfortunately too fast for the Android touch screen. \n\n\n\n## sendevent-getevent aims to offer a solution for the execution speed problem.\n\n\n\n### Features: \n\n\n\n\n\n- You can record getevents directly from python, once you are done you press the hotkey (default=\u201cctrl+x\u201d) to exit the recording session. \n\n- It converts the output into all possible formats: hex - int - sendevent with int - binary data and returns a Pandas DataFrame\n\n- You can define the playback speed of the recorded session (speed 4 is about close to the \"original speed\")\n\n- You can change the playback speed afterwards\n\n- It is possible to save/load recorded sessions\n\n- You can manually change the DataFrame\n\n- 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\n\n\n\n\n\n### Tested against Windows 10 / Python 3.9.13 / BlueStacks 5\n\n\n\nIt should also work with any rooted Android device, the only problem might be the \"bluestacks_divider\".\n\n[https://stackoverflow.com/a/73733261/15096247]()\n\n\n\nBut changing the code (if necessary) shouldn't be a big thing. \n\nSince 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)\n\n\n\nTake a look at the video to see what the code below does:\n\n[![YT](https://github.com/hansalemaos/screenshots/raw/main/bluestacksauto.png)](https://www.youtube.com/watch?v=BNDtruH6frI)\n\n[https://www.youtube.com/watch?v=BNDtruH6frI]()\n\n```python\n\n$pip install getevent-sendevent\n\n\n\nfrom getevent_sendevent import GetEventSendEvent\n\nimport pandas as pd\n\n\n\n# creating an instance \n\ngetsend = GetEventSendEvent(\n\n    adb_path=\"C:\\\\Users\\\\Gamer\\\\AppData\\\\Local\\\\Android\\\\Sdk\\\\platform-tools\\\\adb.exe\",\n\n    deviceserial=\"localhost:5735\",\n\n    sdcard=\"/storage/emulated/0/\",  # it is probably better to pass the path, not the symlink\n\n    temfolder_on_sd_card=\"AUTOMAT\", # if the folder doesn't exist, it will be created\n\n    bluestacks_divider=32767,\n\n    exit_keys=\"ctrl+x\", # stop the recording session\n\n)\n\n\n\n# connect to adb\n\ngetsend.connect_to_adb()\n\n\n\n# start a recording session \n\ndf = getsend.record_events_and_convert_to_df(playbackspeed=3)\n\n\n\n# execute the recorded command\n\ngetsend.execute_recorded_events(\n\n    df,\n\n    structfolder=\"struct\",\n\n    additional_end_command=True,\n\n    remove_temp_files_from_device=False,\n\n)\n\n\n\n# increasing the execution speed\n\ndf_fast=pd.DataFrame()\n\nfor speed_ in range(4,16):\n\n    df_fast = getsend.change_playback_speed(df, playback_speed=speed_)\n\n    getsend.execute_recorded_events(\n\n        df_fast,\n\n        structfolder=\"struct\",\n\n        additional_end_command=True,\n\n        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\n\n    )\n\n\n\n\n\n# executing the same command over and over again without creating a new DataFrame\n\nfor speed_ in range(4,16):\n\n    getsend.execute_recorded_events(\n\n        df_fast,\n\n        structfolder=\"struct\", # binary data\n\n        additional_end_command=True,\n\n        remove_temp_files_from_device=False,\n\n    )\n\n\n\n\n\n# Saving the recorded session \n\ngetsend.save_recorded_data_on_hdd(df, path=\"f:\\\\testfoldersendevent\\\\saveddata.txt\")\n\n\n\n# Loading it again and redefine the playback speed\n\ndfloaded = getsend.load_recoded_data(\n\n    path=\"f:\\\\testfoldersendevent\\\\saveddata.txt\", playback_speed=16\n\n)\n\n\n\n# Executing the loaded session\n\ngetsend.execute_recorded_events(\n\n    dfloaded,\n\n    structfolder=\"struct\",\n\n    additional_end_command=True,\n\n    remove_temp_files_from_device=False,\n\n)\n\n\n\nHere is the DataFrame:\n\n\n\n     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\n\n0  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                   \n\n1  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                   \n\n2  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                   \n\n3  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                   \n\n4  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                   \n\n5  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                   \n\n....\n\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Converts getevent (ADB) into sendevent/binary, output can be saved, loaded and executed. Execution speed can be defined.",
    "version": "0.10",
    "split_keywords": [
        "bluestacks",
        "adb",
        "touch",
        "tap",
        "getevent",
        "sendevent"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ef145190c646733422bc66603650520285d8ee7b46500033087e044bef0a4d29",
                "md5": "2ab3aee26aa7701097d8c115f59b7875",
                "sha256": "d65261002db9eca31f2ed566222f2d8cfaa53a555627e95120629fa18f2fc7d2"
            },
            "downloads": -1,
            "filename": "getevent_sendevent-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2ab3aee26aa7701097d8c115f59b7875",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 20578,
            "upload_time": "2022-11-25T04:19:50",
            "upload_time_iso_8601": "2022-11-25T04:19:50.021039Z",
            "url": "https://files.pythonhosted.org/packages/ef/14/5190c646733422bc66603650520285d8ee7b46500033087e044bef0a4d29/getevent_sendevent-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2512fcfb6d5b4547bc6cb30aeb956a38e259ae2da57a804fa9285b33d0590174",
                "md5": "53cc8642b5b197cbbcf89a8ca43d6530",
                "sha256": "22275fbd2fa174e6d0e0cc5badd1d0a5b42fb24b6ef65afcae19b276ff91f73f"
            },
            "downloads": -1,
            "filename": "getevent_sendevent-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "53cc8642b5b197cbbcf89a8ca43d6530",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 20259,
            "upload_time": "2022-11-25T04:19:52",
            "upload_time_iso_8601": "2022-11-25T04:19:52.186578Z",
            "url": "https://files.pythonhosted.org/packages/25/12/fcfb6d5b4547bc6cb30aeb956a38e259ae2da57a804fa9285b33d0590174/getevent_sendevent-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-11-25 04:19:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hansalemaos",
    "github_project": "getevent_sendevent",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "getevent-sendevent"
}
        
Elapsed time: 0.05431s