Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,813,956 Members 43,434 Now Online
XDA Developers Android and Mobile Development Forum

[SCRIPT] getevent -> sendevent - Easily automate screen/button taps from the shell

Tip us?
 
GermainZ
Old
(Last edited by GermainZ; 15th April 2013 at 09:14 PM.)
#1  
GermainZ's Avatar
Forum Moderator / Recognized Developer - OP
Thanks Meter 6,425
Posts: 5,490
Join Date: Aug 2012
Default [SCRIPT] getevent -> sendevent - Easily automate screen/button taps from the shell

Intro
I originally wrote this script for LMT, but it has changed a lot since then and (hopefully) deserves its own thread.
You can check the original script's post here, or read more about (part of) what this script is automating (and how it does it) here.
You can also check the Tasker Google Groups thread about the script (clickie).

So what does this do?
It "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.

Usage
Run the script, pick the first option and enter the number of events to catch. Depending on the device, one button press ~ 4 events, sometimes more. A screen tap is unpredictable as you're never touching the screen in one spot but in many close spots.
A neat trick would be to enter a high number of events (e.g. 500), do whatever you want to do then wait for ~X seconds (10 for example). Then copy the generated script but exclude everything after the line that says "sleep X".
And if you still have any doubts... try it. That's probably the best way to understand what it does and how to use it.

Custom toolbox
You need a custom toolbox (instead of the default /system/bin/toolbox) in order to use Option 2 correctly. This is because the default "getevent" command isn't line buffered, so it usually sends its output every ~50 lines.
I therefore re-compiled the toolbox (getevent is only a launcher for it) to enable line buffering. This enables the script to work at full speed - it might still be too slow, so do allow a few extra seconds (10 seconds should be safe) of no activity for it to finish.
You'll need to download the modified version, linked below, place it in /tmp/ and give it the correct permissions (chmod 755). Note that it will not persist across reboots, so keep a backup somewhere else.
Code:
https://www.dropbox.com/s/t0xhxa3xuc8m92m/toolbox
Download
You can get the latest version here.

Bugs/Suggestions
Bugs? There are no bugs.
Actually, I'm not an elite script writer, so chances are there are a few quirks. If you find any, please report them.
Also post all your suggestions and I'll try to add them.

To do
  • This list will be updated based on your feedback.

Thanks
  • The guys at #bash helped me a lot.
  • zeppelinrox, learned plenty of stuff from his scripts.
  • Everyone who tested previous versions (mostly laufersteppenwol :P).


Also feel free to ask any question, or answer any potentially interesting question that should be added to this post. I'll make sure to update it with a FAQ.

Thanks
I've contacted a moderator and he said it was okay for me to post in this section instead of the Misc. Software Development section, so it wouldn't get buried within hundreds of ROMs/kernels for devices without forums. This section will be cleaned soon anyway.
The Following 21 Users Say Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
sheraro
Old
#2  
sheraro's Avatar
Senior Member
Thanks Meter 211
Posts: 529
Join Date: Jan 2012
worked flawlessly thanks man , example with search button with filtered inputs for xperia play

 
GermainZ
Old
#3  
GermainZ's Avatar
Forum Moderator / Recognized Developer - OP
Thanks Meter 6,425
Posts: 5,490
Join Date: Aug 2012
Update:
  • You're now warned if you don't have busybox installed;
  • Busybox not automatically creating symlinks shouldn't be an issue any longer;
  • The timeout option should now work, but you'll need a custom toolbox (instead of /system/bin/toolbox) to run it. Read the OP for more info.

I'm not sure if the custom toolbox will work on all devices. Please test it out, it's completely safe as you'll be placing it in /tmp/ anyway without overwriting the original, unmodified version on your device.
The Following 2 Users Say Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
laufersteppenwolf
Old
#4  
laufersteppenwolf's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 5,226
Posts: 2,492
Join Date: Jul 2012
Location: Baden-Württemberg

 
DONATE TO ME
works fine here, too (LG Optimus 4x HD)
the only "issue" is caused by my device itself it records way too much events in a short time (good for using the phone, but bad for the script ) so ~1000 events are enough for about one or two swipe(s)

but try yourself
Sony Ericsson Xperia X8: GingerDX v31b ; alfs CM7 v09c
LG Optimus 4x HD: my own version of CM 10.1 , CWM recovery, UNlocked BL

Crying that it's an application bug is like crying over the speed of light: you should deal with reality, not what you wish reality was. - Linus Torvalds
 
