Issue
I'm going to start off by saying I'm a complete newbie to adb.
That being said, I'm trying to simulate a complex swipe to my android device using adb and python.
I looked everywhere for some sort of documentation or example, but can't find any. I know similar questions has been asked here but none of the answers provide an actual example.
In my program, I do linear swipes with device.shell("input touchscreen swipe 540 1150 750 1250 500")
(using pure-python-adb), and those work perfectly, however I have no idea how to do a swipe that goes from a to b and then from b to c without lifting the "virtual finger".
I found out about sendevent, but I don't understand it at all. All I know is that it takes 4 arguments.
Could someone please tell me exactly how I would produce a swipe from a(200,200) to b(200,300) to c(300,300), for example?
Any help is greatly appreciated. (Note - I'm on Windows 10)
Solution
You can achieve this using the sendevent command. (In the post I explain how it works. If you do not care, you can just use this python file I made. Import the AdbInput class and you are basically done)
1º. Get root access on your adb terminal:
You WILL need to root your phone if you want to use the sendevent command (I will not explain how to root your phone). After rooting it, get into your terminal and, with your phone already connected, write: adb shell su
. A popup should appear on your phone asking for root access. Allow it and now you will see that your shell displays root@[your phone]
instead from ´shell@[your phone]´.
2º. Find the event of your touchscreen.
In the adb terminal (does not matter if its root or not) type ´getevent´ and while its running, touch the screen of your phone. A lot of text and numbers should appear. We are searching for the first part of the messages, in my case: ´/dev/input/event2´ (yours will be pretty similar).
3º. Send the touch events using sendevent.
Now, you will need to replicate the messages gotten from the ´getevent´ command to create a new touchevent. I will paste the commands you need to achieve a swipe going from (200, 200) to (200, 300) and then to (300, 300) and then explain them. (replace ´event~´ by the event gotten in step 2)
device.shell("sendevent /dev/input/event~ 1 330 1")
device.shell("sendevent /dev/input/event~ 3 57 10")
device.shell("sendevent /dev/input/event~ 3 53 200")
device.shell("sendevent /dev/input/event~ 3 54 200")
device.shell("sendevent /dev/input/event~ 0 0 0")
device.shell("sendevent /dev/input/event~ 3 53 200")
device.shell("sendevent /dev/input/event~ 3 54 300")
device.shell("sendevent /dev/input/event~ 0 0 0")
device.shell("sendevent /dev/input/event~ 3 53 300")
device.shell("sendevent /dev/input/event~ 3 54 300")
device.shell("sendevent /dev/input/event~ 0 0 0")
device.shell("sendevent /dev/input/event~ 1 330 0")
device.shell("sendevent /dev/input/event~ 0 0 0")
The first two events "put down a finger" (the first one specifies that the screen has been touched and the second one the pressure of the touch). The third and forth events sets the x and y position of the touch (both at 200, you can change the 200s to experiment). After each group of commands a "0 0 0" is needed. The next two set another swipe point, followed by a "0 0 0". The next one happens in the next three ones. The second to last command "lifts" the finger and the last one is an "0 0 0" event.
So, if you wanted to only tap in (100, 230) you would type the following:
device.shell("sendevent /dev/input/event~ 1 330 1") # Puts down finger
device.shell("sendevent /dev/input/event~ 3 57 10") # Sets pressure
device.shell("sendevent /dev/input/event~ 3 53 100") # Sets X to 100
device.shell("sendevent /dev/input/event~ 3 54 230") # Sets Y to 230
device.shell("sendevent /dev/input/event~ 0 0 0") # "0 0 0" (its called a SYN_REPORT)
device.shell("sendevent /dev/input/event~ 1 330 0") # Lift up finger
device.shell("sendevent /dev/input/event~ 0 0 0") # "0 0 0"
And thats it!! You are done!!
Answered By - Luengor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.