Showing posts with label swipe. Show all posts
Showing posts with label swipe. Show all posts

9/03/2013

Automate Screen or Button Taps via Tasker

When using Tasker, sometimes we want to do some automation on screen e.g. screen or button taps.

At present, there are some ways can reach it.


1."Input" action

We can use actions in "Input" category(especially "Dpad" action and "type" Action) to do some simple click/tap.

An example: http://tasker.wikidot.com/auto-usb-mass-storage

2. Use script

Use some type of Script to do this. Yes, script may be the best solution for automation. Be careful! Sleep values might need some tweaking!
  
 
  2.1 Monkey Script

      Did you remember the "typewriter monkeys" theory? Certainly, the monkey immigrant to Android now. You can reference Android Develop Document for details if you want know parameters of monkey script. Or you can use the app named "Action Box"(Tasker plugin) directly. It providers a somehow "IDE" for monkey script.

     You may need to calculate the coordinate in screen. It's so hard.

In order to get the correct coordinates, on your device go to Settings -> dev options and turn on "show pointer location" then you can go into your app and tap on the correct location and it will display the x/y coordinates of the tap which you can input on that script. 
     Some docs about the monkey tool>>>.

  2.2 "Input" command in shell

      With "input" command in shell, we can simulate keypress event on Android. The keycode sucks!

      More info about "Input" command, here.

  2.3 Sendevent and Getevent command in Shell

      Android shell support sendevent and getevent command to grab and generate tap/swipe events on screen. So we can make a way to do this. The method "listens" to your input actions (screen taps, button presses, etc) and turns them into a script you can use to reproduce them. Think of it as something similar to Excel's Macro Recording feature. Of course, you need have knowledge of basic screen events(refer to tutorial).

  Solution 1:
1. run getevent ini adb shell
2. copy/paste it's output to file on PC
3. run script which contents one line cat $1 | gawk --non-decimal-data '{print $1, ("0x"$2)+0, ("0x"$3)+0, ("0x"$4)+0}' | sed 's/://g;s/^/sendevent /g' as convert.sh file.in > file out
4. put file.out on SD-card
5. Source it with Run Shell action

Note: the solution comes from here. Thanks to Vladimir Oz .

  Solution 2:

     You can use "Sendevent->Getevent Toolbox" to find a way out.

Note:I had test it on my MiOneS phone (ROM: MIUI-3.9.6). Yes, works very well(the shell script need some minor tweaking). Maybe it's the easiest way at present in my opinion. Thanks to GermainZ.