Guys, nowdays, approach in this article is really senseless.
Use: input tap x y
(also input text, swipe, keyevent are available)
adb shell input tap x y
adb shell input swipe x1 y1 x2 y2
adb shell input text Hello!
adb shell input keyevent ID
By this way you do not need to care about hardware implementation. Using events you will have to imeplemnt them for each device. All these commands could be executed on device or on PC via ADB.
Happy testing! (:
To send touch event you need to do:
1 Set coordinates:
adb shell sendevent /dev/input/event2 3 0 x
adb shell sendevent /dev/input/event2 3 1 y
2 Send touch event (must have 0 0 0 pair):adb shell sendevent /dev/input/event2 1 330 1
adb shell sendevent /dev/input/event2 0 0 0
3 Send release finger event (must have 0 0 0 pair):adb shell sendevent /dev/input/event2 1 330 0
adb shell sendevent /dev/input/event2 0 0 0
Please note:1 You can record events:
adb shell getevent
2 if you use getevent all event values are in hex.CONFIRMED, THIS WAY IS NOT WORKING ANYMORE, at least for Android 2.2.
I have rechecked, Android low level events signature was changed starting from Android 2.2 Froyo.
I just dumped single click:
/dev/input/event2: 0003 0030 00000068
/dev/input/event2: 0003 0032 0000000a
/dev/input/event2: 0003 0035 0000022e
/dev/input/event2: 0003 0036 00000039
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0003 0012 0000002f
/dev/input/event2: 0003 0014 00000001
/dev/input/event2: 0000 0000 00000000
/dev/input/event2: 0003 0030 00000000
/dev/input/event2: 0003 0032 0000000a
/dev/input/event2: 0003 0035 0000022e
/dev/input/event2: 0003 0036 00000039
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0003 0012 00000020
/dev/input/event2: 0003 0014 00000000
/dev/input/event2: 0000 0000 00000000
It has obviously another structure.. I'm investigating right now this situation,
solution will be here tomorrow ;)
After a quick investigation I have reproduced the click for Froyo Android:
Perl script (click on screen at 558, 57 point):
system("adb shell sendevent /dev/input/event2 0003 48 104");
system("adb shell sendevent /dev/input/event2 0003 50 10");
system("adb shell sendevent /dev/input/event2 0003 53 558");
system("adb shell sendevent /dev/input/event2 0003 54 57");
system("adb shell sendevent /dev/input/event2 0000 2 00000000");
system("adb shell sendevent /dev/input/event2 0003 18 47");
system("adb shell sendevent /dev/input/event2 0003 20 00000001");
system("adb shell sendevent /dev/input/event2 0000 0000 00000000");
system("adb shell sendevent /dev/input/event2 0003 48 00000000");
system("adb shell sendevent /dev/input/event2 0003 50 10");
system("adb shell sendevent /dev/input/event2 0003 53 558");
system("adb shell sendevent /dev/input/event2 0003 54 57");
system("adb shell sendevent /dev/input/event2 0000 0002 00000000");
system("adb shell sendevent /dev/input/event2 0003 18 32");
system("adb shell sendevent /dev/input/event2 0003 20 00000000");
system("adb shell sendevent /dev/input/event2 0000 0000 00000000");
How I did it:
1. Start dump motion event you need to reproduce:
~$ adb shell getevent | grep event2
grep is very useful to filter output.2. Do motion event you want to reproduce;
3. Than just convert all values from hex in dump to decimal values! :)
To find what eventX is working for you do following:
1. Start terminal and type
~$ adb shell getevent
You will see quickly moving traces with for example /dev/input/event4 ......
2. Touch screen once
You must see between event4 few eventX and these eventX right in the moment of the touch
will be yours input interface for reproducing motion events! :)
Please check my tutorial for low level interaction with device
Happy motion events reproducing! (:
Best regards,
Yahor
When I capture single touch events with getevent | grep event3 I seem to get a different number of events each time I touch the screen(anywhere from about 10-20). I am trying to figure out the code that will simulate a simple touch then release on a specified point. How many sendevent calls should I need to make for this?
ReplyDeleteHello Tim,
ReplyDeleteLets decide, do you want to reproduce single tap?
If true - you can find a minimal set of events for this task in this article for point 558,57.
I just have started investigation and it is very cool that you are interested in my article :)
Answer, why you are getting different number of events:
a) you will never get less set of events, I have listed in the example;
b) you are getting only greater number of events, why? It is simple you are doing a thick touch or little slide/swipe. Because your finger is not 1px : 1 px you can not get always only for 1 point set of events. Here you need to be careful when dumping.
Please let me know if you need some more assistant or if my comment was useful for you :)
Best regards,
Yahor
Also, please take a look to article I have added just 2 minutes ago:
ReplyDeletehttp://softteco.blogspot.com/2011/03/android-writing-events-low-level-touch.html
It describes basics how to use getevents and sendevent.
I will highly appreciate any comment :) If you feel that you need some more info - just specify what you are interested in, and I will added it during launch time ;)
Also, please note on out HTC Desire touch screen is always /dev/input/event2. Pay attention when starting dumping to interfaces description. All of them now have names and ids before events sequence dump begins flushing into your terminal. Touch screen interface should be not producing a single event when you are using grep!
Best regards,
Yahor
thx for the example. this might help someone else:
ReplyDeleteTo record your own script based on your actions, rather than programming:
# convert getevent string to sendevent string
function convert_input()
{
awk '{ \
if (($1 != "") && (substr($0,1,1)=="/"))
{ sub(":","",$1); \
printf("adb shell sendevent %s %d %d %d\n",$1,strtonum("0x"$2),strtonum("0x"$3),strtonum("0x"$4)); \
} }'
}
Example:
adb shell getevent | convert_input > draw_a_circle.sh # draw a circle, or some action, then end data collection by breaking with ctrl-c
chmod +x draw_a_circle.sh # may want to inspect the end of the file because of the arbitrary ctrl-c
draw_a_circle.sh # execute the script once
this runs kind of slow on the host, but running on the target without adb should be faster, just modify the script to remove the adb shell…and it should work.
-PB
Anonymous said...
ReplyDeleteHello, PB,
The way is cool!
But, do you know how to add custom coords into this function?
Best regards,
Yahor
not sure i understand your question. the script is just to record manual actions, and convert the actions to a script. where are you wanting to put in custom coords ?
ReplyDeleteis this what you mean ? if you take your original code, you can do this:
# send a touch event at X Y
function atouchxy()
{
adb shell sendevent /dev/input/event3 0003 48 104
adb shell sendevent /dev/input/event3 0003 50 10
adb shell sendevent /dev/input/event3 0003 53 $1
adb shell sendevent /dev/input/event3 0003 54 $2
adb shell sendevent /dev/input/event3 0000 2 00000000
adb shell sendevent /dev/input/event3 0003 18 47
adb shell sendevent /dev/input/event3 0003 20 00000001
adb shell sendevent /dev/input/event3 0000 0000 00000000
adb shell sendevent /dev/input/event3 0003 48 00000000
adb shell sendevent /dev/input/event3 0003 50 10
adb shell sendevent /dev/input/event3 0003 53 558
adb shell sendevent /dev/input/event3 0003 54 57
adb shell sendevent /dev/input/event3 0000 0002 00000000
adb shell sendevent /dev/input/event3 0003 18 32
adb shell sendevent /dev/input/event3 0003 20 00000000
adb shell sendevent /dev/input/event3 0000 0000 00000000
}
then use that in any script you like
atouchxy 50 600
a problem i'm seeing with all of this is that it runs slowly. even when running a script on the target, playing back a recorded event session is slow because of the sheer number of events that are generated. not really sure what to do about that. for example, try to record a flicking motion, like you were doing a big scroll. then play it back, obviously, if it doesn't play back fast enough, then android won't react with a big scroll.
-PB
Hello, PB,
ReplyDeleteYep, such scripts are more interesting :) But most interesting is to reproduce by this way drag motion event. Do you succeed to reproduce dragging? I have reproduced only short drag via shell script (Like you are preparing 2 fingers, touch screen by left finger, release, immideatelly touch screen by right finger.) Using this approach I'm unlocking the device.
Article with slide function: http://softteco.blogspot.com/2011/03/android-reproducing-swipe-motion-to.html
Please let me know if you have luck to reproduce more complicated motion events!
Respect for recording function! :)
Best regards,
Yahor
Hi,
ReplyDeleteOn my Samsung Galaxy Tab (2.2) the sequence from getevent was shorter (12 lines instead od 16):
// touch screen:
/dev/input/event2: 0003 0035 0000039f // 53
/dev/input/event2: 0003 0036 0000022f // 54
/dev/input/event2: 0003 0030 00000028 //48
/dev/input/event2: 0003 0032 00000001 //50
/dev/input/event2: 0000 0002 00000000 //2
/dev/input/event2: 0000 0000 00000000
//release screen:
/dev/input/event2: 0003 0035 0000039f
/dev/input/event2: 0003 0036 0000022f
/dev/input/event2: 0003 0030 00000000
/dev/input/event2: 0003 0032 00000001
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0000 0000 00000000
I managed to shorten your perl script by removing lines with code equals 18 and 20. This is the result:
sendevent /dev/input/event2 0003 48 104
sendevent /dev/input/event2 0003 50 10
sendevent /dev/input/event2 0003 53 558 // position
sendevent /dev/input/event2 0003 54 57 // position
sendevent /dev/input/event2 0000 2 00000000
sendevent /dev/input/event2 0000 0000 00000000
sendevent /dev/input/event2 0003 48 00000000
sendevent /dev/input/event2 0003 50 10
sendevent /dev/input/event2 0003 53 558 //position
sendevent /dev/input/event2 0003 54 57 //position
sendevent /dev/input/event2 0000 0002 00000000
sendevent /dev/input/event2 0000 0000 00000000
And it works great :) Thank you very much!
can someone tell more detail about how to make and use this file or function 'convert_input()'?
ReplyDeletethank you very much
KJ
Hello Kacper,
ReplyDeleteYou are very welcome, both line are optional and looks like used only for swipe motions.
Convert_input usage was perfectly described by PB:
adb shell getevent | convert_input > draw_a_circle.sh
Best regards,
Yahor
Informative.
ReplyDeleteThanks for such a useful blog.
I wanted to know if we can add delay while sending the commands?
i am capturing events using 'adb shell getevent' and sending the same sequence using 'adb shell sendevent'.
The application time to respond and meanwhile the sequence is lost. Any inputs shall be of great help.
Hello,
ReplyDeleteYou can use: sleep N
where N is timeout in seconds (but you able to specify milliseconds like: N=0.1).
Best regards,
Yahor
hi,
ReplyDeleteI am trying this but it's not working.
this is my output from getevent:
/dev/input/event4: 0003 002b 002c0003
/dev/input/event4: 0003 002a 820301ad
/dev/input/event4: 0003 002b 00120002
/dev/input/event4: 0003 002a 820301ad
/dev/input/event4: 0003 002b 00000000
/dev/input/event4: 0003 002a 80000000
/dev/input/event4: 0003 002b 00250004
/dev/input/event4: 0003 002a 823e01c6
/dev/input/event4: 0003 002b 00190003
/dev/input/event4: 0003 002a 823e01c6
/dev/input/event4: 0003 002b 00000000
/dev/input/event4: 0003 002a 80000000
i convert it to decimal, here is what i put into the terminal:
adb shell sendevent /dev/input/event4 3 42 2883587;
adb shell sendevent /dev/input/event4 3 43 2181235117;
adb shell sendevent /dev/input/event4 3 42 1179650;
adb shell sendevent /dev/input/event4 3 43 2181235117;
adb shell sendevent /dev/input/event4 3 42 0;
adb shell sendevent /dev/input/event4 3 43 2147483648;
adb shell sendevent /dev/input/event4 3 42 2424836;
adb shell sendevent /dev/input/event4 3 43 2185101766;
adb shell sendevent /dev/input/event4 3 42 1638403;
adb shell sendevent /dev/input/event4 3 43 2185101766;
adb shell sendevent /dev/input/event4 3 42 0;
adb shell sendevent /dev/input/event4 3 43 2147483648;
but it doesnt do anything. am i doing something wrong? thanks for any help :)
Dan
Hello Dan,
ReplyDeleteWhat device do you use? Htc?
You have to analyse this output and find how to decode them :)
3 42 0 is 0 0 0 :)
Could you please try to do the following:
1. do a very quick click into 0,0 on your device and save the output;
2. do a very quick click into 0, 100 coord on your device and save the output;
3. do a very quick click into 100, 0 coord on your device and save the output;
Post outputs :) And lets try to find dependencies. I think there have place some binary or hex arithmetic. And coords are multiplied with some constants (flags). We need to find these flags.
To do accurate clicks, you can run Robotium test and adb shell getevent in parallel to catch the output with clicks.
Please let me know if you have any questions, I'm also interested in this issue.
Best regards,
Yahor
update:
ReplyDeleteyou can post only hex output, because decimal output has no sense :)
Best regards,
Yahor
its weird, if i click on the left or right side of the screen, anywhere from top to bottom, this is the output (only along the edge of the screen):
ReplyDelete/dev/input/event4: 0003 002b 00000000
/dev/input/event4: 0003 002a 80000000
/dev/input/event4: 0003 002b 00000000
/dev/input/event4: 0003 002a 80000000
I don't have time now to setup robotium, I will tonight though, the following is the top center of screen:
/dev/input/event4: 0003 002b 001e0003
/dev/input/event4: 0003 002a 82220005
/dev/input/event4: 0003 002b 00160003
/dev/input/event4: 0003 002a 82220005
/dev/input/event4: 0003 002b 00000000
/dev/input/event4: 0003 002a 80000000
then bottom center screen:
/dev/input/event4: 0003 002b 002d0004
/dev/input/event4: 0003 002a 821503bd
/dev/input/event4: 0003 002b 00260004
/dev/input/event4: 0003 002a 821503bd
/dev/input/event4: 0003 002b 00120001
/dev/input/event4: 0003 002a 821503bd
/dev/input/event4: 0003 002b 00000000
/dev/input/event4: 0003 002a 80000000
this is my first attempt at low level programming, thanks for all your help :)
I have the htc droid incredible, rooted custom 2.3.3 rom
Dan
I am having some trouble getting robotium to work correctly. :/
ReplyDeleteI have been working on decoding getevent.
after i take my finger off the screen the last command is always:
0003 002b 00000000
0003 002a 80000000
I can reproduce a click with only 4 lines, so only two lines actually make the click
the first is usually
00**000*
(0's stay the same but the *'s are different numbers, i dont know what they mean though.)
the second line it seems is where the coordinates are set, the first 4 numbers are for x and the last four numbers are for y.
that's all I got for now.
Dan
I got robotium setup but getevent doesn't print/see the clicks.
ReplyDeleteIs there anything else I could try to get more accurate clicks?
Dan
Hello Dan,
ReplyDeleteCould you please try to do the following:
1) adb shell getevent
2) copy all interfaces list event0-N and post them with theirs names, like:
add device 1: /dev/input/event3
name: "kxtf9_accel"
add device 2: /dev/input/event0
name: "gpio-keys"
add device 3: /dev/input/event2
name: "cyttsp-i2c"
add device 4: /dev/input/event1
name: "twl4030-keypad"
I suspect that your event4 interface is an accelerometer :) This is why you are getting the same output for different coords.
You can check it - rotate your device and check if event4 output is changing or not.
If you post interfaces list, I think I can say which of them is Touch screen.
Best regards,
Yahor
add device 1: /dev/input/event9
ReplyDeletename: "compass"
add device 2: /dev/input/event8
name: "curcial-oj"
add device 3: /dev/input/event7
name: "dummy_keypad"
add device 4: /dev/input/event6
name: "lightsensor-level"
add device 5: /dev/input/event5
name: "incrediblec-keypad"
add device 6: /dev/input/event4
name: "atmel-touchscreen"
add device 7: /dev/input/event3
name: "projector-Keypad"
add device 8: /dev/input/event2
name: "projector_input"
add device 9: /dev/input/event1
name: "h2w headset"
add device 10: /dev/input/event0
name: "proximity"
I think it is only the edge of the screen that displays the same coords(it is literally at the very edge of the screen) otherwise it is different coords.
I setup robotium to click at
(0, 0) (0, 100) and (100, 0)
but it said the click failed, I then set it up to click at
(100, 100) (200, 200) and (300, 300)
and it doesn't fail. so it must not be able to click at 0. I can see it clicking on the screen (it clicked on a text field), but getevent running parallel to the test didn't report any clicks.
I recorded a click as follows:
0003 002b 003E0006
0003 002a 828B019F
0003 002b 00000000
0003 002a 80000000
then converted to dec and entered into terminal, I can see it clicking. getevent running parallel also reads these clicks, just not from robotium. Thanks for all your help :)
Dan
this seems to be the basic layout
ReplyDelete0003 002b 00**000*
0003 002a ********
0003 002b 00000000
0003 002a 80000000
the first part (00**000*) is the pressure of the click, the second part (*******) is the actual coords. (xxxxyyyy)
the last two lines only show up after I lift my finger off the screen.
I'm not sure how to decode it to make my own clicks yet but I'm getting closer :)
Dan
Hello Dan,
ReplyDeleteOn my HTC Desire 2.2:
yahor@xeondtp:~$ adb shell getevent | grep event3
add device 7: /dev/input/event3
1) /dev/input/event3: 0003 002b 00260002
2) /dev/input/event3: 0003 002a 88f00e53
3) /dev/input/event3: 0003 002b 00270002
4) /dev/input/event3: 0003 002a 88ea0e6e
5) /dev/input/event3: 0003 002b 00000008
6) /dev/input/event3: 0003 002a 89120eac
7) /dev/input/event3: 0003 002b 00000000
8) /dev/input/event3: 0003 002a 800819a3
I have found that:
X coord: 0e5 at the second (2) line
Y coord: 19a at the last (8) line
I did click in the point: 229; 410
And looks like there are alike coords on X axis, but for Y axis I have found only 19a.
I have tried your "xxxxyyyy" pattern but it seems not work for me :(
Best regards,
Yahor
It must be different for us, by the way I'm on gingerbread(android 2.3.3). Are you on Froyo. Would it be the same for all devices that have the same android versions? Or does it depend on the type of screen you have?
ReplyDeleteI haven't tested pressure yet but here is what I have
pressure on screen(have not tested different numbers yet)
0003 002b 00xx000x
at coordinates
0003 002a xxxxyyyy(from 8009000b to 83f103fb)
lifted finger off screen
0003 002b 00000000
0003 002a 80000000
Thanks again for all your help Yahor :)
Dan
Also there doesn't seem to be any arithmetic on the coords.
ReplyDeleteSo 8009000b would click at (1, 1) and 800a000c would click at (2, 2)
I wasn't thinking earlier, the coordinates above don't seem to depend on pixel width. it seems the hex codes go by one but two different coordinates may click on the same point (according to the phone)
ReplyDeleteAs I said before the left side of the screen is:
8009****
right:
83f1****
My screen width resolution is 600, but the hex codes allow for 1000 different coords.
I'm too tired to figure out how many hex points equal one pixel right now, I'll post back later. :)
Dan
Hi all, thank you for your great tips!
ReplyDeleteI'm trying to emulate key press on samsung galaxy s2 with gingerbread 2.3.5, this is the getevent output: 14 lines
/dev/input/event2: 0003 0035 00000062
/dev/input/event2: 0003 0036 00000179
/dev/input/event2: 0003 0030 0000004c
/dev/input/event2: 0003 0032 00000004
/dev/input/event2: 0003 0039 00000000
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0000 0000 00000000
/dev/input/event7: 0002 0000 00000003
/dev/input/event7: 0002 0001 fffffffb
/dev/input/event7: 0002 0002 fffffd3b
/dev/input/event7: 0000 0000 00000000
/dev/input/event2: 0003 0035 00000062
/dev/input/event2: 0003 0036 00000179
/dev/input/event2: 0003 0030 00000000
/dev/input/event2: 0003 0032 00000004
/dev/input/event2: 0003 0039 00000000
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0000 0000 00000000
I convert it to decimal:
/dev/input/event2: 3 53 98
/dev/input/event2: 3 54 377
/dev/input/event2: 3 48 76
/dev/input/event2: 3 50 4
/dev/input/event2: 3 57 0
/dev/input/event2: 0 2 0
/dev/input/event2: 0 0 0
/dev/input/event2: 3 53 98
/dev/input/event2: 3 54 377
/dev/input/event2: 3 48 0
/dev/input/event2: 3 50 4
/dev/input/event2: 3 57 0
/dev/input/event2: 0 2 0
/dev/input/event2: 0 0 0
try using it in tasker execute plugin using !sendevent before any lines but I can't make it work, it doesn't happen anything.
Please, can you help me?
Gabriele
I found the solution, it didn't work because it require anoter 0 0 0 at the end, strange...:) this is the final result:
ReplyDeletesendevent /dev/input/event2 3 53 98
sendevent /dev/input/event2 3 54 377
sendevent /dev/input/event2 3 48 76
sendevent /dev/input/event2 3 50 4
sendevent /dev/input/event2 3 57 0
sendevent /dev/input/event2 0 2 0
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 3 53 98
sendevent /dev/input/event2 3 54 377
sendevent /dev/input/event2 3 48 0
sendevent /dev/input/event2 3 50 4
sendevent /dev/input/event2 3 57 0
sendevent /dev/input/event2 0 2 0
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 0 0 0
use adb shell prefix using emulator or ! using execute plugin for tasker, ciao!!
How did you get it to work in tasker, what context do you use. I can't get it to click at all.
ReplyDeleteLocaleexecute plugin has root permissions. It just doesn't try to click, it will do anything else I set it to do. Just not clicks.
Dan
Hello Dan,
ReplyDeleteWhat is tasker? :)
Best regards,
Yahor
check here for info:
ReplyDeletehttp://tasker.dinglisch.net/
you can use it to set up tasks to perform
eg.
"turn on wifi when you are home"
"turn on silent mode at night"
there is a plugin called "locale execute" that lets you use terminal commands.
more info here:
http://www.appbrain.com/app/locale-execute-plug-in/de.elmicha.app.LocaleExecute
Hello,
ReplyDeleteI think if you want to execute click, it would be better to create a *.sh file which takes coord params and run it from the tasker..
Also, make sure that your interface is accessible for your tasker, or do chmod 777 /dev/input/event4 :)
Best regards,
Yahor
I found the problem with the execute plugin.
ReplyDeleteIt asks for root permissions for every command, but it tries to force close for every command. If I click wait instead of force close then it will continue to the next command and try to force close again.
I will try the *.sh script later tonight, thanks for the tip :)
Dan
Hi!
ReplyDeleteAnd do you think it would be possible to automatically figure out what is the correct eventX for the current device touchscreen?
Hello Dan,
ReplyDeleteYou are always welcome :)
Please share your results if possible :)
Best regards,
Yahor
Hi cpphool,
ReplyDeleteThe easiest way to find the correct eventX (in my opinion):
after you have adb setup connect your phone to your computer, open a command prompt and type
"adb getevent -p". That should list all events, showing the number. here is the result for my touchscreen:
add device 6: /dev/input/event4
name: "atmel-touchscreen"
events:
SYN (0000): 0000 0001 0003
KEY (0001): 0066 008b 009e 00d9 0102 014a
ABS (0003): 002a value 0, min 0, max -2080439354, fuzz 0 flat 0
002b value 0, min 0, max 16711700, fuzz 0 flat 0
0030 value 0, min 0, max 255, fuzz 0 flat 0
0032 value 0, min 0, max 20, fuzz 0 flat 0
0035 value 0, min 1, max 1023, fuzz 0 flat 0
0036 value 0, min 2, max 966, fuzz 0 flat 0
you can see at the top it says "/dev/input/event4" and right below that it says "atmel-touchscreen", yours will probably say something different depending on your screen type. If you need more help just ask.
Hi Yahor,
I haven't had much free time, too busy christmas shopping :) I will try the sh script asap and report back :)
Dan
Hello Dan,
ReplyDelete"adb getevent -p" - really great tip!
Thanks a lot!
Happy testing! (:
Best regards,
Yahor
Hi guys, to make it work with tasker I used execute plugin, but instead of put all commands in execute, with problems that you have seen, I have:
ReplyDelete1. save all text lines in a txt file, for example:
sendevent /dev/input/event2 3 53 98
sendevent /dev/input/event2 3 54 377
sendevent /dev/input/event2 3 48 76
sendevent /dev/input/event2 3 50 4
sendevent /dev/input/event2 3 57 0
sendevent /dev/input/event2 0 2 0
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 3 53 98
sendevent /dev/input/event2 3 54 377
sendevent /dev/input/event2 3 48 0
sendevent /dev/input/event2 3 50 4
sendevent /dev/input/event2 3 57 0
sendevent /dev/input/event2 0 2 0
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 0 0 0
this is a click on 98 X 377 Y pixel
2. run that file with execute, using this command: ! sh /sdcard/mytxtfile.txt
So you will have to give root permission only one time, in my case I have to wait 20 seconds before it starts, but later it run sweet, hoping this help..regards
Gabriele
Hello Gabriel,
ReplyDeleteThanks for the sharing knowledges and for the tip! :)
I can add, that if you replace 98 and 377 with $1 and $2 accordignaly, you would be able to run script with X, Y params: sh /sdcard/mytxtfile.txt 100 200
Happy clicking! (:
Best regards,
Yahor
Hi,
ReplyDeleteI got the locale execute plugin to perform clicks for me, only problem is sometimes it tries to force close, just hitting 'wait' seems to fix it.
I checked the logcat and I am getting an 'app not responding' error. So its a problem with the responsiveness of the plugin.
I also tried executing the .sh script with a terminal emulator. instead of using !sendevent just type su into the terminal before executing the script, and just use sendevent. It works perfectly that way. :)
Dan
hey,
ReplyDeletewhen i run adb shell getevent | grep event2
in C:\android-sdk\tools i get this:
'grep' is not recognized as an internal or external command,
operable program or batch file
what am i doing wrong? Thanks
Hello,
ReplyDeleteThe reason that "Grep" it is Unix command, try to use "Find" command for windows:
adb shell getevent | Find "event2"
or adb shell getevent | Find /i "event2"
where /i - for case insensitive lookup (perhaps -i)
Happy testing! (:
Best regards,
Yahor
Hi all,
ReplyDeleteI'm new here, and just starting to use adb to reproduce click on devices.
I have HTC Inspire ( Android vesion 2.2.1) and trying to record click.
I extracted events related to "touch":
adb shell sendevent /dev/input/event3 3 48 48
adb shell sendevent /dev/input/event3 3 50 5
adb shell sendevent /dev/input/event3 3 53 511
adb shell sendevent /dev/input/event3 3 54 414
adb shell sendevent /dev/input/event3 0 2 0
adb shell sendevent /dev/input/event3 0 0 0
adb shell sendevent /dev/input/event3 3 48 44
adb shell sendevent /dev/input/event3 3 50 4
adb shell sendevent /dev/input/event3 3 53 511
adb shell sendevent /dev/input/event3 3 54 414
adb shell sendevent /dev/input/event3 0 2 0
adb shell sendevent /dev/input/event3 0 0 0
adb shell sendevent /dev/input/event3 3 48 38
adb shell sendevent /dev/input/event3 3 50 3
adb shell sendevent /dev/input/event3 3 53 511
adb shell sendevent /dev/input/event3 3 54 414
adb shell sendevent /dev/input/event3 0 2 0
adb shell sendevent /dev/input/event3 0 0 0
adb shell sendevent /dev/input/event3 3 48 22
adb shell sendevent /dev/input/event3 3 50 1
adb shell sendevent /dev/input/event3 3 53 511
adb shell sendevent /dev/input/event3 3 54 414
adb shell sendevent /dev/input/event3 0 2 0
adb shell sendevent /dev/input/event3 0 0 0
adb shell sendevent /dev/input/event3 3 48 0
adb shell sendevent /dev/input/event3 0 0 0
adb shell sendevent /dev/input/event3 0 0 0
and stored them in shell script but when I run it - "save image" menu pops up. Is it click too long?
Any suggestions how to fix it?
Hello,
ReplyDeleteYep, your click is too long. Looks like you have something like double or triple click..
Best regards,
Yahor
Any suggestions how to make it shorter?
DeleteWhich lines are about it?
Hello,
ReplyDeleteIf you try to discover this blog, you would find the answer :)
Your click is very alike to slide/swipe.
If you cut first half, you should get a single click, just try to use:
adb shell sendevent /dev/input/event3 3 48 38
adb shell sendevent /dev/input/event3 3 50 3
adb shell sendevent /dev/input/event3 3 53 511
adb shell sendevent /dev/input/event3 3 54 414
adb shell sendevent /dev/input/event3 0 2 0
adb shell sendevent /dev/input/event3 0 0 0
adb shell sendevent /dev/input/event3 3 48 22
adb shell sendevent /dev/input/event3 3 50 1
adb shell sendevent /dev/input/event3 3 53 511
adb shell sendevent /dev/input/event3 3 54 414
adb shell sendevent /dev/input/event3 0 2 0
adb shell sendevent /dev/input/event3 0 0 0
adb shell sendevent /dev/input/event3 3 48 0
adb shell sendevent /dev/input/event3 0 0 0
Happy clicking (:
Best regards,
Yahor
Also, please note, you can use example from article (just copy&paste "adb shell.... " from qoutes) and it should be fine signle click.
DeleteHi Yahor,
ReplyDeletethank you for your reply.
I've tried to use the code that you posted in your reply, and, got the same.
Some details what kind of click I'm trying to do:
I'm on youtube mobile video and clicking "play" button to start video. It switches to player where video starts to play, and this might affect the click. I've tried to perform simple click that loads another page, and it works perfectly fine...
It works!
DeleteI've removed few more lines:
adb shell sendevent /dev/input/event3 3 48 22
adb shell sendevent /dev/input/event3 3 50 1
adb shell sendevent /dev/input/event3 3 53 511
adb shell sendevent /dev/input/event3 3 54 414
adb shell sendevent /dev/input/event3 0 2 0
adb shell sendevent /dev/input/event3 0 0 0
adb shell sendevent /dev/input/event3 3 48 0
adb shell sendevent /dev/input/event3 0 0 0
Thank you!
Hello,
ReplyDeleteYou are always welcome :)
Happy testing! (:
Best regards,
Yahor
thank u!!
ReplyDeleteIt works on my LG optimus(2.3.4 gingerbread)
Hello,
ReplyDeleteYou are always very welcome :)
Best regards,
Yahor
Hi!
ReplyDeleteI try this on android 4.0.3 (SGS2)
This code works, but after it my phone is ignoring screen taps. Only reset helps.
Some remote control programms result the same. Some works good.
Hello! I tried a lot of the above code but none of them is working :( Maybe you can help me and provide some lines of code to touch a single point on the display. Here is what i've got from adb shell getevent:
ReplyDeleteadd device 1: /dev/input/event0
name: "Atmel maXTouch Touchscreen controller"
add device 2: /dev/input/event2
name: "7k_handset"
add device 3: /dev/input/event1
name: "7x27a_kp"
/dev/input/event0: 0003 0039 00000000
/dev/input/event0: 0003 0030 00000001
/dev/input/event0: 0003 0035 000000ba
/dev/input/event0: 0003 0036 00000125
/dev/input/event0: 0000 0002 00000000
/dev/input/event0: 0001 014a 00000001
/dev/input/event0: 0000 0000 00000000
/dev/input/event0: 0003 0039 00000000
/dev/input/event0: 0003 0030 00000001
/dev/input/event0: 0003 0035 000000ba
/dev/input/event0: 0003 0036 00000125
/dev/input/event0: 0000 0002 00000000
/dev/input/event0: 0000 0000 00000000
/dev/input/event0: 0001 014a 00000000
/dev/input/event0: 0000 0002 00000000
/dev/input/event0: 0000 0000 00000000
/dev/input/event0: 0004 0002 03000000
/dev/input/event0: 0004 0002 00ba0125
/dev/input/event0: 0000 0002 00000000
/dev/input/event0: 0000 0000 00000000
/dev/input/event1: 0001 008e 00000001
/dev/input/event1: 0000 0000 00000000
/dev/input/event1: 0001 008e 00000000
/dev/input/event1: 0000 0000 00000000
I tried the above examples with all 3 event-devices, but none of them is giving any reaction on the display.
Thanks,
Stefan
Hello,
ReplyDeleteJust try to do:
chmod 777 /dev/event*
to make event0-event3 accessible for you.
Please let me know if you have another issue.
Best regards,
Yahor
update: adb shell chmod 777 /dev/event*
DeleteHi Yahor,
Delete/dev/eventX are accessible for me. The problem looks more like they changed something in the behavior. I dumped one touch and tried to reproduce it. It actually works if i run it as a script on the phone, else sending the commands would take to much time and android thinks i pressed the touchscreen for about a second. Here is what i'm sending to the phone (and actually works):
sendevent /dev/input/event0 3 57 0
sendevent /dev/input/event0 3 48 1
sendevent /dev/input/event0 3 53 146
sendevent /dev/input/event0 3 54 448
sendevent /dev/input/event0 0 2 0
sendevent /dev/input/event0 1 330 1
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 3 57 0
sendevent /dev/input/event0 3 48 1
sendevent /dev/input/event0 3 53 146
sendevent /dev/input/event0 3 54 448
sendevent /dev/input/event0 0 2 0
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 1 330 0
sendevent /dev/input/event0 0 2 0
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 4 2 55836752
sendevent /dev/input/event0 4 2 9568704
sendevent /dev/input/event0 0 2 0
sendevent /dev/input/event0 0 0 0
I see 4 lines with the coordinates (146,448 in this case). But i don't know that the big numbers are for. They are changing when i touch different points on the display.
Do you have any idea?
Thanks for your effort.
Best regards,
Stefan
Hi Stefan,
DeleteI think it should looks like:
sendevent /dev/input/event2 1 330 1
sendevent /dev/input/event2 3 48 14
sendevent /dev/input/event2 3 53 $1
sendevent /dev/input/event2 3 54 $2
sendevent /dev/input/event2 0 2 0
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 1 330 0
sendevent /dev/input/event2 3 48 0
sendevent /dev/input/event2 3 53 $1
sendevent /dev/input/event2 3 54 $2
sendevent /dev/input/event2 0 2 0
sendevent /dev/input/event2 0 0 0
Where $1 and $2 are x and y respectively.
Just put it into the click.sh file, then do:
adb push click.sh /data/click.sh
adb shell chmod 777 /data/click.sh
adb shell /data/./click.sh 500 100
And you should see the click :)
Best regards,
Yahor
Ok, that actually works fine. Thank you. But for my device it's event0.
DeleteBest regards,
Stefan
Just wanted to say this has been a HUGE help. Thank you so much for writing this. Can't find anywhere else that even begins to explain it.
ReplyDeleteIt didn't work with Android 3.0+ (tablet).. sometimes sendevent missed for X,Y co-ordinates..
ReplyDeleteI tried to send touch event for x:113 y:165,
adb shell sendevent /dev/input/event2 1 330 1
adb shell sendevent /dev/input/event2 3 48 14
adb shell sendevent /dev/input/event2 3 53 113
adb shell sendevent /dev/input/event2 3 54 165
adb shell sendevent /dev/input/event2 0 2 0
adb shell sendevent /dev/input/event2 0 0 0
adb shell sendevent /dev/input/event2 1 330 0
adb shell sendevent /dev/input/event2 3 48 0
adb shell sendevent /dev/input/event2 3 53 113
adb shell sendevent /dev/input/event2 3 54 165
adb shell sendevent /dev/input/event2 0 2 0
adb shell sendevent /dev/input/event2 0 0 0
with acer tab 3.0 and samsung galaxy 3.x. In both case it fails.
i want to perform button click on messaging icon on the screen. i made this script for the same. on running it, the icon just moves but is not clicked and messaging page is not open.
ReplyDeleteHow can I do this?
Do I need to control pressure to do that?
I was able to emulate swipe and key press but not this button click on a screen where icons can be dragged.
sendevent /dev/input/event0 0003 0057 00000000
sendevent /dev/input/event0 0003 0048 00000001
sendevent /dev/input/event0 0003 0053 00000195
sendevent /dev/input/event0 0003 0054 00000589
sendevent /dev/input/event0 0000 0002 00000000
sendevent /dev/input/event0 0001 0348 00000001
sendevent /dev/input/event0 0000 0000 00000000
sendevent /dev/input/event0 0003 0057 00000000
sendevent /dev/input/event0 0003 0048 00000001
sendevent /dev/input/event0 0003 0053 00000195
sendevent /dev/input/event0 0003 0054 00000589
sendevent /dev/input/event0 0000 0002 00000000
sendevent /dev/input/event0 0000 0000 00000000
sendevent /dev/input/event0 0003 0057 00000000
sendevent /dev/input/event0 0003 0048 00000001
sendevent /dev/input/event0 0003 0053 00000195
sendevent /dev/input/event0 0003 0054 00000589
sendevent /dev/input/event0 0000 0002 00000000
sendevent /dev/input/event0 0000 0000 00000000
sendevent /dev/input/event0 0003 0057 00000000
sendevent /dev/input/event0 0003 0048 00000002
sendevent /dev/input/event0 0003 0053 00000195
sendevent /dev/input/event0 0003 0054 00000589
sendevent /dev/input/event0 0000 0002 00000000
sendevent /dev/input/event0 0000 0000 00000000
sendevent /dev/input/event0 0003 0057 00000000
sendevent /dev/input/event0 0003 0048 00000002
sendevent /dev/input/event0 0003 0053 00000193
sendevent /dev/input/event0 0003 0054 00000589
sendevent /dev/input/event0 0000 0002 00000000
sendevent /dev/input/event0 0000 0000 00000000
sendevent /dev/input/event0 0003 0057 00000000
sendevent /dev/input/event0 0003 0048 00000001
sendevent /dev/input/event0 0003 0053 00000193
sendevent /dev/input/event0 0003 0054 00000589
sendevent /dev/input/event0 0000 0002 00000000
sendevent /dev/input/event0 0000 0000 00000000
sendevent /dev/input/event0 0001 0348 00000000
sendevent /dev/input/event0 0000 0002 00000000
sendevent /dev/input/event0 0000 0000 00000000
I am trying this on android 4.0.3 and 4.1 and they don't work either? Did Google change this again?
ReplyDeleteHello,
ReplyDeleteYep, Google has changed signature.
Also, I can confirm that Samsung and HTC have own signatures on various platform levels.
Best regards,
Yahor
Confirmed not working for Android 4.x, but the
ReplyDeleteadb shell getevent | grep event2
method works. Thanks.
So I used the method and got result for ICS. Only 8 lines of code is need. See the code I grabbed at my blog here:
http://wp.me/p2PzKg-E
Hi Folks,
ReplyDeleteIs it possible user given (x,y) co-ordinates can be invoke as a local touch event for non-rooted device.
Rooted is possible to access /dev/input/event3 and we can convert our own coordinates and create a touch event. But Non-Rooted Android device How should I my approach? Kindly share your views.
Hi,
Deleteyes, it is possible for 4.1 android device. Please check my newest post in this blog.
Best regards,
Yahor
OMG ! it's working so wonderfully on 2.2.3 !
ReplyDeletethanks !
You are very welcome! :)
ReplyDeleteI have read this blog that is really interesting and easy to understand the low level signature process that is nice process explained in this blog that help me and other.
ReplyDeleteThanks! Please check our new articles! :)
ReplyDeleteExcellent article.
ReplyDeleteThanks a lot, Yahor Paulavets.
Do you have a G+ profile?
Thanks!
DeleteI think yes, but I'm not sure.
Best regards,
Yahor
Hi,
ReplyDeleteJust wanted to mention here that it is very easy to emulate tap/swipe on phones: Galaxy S3, Nexus S, Nexus 4 (and probably Galaxy Nexus and Galaxy S4, but I haven’t tried yet).
You just use same shell input command:
input tap [x] [y]
input swipe [x1] [y1] [x2] [y2]
Hi Yahor,
ReplyDeleteadb getevent and the send events always works. But the problem is in interpreting the slide down(scroll down) and slide up on the emulator. When i replay them using sendevent, those events are not being recognised properly as scroll rather they are recognised as long press so dragging (the icon in the location is being moved to another) occurs. Any idea of how to fix that?
Thank you.
albs
Hi!
DeleteThe better way to go is:
input tap [x] [y]
input swipe [x1] [y1] [x2] [y2]
Thanks to stansult!
If you really want to continue with events, here is the secret of any single finger gesture:
1) split events to finger down and finger up
2) send finger down with different coords
3) send funger up to complete the gesture
Best regards,
Yahor