# Send touch/longtouch events to BlueStacks/Android
```python
$pip install sendevent-touch
from sendevent_touch import SendEventTouch
sendtouch = SendEventTouch(
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
tmp_folder_on_sd_card="AUTOMAT", # if the folder doesn't exist, it will be created
bluestacks_divider=32767,
use_bluestacks_coordinates=True, # Recalculates the BlueStacks coordinates https://stackoverflow.com/a/73733261/15096247
)
sendtouch.connect_to_adb()
# Useful if you want to repeat the click
df_click1 = sendtouch.get_dataframe_for_clicks(50, 50)
sendtouch.touch_df(
df_click1, struct_folder="struct real"
) # "struct real" will use the recalculated coordinates for BlueStacks
# Touching without returning a DataFrame
sendtouch.touch(520, 40, struct_folder="struct real")
# Same thing for longtouch, duration is in seconds
sendtouch.longtouch_df(df_click1, duration=2.5, struct_folder="struct real")
sendtouch.longtouch(520, 40, duration=3.1, struct_folder="struct real")
# Using struct_folder="struct" should work for any rooted Android device, but I haven't checked it!
# I would be grateful for any feedback!
df_click1 = sendtouch.get_dataframe_for_clicks(50, 50)
sendtouch.touch_df(df_click1, struct_folder="struct")
sendtouch.touch(520, 40, struct_folder="struct")
sendtouch.longtouch_df(df_click1, duration=2, struct_folder="struct")
sendtouch.longtouch(520, 40, duration=3, struct_folder="struct")
#%timeit sendtouch.touch_df(df_click1 ,struct_folder="struct real")
# 109 ms ± 4.62 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
#%timeit subprocess.run('adb shell input tap 50 50')
# 197 ms ± 1.54 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
```
### 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 the module against a physical Android device. (I would be grateful for any feedback)
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/sendevent_touch",
"name": "sendevent-touch",
"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/10/c7/f903484225d96c4e986c05d0d6ecf731b1468a01d5312d007a0e061d1815/sendevent_touch-0.11.tar.gz",
"platform": null,
"description": "\n# Send touch/longtouch events to BlueStacks/Android\n\n\n\n\n\n```python\n\n$pip install sendevent-touch\n\n\n\nfrom sendevent_touch import SendEventTouch\n\n\n\nsendtouch = SendEventTouch(\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 tmp_folder_on_sd_card=\"AUTOMAT\", # if the folder doesn't exist, it will be created\n\n bluestacks_divider=32767,\n\n use_bluestacks_coordinates=True, # Recalculates the BlueStacks coordinates https://stackoverflow.com/a/73733261/15096247\n\n)\n\n\n\nsendtouch.connect_to_adb()\n\n\n\n# Useful if you want to repeat the click\n\ndf_click1 = sendtouch.get_dataframe_for_clicks(50, 50)\n\nsendtouch.touch_df(\n\n df_click1, struct_folder=\"struct real\"\n\n) # \"struct real\" will use the recalculated coordinates for BlueStacks\n\n\n\n\n\n# Touching without returning a DataFrame\n\nsendtouch.touch(520, 40, struct_folder=\"struct real\")\n\n\n\n\n\n# Same thing for longtouch, duration is in seconds\n\nsendtouch.longtouch_df(df_click1, duration=2.5, struct_folder=\"struct real\")\n\nsendtouch.longtouch(520, 40, duration=3.1, struct_folder=\"struct real\")\n\n\n\n\n\n# Using struct_folder=\"struct\" should work for any rooted Android device, but I haven't checked it!\n\n# I would be grateful for any feedback!\n\ndf_click1 = sendtouch.get_dataframe_for_clicks(50, 50)\n\nsendtouch.touch_df(df_click1, struct_folder=\"struct\")\n\nsendtouch.touch(520, 40, struct_folder=\"struct\")\n\n\n\n\n\nsendtouch.longtouch_df(df_click1, duration=2, struct_folder=\"struct\")\n\nsendtouch.longtouch(520, 40, duration=3, struct_folder=\"struct\")\n\n\n\n#%timeit sendtouch.touch_df(df_click1 ,struct_folder=\"struct real\")\n\n# 109 ms \u00b1 4.62 ms per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\n\n#%timeit subprocess.run('adb shell input tap 50 50')\n\n# 197 ms \u00b1 1.54 ms per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\n\n\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 the module against a physical Android device. (I would be grateful for any feedback)\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Sendevents for faster / more reliable touch/longtouch events when using ADB",
"version": "0.11",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/sendevent_touch"
},
"split_keywords": [
"bluestacks",
"adb",
"touch",
"tap",
"getevent",
"sendevent"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3ce3ebc51399cf69ab4a1ca7a651c316eb843767b4552eb8eb8dd386f350faba",
"md5": "33b4ba1a15a8fac11de515242c23389a",
"sha256": "7536f1e103e136bccc16972931becc4713e1183e0504f69bf02141242e03e6ee"
},
"downloads": -1,
"filename": "sendevent_touch-0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "33b4ba1a15a8fac11de515242c23389a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 9425,
"upload_time": "2022-11-25T06:05:13",
"upload_time_iso_8601": "2022-11-25T06:05:13.652369Z",
"url": "https://files.pythonhosted.org/packages/3c/e3/ebc51399cf69ab4a1ca7a651c316eb843767b4552eb8eb8dd386f350faba/sendevent_touch-0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "10c7f903484225d96c4e986c05d0d6ecf731b1468a01d5312d007a0e061d1815",
"md5": "4fc4035108ae6bedc9b08eecaed1ec65",
"sha256": "2a53e909903b197133b1abc8f3a1b0b0603a70406c487d309cf136d3cbe93cea"
},
"downloads": -1,
"filename": "sendevent_touch-0.11.tar.gz",
"has_sig": false,
"md5_digest": "4fc4035108ae6bedc9b08eecaed1ec65",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8046,
"upload_time": "2022-11-25T06:05:14",
"upload_time_iso_8601": "2022-11-25T06:05:14.865929Z",
"url": "https://files.pythonhosted.org/packages/10/c7/f903484225d96c4e986c05d0d6ecf731b1468a01d5312d007a0e061d1815/sendevent_touch-0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-11-25 06:05:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "sendevent_touch",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "sendevent-touch"
}