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

Search This thread

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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:

sheraro

Senior Member
Jan 15, 2012
689
235
Casablanca
worked flawlessly thanks man , example with search button with filtered inputs for xperia play

qezFkiI.png
 
  • Like
Reactions: MReinke

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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. :)
 

laufersteppenwolf

Inactive Recognized Developer / Retired Forum Mod
Jul 1, 2012
2,840
6,964
Baden-Württemberg
droideveloper.com
works fine here, too (LG Optimus 4x HD)
the only "issue" is caused by my device itself :D 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 ;)
 

fabzbear

Senior Member
Nov 26, 2010
934
80
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

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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:
  • Like
Reactions: MReinke

agentdude

Member
Jul 8, 2012
33
11
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

Senior Member
Aug 12, 2012
2,313
748
HEAVEN
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!
 

at4r1

Senior Member
May 6, 2011
98
32
Thank you for this. I was finally able to get tasker to play Spotify with the help from this script.
 

e154037

Senior Member
Jul 17, 2010
204
121
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...".
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
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...".

I don't think so, not unless you have a hard keyboard.
 
  • Like
Reactions: e154037

e154037

Senior Member
Jul 17, 2010
204
121
I don't think so, not unless you have a hard keyboard.
Found a way to simulate key clicks for coping current text line to clipboard. With Hackers soft keyboard, the keys to press are: HOME, SHIFT+END, CTROL+C. The following script does this simulation nicely:

#simulate key click on fn, home, shift, end, fn, ctrl, c
input touchscreen tap 870 730
input touchscreen tap 1020 450
input touchscreen tap 80 670
input touchscreen tap 1020 520
input touchscreen tap 870 730
input touchscreen tap 70 590
input touchscreen tap 400 660

The key positions are for hacker's keyboard on ASUS TF101 tablet.
 
Last edited:

gianmaxfactor

Senior Member
Sep 5, 2012
83
10
47
Rome
Hi, thanks for the wonderful script. I get it working.
Now that I can simulate the "tap", I would like to know how to modify my script to obtain a "double tap" and a "long tap".

Thanks in advance.

PS.: This is my tap at x=248,y=164

sendevent /dev/input/event1 3 57 0
sendevent /dev/input/event1 3 53 248
sendevent /dev/input/event1 3 54 164
sendevent /dev/input/event1 3 48 1
sendevent /dev/input/event1 3 49 0
sendevent /dev/input/event1 3 52 0
sendevent /dev/input/event1 3 50 0
sendevent /dev/input/event1 0 2 0
sendevent /dev/input/event1 3 57 1
sendevent /dev/input/event1 3 53 83
sendevent /dev/input/event1 3 54 202
sendevent /dev/input/event1 3 48 0
sendevent /dev/input/event1 3 49 0
sendevent /dev/input/event1 3 52 0
sendevent /dev/input/event1 3 50 0
sendevent /dev/input/event1 0 2 0
sendevent /dev/input/event1 0 0 0
sendevent /dev/input/event1 3 57 0
sendevent /dev/input/event1 3 53 248
sendevent /dev/input/event1 3 54 164
sendevent /dev/input/event1 3 48 0
sendevent /dev/input/event1 3 49 0
sendevent /dev/input/event1 3 52 0
sendevent /dev/input/event1 3 50 0
sendevent /dev/input/event1 0 2 0
sendevent /dev/input/event1 3 57 1
sendevent /dev/input/event1 3 53 83
sendevent /dev/input/event1 3 54 202
sendevent /dev/input/event1 3 48 0
sendevent /dev/input/event1 3 49 0
sendevent /dev/input/event1 3 52 0
sendevent /dev/input/event1 3 50 0
sendevent /dev/input/event1 0 2 0
sendevent /dev/input/event1 0 0 0
sendevent /dev/input/event1 3 57 0
sendevent /dev/input/event1 3 53 248
sendevent /dev/input/event1 3 54 164
sendevent /dev/input/event1 3 48 0
sendevent /dev/input/event1 3 49 0
sendevent /dev/input/event1 3 52 0
sendevent /dev/input/event1 3 50 0
sendevent /dev/input/event1 0 2 0
sendevent /dev/input/event1 3 57 1
sendevent /dev/input/event1 3 53 83
sendevent /dev/input/event1 3 54 202
sendevent /dev/input/event1 3 48 0
sendevent /dev/input/event1 3 49 0
sendevent /dev/input/event1 3 52 0
sendevent /dev/input/event1 3 50 0
sendevent /dev/input/event1 0 2 0
sendevent /dev/input/event1 0 0 0
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
Hi, thanks for the wonderful script. I get it working.
Now that I can simulate the "tap", I would like to know how to modify my script to obtain a "double tap" and a "long tap".

Thanks in advance.

PS.: This is my tap at x=248,y=164
Either copy paste the 4 lines that appear on every touch twice (double tap) or once and put a "sleep 1" between the first two and the last two (long press).

You can also use something like this:
Code:
# double tap
input tap 248 164
input tap 248 164

# long press
input swipe 248 164 248 164 1000

# help on the input command
input
 

gianmaxfactor

Senior Member
Sep 5, 2012
83
10
47
Rome
Input tap and input swipe would be marvelous... but unfortunately I'm on android 2.3.6. In fact I imagine that swipe will be almost impossible.

Anyway, why do you talk about "4 lines" ? I see dozens of lines... what are the four I have to duplicate?
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
Input tap and input swipe would be marvelous... but unfortunately I'm on android 2.3.6. In fact I imagine that swipe will be almost impossible.

Anyway, why do you talk about "4 lines" ? I see dozens of lines... what are the four I have to duplicate?
It's four on my old device, might be more for you. Basically, X lines are repeated every time you make a click. See which.

BTW, did you try actually long pressing? The script should be able to simulate that, though you'll probably want to exaggerate the long press (e.g. 3 seconds instead of one).
 

gianmaxfactor

Senior Member
Sep 5, 2012
83
10
47
Rome
It's four on my old device, might be more for you. Basically, X lines are repeated every time you make a click. See which.

BTW, did you try actually long pressing? The script should be able to simulate that, though you'll probably want to exaggerate the long press (e.g. 3 seconds instead of one).

I tried... but the output is so long that I am not able to copy it entirely. I think I could add something to your script to divert the output into a file. But I don't know where (and how)...
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
I tried... but the output is so long that I am not able to copy it entirely. I think I could add something to your script to divert the output into a file. But I don't know where (and how)...
Run the script. Tap *once*. Wait for ~5s. Cancel the action. In the outputted script, you'll see a line that says something like "sleep 5" - everything before it should be the tap, everything after garbage..
 

gianmaxfactor

Senior Member
Sep 5, 2012
83
10
47
Rome
BTW, did you try actually long pressing? The script should be able to simulate that, though you'll probably want to exaggerate the long press (e.g. 3 seconds instead of one).

Incredibly there is a continuos flow of events while longpressing... dozens and dozens of quickly repeating actions... so there is no "sleep" in the output of the script. Every device is a world apart ! Thanks anyway... I've been a big help from you ! Bye
 

hamzahrmalik

Senior Member
May 31, 2013
1,658
2,020
I used option one
I set to record 4
Nothing happens
O tried 500
Same result

Edit
OK that was vague
It does countdown
Then goes blank
No output no matter what I do
 

Top Liked Posts

  • There are no posts matching your filters.
  • 25
    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.
    2
    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. :)
    1
    worked flawlessly thanks man , example with search button with filtered inputs for xperia play

    qezFkiI.png
    1
    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.
    1
    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...".

    I don't think so, not unless you have a hard keyboard.