Android 5.0 Favorite Features, Release November 3rd? – XDA TV

Google Confirms Android 5.0 Lollipop for November 3rd! That and much more … more

Prepare Your Build Machines: Ubuntu 14.10 Utopic Unicorn Now Official

Today is an important day for any and all Linux enthusiasts. One of the … more

Track the Time You Waste on Social Media with Socials Addict

When you use your phone, you often don’t even realize how much time you … more

Document the Story of Your Social Life with 8tory

The different forms of social media are growing every day. It’s hard to imagine a day … more
Post Reply

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

OP GermainZ

14th April 2013, 12:31 AM   |  #1  
GermainZ's Avatar
OP Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 6,740
 
5,689 posts
Join Date:Joined: Aug 2012
Donate to Me
More
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.
Last edited by GermainZ; 15th April 2013 at 09:14 PM.
The Following 21 Users Say Thank You to GermainZ For This Useful Post: [ View ]
14th April 2013, 06:29 PM   |  #2  
sheraro's Avatar
Senior Member
Thanks Meter: 211
 
529 posts
Join Date:Joined: Jan 2012
More
worked flawlessly thanks man , example with search button with filtered inputs for xperia play

15th April 2013, 08:09 PM   |  #3  
GermainZ's Avatar
OP Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 6,740
 
5,689 posts
Join Date:Joined: Aug 2012
Donate to Me
More
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: [ View ]
15th April 2013, 09:18 PM   |  #4  
laufersteppenwolf's Avatar
Forum Moderator / Recognized Developer
Flag Baden-Württemberg
Thanks Meter: 5,443
 
2,565 posts
Join Date:Joined: Jul 2012
Donate to Me
More
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
25th April 2013, 07:57 PM   |  #5  
Senior Member
Thanks Meter: 80
 
887 posts
Join Date:Joined: 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
25th April 2013, 08:10 PM   |  #6  
GermainZ's Avatar
OP Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 6,740
 
5,689 posts
Join Date:Joined: Aug 2012
Donate to Me
More
Quote:
Originally Posted by fabzbear

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.
Last edited by GermainZ; 25th April 2013 at 08:13 PM.
26th May 2013, 09:25 AM   |  #7  
Member
Thanks Meter: 11
 
33 posts
Join Date:Joined: 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.
1st July 2013, 08:56 PM   |  #8  
BleedingIris's Avatar
Senior Member
HEAVEN
Thanks Meter: 744
 
2,328 posts
Join Date:Joined: Aug 2012
Quote:
Originally Posted by agentdude

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!
9th July 2013, 03:43 AM   |  #9  
Member
Thanks Meter: 32
 
98 posts
Join Date:Joined: May 2011
Thank you for this. I was finally able to get tasker to play Spotify with the help from this script.
9th October 2013, 05:07 PM   |  #10  
Senior Member
Thanks Meter: 81
 
192 posts
Join Date:Joined: Jul 2010
Quote:
Originally Posted by GermainZ

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...".

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Miscellaneous Android Development by ThreadRank