fabzbear
Old
#5  
Senior Member
Thanks Meter 80
Posts: 879
Join Date: Nov 2010
Can you do a YouTube tutorial or just a written one one how to use it to get an event like opening the app draw of a launcher or something.
You give some explanation but I'm still a bit lost after rereading twice.

Sent from my SPH-L710 using xda app-developers app
 
GermainZ
Old
(Last edited by GermainZ; 25th April 2013 at 08:13 PM.)
#6  
GermainZ's Avatar
Forum Moderator / Recognized Developer - OP
Thanks Meter 6,425
Posts: 5,490
Join Date: Aug 2012
Quote:
Originally Posted by fabzbear View Post
Can you do a YouTube tutorial or just a written one one how to use it to get an event like opening the app draw of a launcher or something.
You give some explanation but I'm still a bit lost after rereading twice.

Sent from my SPH-L710 using xda app-developers app
Choose option 1 or 2, wait for the countdown to finish. do whatever you want to do.
For option 2, it should be simple enough - you just put a timeout. You'll need the modified toolbox from the first post, tho.

For option 1, you have to input a certain number of events. It's just impossible to predict that (especially if you're dealing with screen taps and not just button presses), so I suggest you do this:
  1. Put a higher number (e.g. 500) (if you're only interested in button presses, 1 button press = ~4->~10 events, depending on the device).
  2. Do whatever you want to do.
  3. Wait for ~10s without doing anything.
  4. Check the script's output (by reopening the terminal emulator/script manager).
  5. If the script has finished (500 events have been reached already), it probably didn't record everything. Restart from step 1, with a higher number (e.g. 1000).
  6. If not, spam your touchscreen till it's done.
  7. Copy the outputted script and search for a line that looks like "sleep 10" (where "10" is approximately the amount of seconds you waited in step 3).
  8. Remove everything after that line.

PS: If you get spam events from other input devices you're not interested in (e.g. compass), you can use Option 4 to only monitor the touchscreen device, for example.
 
agentdude
Old
#7  
Member
Thanks Meter 11
Posts: 33
Join Date: Jul 2012
wow this is great! what is the minimum number of lines of code needed for one screen touch to register (e.g. pressing a button)? i try to make mine the small by pressing very quickly which works great. However, i am just curious because when i try to shorten the code by myself in any of the areas, the script does not work.
 
BleedingIris
Old
#8  
BleedingIris's Avatar
Senior Member
Thanks Meter 743
Posts: 2,328
Join Date: Aug 2012
Location: HEAVEN
Quote:
Originally Posted by agentdude View Post
wow this is great! what is the minimum number of lines of code needed for one screen touch to register (e.g. pressing a button)? i try to make mine the small by pressing very quickly which works great. However, i am just curious because when i try to shorten the code by myself in any of the areas, the script does not work.
Possibly two lines -

@GermainZ

Great work - now I can diagnose my power button as well as simulate it. Thanks man!
If I didn't answer you for a long time, then enter the answer to your question is either here or here.
 
at4r1
Old
#9  
Member
Thanks Meter 32
Posts: 97
Join Date: May 2011
Thank you for this. I was finally able to get tasker to play Spotify with the help from this script.
 
e154037
Old
#10  
Senior Member
Thanks Meter 80
Posts: 192
Join Date: Jul 2010
Quote:
Originally Posted by GermainZ View Post
Update:
  • You're now warned if you don't have busybox installed;
  • Busybox not automatically creating symlinks shouldn't be an issue any longer;
  • The timeout option should now work, but you'll need a custom toolbox (instead of /system/bin/toolbox) to run it. Read the OP for more info.

I'm not sure if the custom toolbox will work on all devices. Please test it out, it's completely safe as you'll be placing it in /tmp/ anyway without overwriting the original, unmodified version on your device.
I would like to make a script to copy current text line to clipboard. With Hackers soft keyboard, the keys to press are: HOME, SHIFT+END, CTROL+C. Anyway to do this
simulation with either "input keyevent ..." or "sendevent...".

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Add Some Power to First Generation Snapdragon CPUs

Some older devices still remain very popular. Phones like theHTC Desire, Sony Ericsson … more

Android M Mentions Spotted in Android Code Review

While we are still waiting for Android L to be officially released, the first mentions of … more

Create a Simple Custom Launcher from Scratch

When you are starting your journey intoany sort of development, it’s never easy at the … more