Helper script: reproduce key taps/button presses easily.

2,013 views
Skip to first unread message

GermainZ

unread,
Feb 18, 2013, 10:52:11 AM2/18/13
to tas...@googlegroups.com
Root required

If you're interested in emulating button presses and key taps, you might want to give this script a shot.
It's a script I wrote that fully automates getevent -> sendevent conversion.
Basically, you fire it up, tell it how many events to catch, and do whatever you wanna do. The script then outputs a script you can use to reproduce what you just did. It's that simple.

Why you might want to use it:
* It supports screen touches;
* It's faster than Tasker's built in dpad (if you have hard dpad buttons; otherwise you can't emulate them directly using the script, but the same method applies);
* You can queue many actions (e.g. menu button > press the preferences button > enable a random setting > press back > press home, etc).

Example usage (I just tried that on my device; ran the script's output in SManager):
*Press Menu button
*Open SManager's Help popup by tapping on the screen
*Close the popup by tapping on the "Close" button
*Long press the home button and tap "Task Manager"
*Kill SManager by tapping "End"


Getting the right amount of events can be tricky, so here's a little hint: set a high number (e.g. 200), do what you wanna do, and once you're done, wait for ~20 seconds then spam your screen with touches till the script outputs the commands. Don't copy everything below the line that reads something like "sleep 20". :D

Lex

unread,
Feb 18, 2013, 8:48:54 PM2/18/13
to Tasker
Awesome work, thanks! This will definitely save me a bunch of
tinkering and experimentation :)

Sergio

unread,
Feb 19, 2013, 3:11:55 PM2/19/13
to tas...@googlegroups.com
If I understand wellì, this is like the "record macro" in Excel.
Is it ?

If yes, this means it it's time for me to root my SGS2, so that I can mount my SD card as a USB mass storage without having to touch the screen more than 7 times to get to the right place...

And, if yes, many many thanks to GermainZ

Now, I just need to learn how to load the script on my SGS2 and run it... 

GermainZ

unread,
Feb 19, 2013, 3:34:01 PM2/19/13
to tas...@googlegroups.com
More or less, except there's no stop button. You'll have to guess how many events you wanna catch.
That being said, the script might not detect swipes perfectly. I don't know how Android reports them, I haven't tested swipes yet -in that case, some manual tweaking will be required. If someone tests it, report back ;)

By the way, make sure you have busybox installed and you run the script as root (using SManager is probably the easiest way to manage scripts).

Sergio

unread,
Feb 19, 2013, 4:03:57 PM2/19/13
to tas...@googlegroups.com

thanks.
I will try...
I'm on business trip this week, but I know know what I will do during the week-end... 
- root the phone, after I have found out how
- install "busybox" and SManager after I have read what they do
- download your script from XDA and find the way to upload it on the SGS2
- find the way to run it
- activate USB mass storage and obtain the script (swipes are not required, just multiple touches on "manu-settings-USBmassstorage-confirm-ok-ok....)
- find a way to link the new script to a widget on my home.....

As soon as I can finish everything I will post the results here. Or before, if I run into problems...

Rich D

unread,
Feb 20, 2013, 9:26:02 PM2/20/13
to tas...@googlegroups.com

Thanks for the great work GermainZ ... This script works great. :)

I have already been able to figure out a few buttons and put together a keyboard shortcut for pasting in tasker.  I have posted it here:

https://groups.google.com/group/tasker/browse_thread/thread/78b90b185cf1bd6a/c4492f1cb0f1240d?hl=en#c4492f1cb0f1240d

I have very little experience with shell script or using a terminal emulator but was able to muddle my way through and figure most of it out. So I thought i would post a small newbie help guide here for others..

- you need to set the terminal for root.. this is done by simply entering "su" ( no quotes ) in the terminal

- copying and pasting the script did not work for me at all. You should run the downloaded file from the terminal.  Use the command: exec sh /mnt/sdcard/download/getevent_to_sendevent.txt ( you will have to use your file path of course.)

- The one thing that tripped me up the most was after reading the tutorial and seeing the example that on  GermainZ's device the menu button had 4 events I ASSumed that my menu button would have 4 events as well BZZZZZTT...  Wrong answer...  on my device the menu button has 14  events ( 7 for button down 7 for button up) and my "v" button has 10 ( 5 down, 5 up)   

Unfortunately I did not understand the hint about how to spam the screen for output. I probably did it the hard way and copied the entire output to a text editor then copied what I thought might be the correct code and pasted it back into the terminal. Hopefully  GermainZ could post a a few tips on this approach....

Here are the 2 buttons I figured out for my DROID 4 ..

Menu Button:

sendevent /dev/input/event4    3    53    95
sendevent /dev/input/event4    3    54  1017
sendevent /dev/input/event4    3    48    15
sendevent /dev/input/event4    3    50     1
sendevent /dev/input/event4    3    57     0
sendevent /dev/input/event4    0     2     0
sendevent /dev/input/event4    0     0     0
sendevent /dev/input/event4    3    53    95
sendevent /dev/input/event4    3    54  1017
sendevent /dev/input/event4    3    48     0
sendevent /dev/input/event4    3    50     1
sendevent /dev/input/event4    3    57     0
sendevent /dev/input/event4    0     2     0
sendevent /dev/input/event4    0     0     0

"v"   Button


sendevent /dev/input/event1    3     2   265
sendevent /dev/input/event1    0     0     0
sendevent /dev/input/event3    4     4    15
sendevent /dev/input/event3    1    47     1
sendevent /dev/input/event3    0     0     0
sendevent /dev/input/event1    3     2   269
sendevent /dev/input/event1    0     0     0
sendevent /dev/input/event3    4     4    15
sendevent /dev/input/event3    1    47     0
sendevent /dev/input/event3    0     0     0

As you can see there is a    0   0    0   In between the down and up button but also note that a.    0    0     0   Can be included in the button sequence as well.  In the end I figured it out by setting it for 100 events then pressing the button on/off multiple times during the test then checking for a pattern in the output.

Hope this helps....  Rich..

GermainZ

unread,
Feb 21, 2013, 7:13:27 AM2/21/13
to tas...@googlegroups.com
Basically, my tip was something like this:
1- Set a high number of events;
2- Do what you wanna do;
3- Wait for ~20 seconds;
4- Spam your buttons/screen by tapping around till the number of events is satisfied.
Now, in the output, there should be a line like "sleep 20" (where "20" is the amount of time you waited). Just ignore everything below that.

Danny Thomson

unread,
Feb 26, 2013, 7:20:57 AM2/26/13
to tas...@googlegroups.com
I have no idea what im doing.. I just added profile, um.. sensor.. shake. Added task, script, javascript.. added ur txt under file path.. but I get an unexpected string.. I just wanna simulate the screen being pressed about 1000 times in the center-ish (doesnt have to be perfect) then stop.. so.. :/ what am I doing wrong? Sorry if im just being dumb... thx

GermainZ

unread,
Feb 26, 2013, 11:12:10 AM2/26/13
to tas...@googlegroups.com
Run the script using SManager or similar. What the script outputs can be used in Tasker.

Danny Thomson

unread,
Feb 26, 2013, 2:06:06 PM2/26/13
to tas...@googlegroups.com
Events to catch? > 4 Gonna catch 4 events... Starting in... 3 2 1 Go! sendevent /dev/input/event5 1 102 1 sendevent /dev/input/event5 0 0 0 sleep 3 sendevent /dev/input/event5 1 102 0 sendevent /dev/input/event5 0 0 0

Alright. So this goes in tasker as a javascript?

Danny Thomson

unread,
Feb 26, 2013, 3:00:45 PM2/26/13
to tas...@googlegroups.com
Omg.. this is to much... rage quit.. anyone know of an app that will click the screen a ton of times?

TomL

unread,
Feb 26, 2013, 3:43:21 PM2/26/13
to tas...@googlegroups.com
I saw someone once use the internet to look for stuff.

Danny Thomson

unread,
Feb 27, 2013, 12:01:26 AM2/27/13
to tas...@googlegroups.com
I once saw someone assume somthing and looked like an idiot.

Ive been serching the internet, playstore, blackmarket alpha, xda, for about 4 days now.
Hence why I asked. I wouldnt have otherwise.
Not sure if im searching with the wrong words or what...

Oon-Ee Ng

unread,
Feb 27, 2013, 1:05:10 AM2/27/13
to tas...@googlegroups.com
You know, asking a question like 'so this goes in tasker as a
javascript?' is the very definition of looking like an idiot who
doesn't search, which part of the script looks like java to you?

Or perhaps you haven't actually looked at the scripts...

GermainZ

unread,
Feb 27, 2013, 1:31:02 AM2/27/13
to tas...@googlegroups.com
It's a shell script. It outputs shell commands. That should've been clear enough in the first post. ;)

Copy the sendevent commands the script outputted and paste them in the "Run Shell" action of Tasker. You can test these lines first using SManager.
I trust you to read the documentation of Tasker and help of SManager first, obviously, if there are some parts you don't understand.

Also, take into consideration what the other guys said. This definitely wasn't hard to figure out with a bit of searching and thinking. If you're going to reply and try to prove they're wrong and that you did search - don't bother. You could've searched better, and it doesn't matter anymore at this point.

Danny Thomson

unread,
Feb 27, 2013, 5:48:05 AM2/27/13
to tas...@googlegroups.com
I never said anyone was wrong. I simply stated that I did search for a while. And sense taskers website isnt all that updated. There was nothing really I could do. All I said is that it was to confusing to me. And if anyone knew of an app that clicked a bunch. And I got a smart ass remark. So I gave one back. Also. Just because im new to java, or shell. Dont mean im an idiot. Refer to my assume post. Thx.

TomL

unread,
Feb 27, 2013, 7:50:02 AM2/27/13
to tas...@googlegroups.com
Danny, two questions.

1. What exactly are you trying to do with the "tap on the screen a lot"?  Maybe there's a better approach to accomplish what you want that doesn't involve screen taps.

2. Why should we put in the effort to help you when you can't even be bothered to put in the effort to explain what it is you want, what you've tried, and what didn't work, and what were the steps you took?

As in many things in life, you get back what you put in.

Tom

GermainZ

unread,
Feb 27, 2013, 8:24:11 AM2/27/13
to tas...@googlegroups.com
On Wednesday, February 27, 2013 12:48:05 PM UTC+2, Danny Thomson wrote:
I never said anyone was wrong.
Hence the "If". :)

Danny Thomson

unread,
Feb 27, 2013, 3:15:18 PM2/27/13
to tas...@googlegroups.com
Actually.. ive givin up on it. It was dumb n e ways. It was a stupid game. I was only doing it for my wife.
But anyways..

I start by opening smanager.
The make new script. Paste your script in there. Then I make it my fav. And turned on root. Then run it. It sits there at..

Events to catch? >

Then I goto console and click run shell.
I paste in your little script thingy..
No idea what im doing at this point.. this is what I get.

exec sh -c "cd '/storage/sdcard0' ; exec /system/bin/sh"
'/storage/sdcard0' ; exec /system/bin/sh" <
t /dev/input/event5 0 0 0 /dev/input/event5 0 0 0 1 Go! sendevent /dev/input/event5 1 102 1 s*
/system/bin/sh: vents: not found
127|root@android:/storage/sdcard0 #

Ok so to me that = broken. :p
So then I think.. ok what about paste were it says..
Events to catch? >

This is what I get..


Events to catch? > Events to catch? > 4 Gonna catch 4 events... Starting in... 3 2 1 Go! sendevent /dev/input/event5 1 102 1 sendevent /dev/input/event5 0 0 0 sleep 3 sendevent /dev/input/event5 1 102 0 sendevent /dev/input/event5 0 0 0
Gonna catch Events to catch? > 4 Gonna catch 4 events... Starting in... 3 2 1 Go! sendevent /dev/input/event5 1 102 1 sendevent /dev/input/event5 0 0 0 sleep 3 sendevent /dev/input/event5 1 102 0 sendevent /dev/input/event5 0 0 0 events...


Starting in...
3
2
1
Go!

tail: invalid number 'Events'
Usage: getevent [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r] [device]
-t: show time stamps
-n: don't print newlines
-s: print switch states for given bits
-S: print all switch states
-v: verbosity mask (errs=1, dev=2, name=4, info=8, vers=16, pos. events=32, props=64)
-d: show HID descriptor, if available
-p: show possible events (errs, dev, name, pos. events)
-i: show all device info and possible events
-l: label event types and names in plain text
-q: quiet (clear verbosity mask)
-c: print given number of events then exit
-r: print rate events are received


This is as far as ive gotten using smanager.

Oh and the game. Its called "fish live" ive used cih to kinda alter the code to have more than 30 fish in the tank. I have to click the screen to put fish in it. Every.... time..... :/

Hope this is useful. And I apologies for my previous comments. Been workin 60hrs week. Well.. im just stressed.
Thsnks.

GermainZ

unread,
Feb 27, 2013, 3:33:55 PM2/27/13
to tas...@googlegroups.com
1- Run the script using SManager.
2- Specify the number of events to catch. Let's say 4 (equivalent to one button on my device).
3- Press e.g. the menu button.
4- You should see something like this in the output:
sendevent /dev/input/event5 1 102 1
sendevent /dev/input/event5 0 0 0
sendevent /dev/input/event5 1 102 0
sendevent /dev/input/event5 0 0 0
5- Copy the sendevent lines.
6- Create a new script using SManager and paste these lines.
7- Run the newly create script as root.
8- What you just did (the button press) should be replicated.

TomL

unread,
Feb 27, 2013, 4:49:02 PM2/27/13
to tas...@googlegroups.com
You were obviously frustrated with trying to get things to work, and didn't deserve a smart alec remark from me. My apologies. You're a good spouse to trying to get it working for your wife.

Cheers.

Tom

Rich D

unread,
Feb 27, 2013, 5:29:04 PM2/27/13
to tas...@googlegroups.com

I am glad to see we are all playing nice now. :)  ... I actually did not reply earlier because I found your first few posts to be nondescript and confusing as well..

So here is my 2 cents for what it is worth..

> Then I goto console and click run shell.
> I paste in your little script thingy..
> No idea what im doing at this point.. this is what I get.

I am not sure but this might be where the trouble starts.. if you read my post above for newbies (like me) I found that when I copied and pasted the script into the terminal it did run,  but not correctly.. you need to run the script from the terminal by using the command:

exec sh /mnt/sdcard/download/getevent_ to_sendevent.txt ( you will have to use your file path of course.)

I am sure this will work however I think getting a screen tap may be a somewhat trickier than a button.

Another approach can be found if you search the group for "Speed up DPAD presses? "  This may be a easier method for a screen tap.

GermainZ

unread,
Apr 8, 2013, 11:15:46 AM4/8/13
to tas...@googlegroups.com
And what happened?

On Monday, April 8, 2013 5:25:17 PM UTC+3, James Eastwood wrote:
Hi,

I didn't get an option to specify how many events to catch?

Whereabouts do I specify this?

I opened it in scriptmanager with root checked.

ScottS

unread,
Apr 8, 2013, 1:26:15 PM4/8/13
to tas...@googlegroups.com
I'm a bit confused by this as well...where do you indicate the number of Events to track? I opened it as a 'Script' in Script Manager, and thought maybe the number of Events was 'Arguments', however, that didn't seem to work either. I've attached a screenshot of the output I receive.
get-send.jpg

GermainZ

unread,
Apr 8, 2013, 1:33:36 PM4/8/13
to tas...@googlegroups.com
I keep forgetting about updating the script, oh well. Anyway, just read EDIT3 of the XDA thread:

EDIT3: Here's one fix you could try if you're getting an error related to "read -p", replace the first line by: echo "Events to catch? > "; read l

ScottS

unread,
Apr 8, 2013, 2:26:26 PM4/8/13
to tas...@googlegroups.com
Okay, made some progress, though I seem to be getting errors now (shown below). Assuming the replacement phrase you mentioned was to replace the 'read -p' line, to look like:

Script:
clear

echo "Events to catch? > "; read l
echo "Gonna catch $l events..."
...

Script output:
Events to catch? >
50
Gonna catch 50 events...

Starting in...
3
2
1
Go!

could not get driver version for /dev/input/mice, Not a typewriter
expr: non-numeric argument
/storage/sdcard0/Download/get_send_event.txt[26]: [: 0: unexpected operator/operand
sendevent 53232.126390printf: 0x/dev/input/event5:: invalid number
0 3 53
expr: non-numeric argument
/storage/sdcard0/Download/get_send_event.txt[26]: [: 0: unexpected operator/operand
sendevent 53232.126390printf: 0x/dev/input/event5:: invalid number
0 3 54
...

GermainZ

unread,
Apr 8, 2013, 3:37:49 PM4/8/13
to tas...@googlegroups.com
I'll try rewriting it later and check the POSIX syntax (hopefully that'll work across all Android shells).

ScottS

unread,
Apr 8, 2013, 3:47:58 PM4/8/13
to tas...@googlegroups.com
Sounds great...thanks for this! For what it's worth, here's my phone:

Moto Droid RAZR M
JB 4.1.1
Rooted, stock ROM

James Eastwood

unread,
Apr 10, 2013, 6:44:04 AM4/10/13
to tas...@googlegroups.com
I have the same errors as Scott and am looking forward to an update :) the potential for tasker is huge!

TomL

unread,
Apr 10, 2013, 7:48:21 AM4/10/13
to tas...@googlegroups.com
Would it be helpful if people posted what version of busybox they're running?  I suspect that might contribute to the differences in shell command syntax in the field.

busybox | head -n1

"BusyBox v1.20.2-Stericson"

etc etc etc

Tom

James Eastwood

unread,
Apr 10, 2013, 8:23:44 AM4/10/13
to tas...@googlegroups.com
1.20.2

ScottS

unread,
Apr 10, 2013, 10:26:54 AM4/10/13
to tas...@googlegroups.com
BusyBox 1.21.0

GermainZ

unread,
Apr 10, 2013, 11:28:36 AM4/10/13
to tas...@googlegroups.com
Can you guys try this?
http://pastie.org/private/0khstnakrx0erb5rlvfca

Note that the timeout option is unlikely to actually work precisely (its output only updates every 4k of data or so), because of buffering, so try that at your own risk. :P

ScottS

unread,
Apr 10, 2013, 2:43:00 PM4/10/13
to tas...@googlegroups.com
Seems there's an error in the code; here's my output:

Catch by [n]umber of events or [t]imeout? >n
Events to catch? >100
Gonna catch 100 events!
Starting in...
3
2
10

Go!


could not get driver version for /dev/input/mice, Not a typewriter
/storage/sdcard0/Download/pastie-7428195.txt[49]: [--1: unexpected '['
/storage/sdcard0/Download/pastie-7428195.txt[49]: break: can't break

GermainZ

unread,
Apr 10, 2013, 2:57:51 PM4/10/13
to tas...@googlegroups.com
Forgot to remove two lines, was trying a few things.. Try this, please:
http://pastie.org/private/ij8zous5mvvjlumj6cwrq

If it doesn't work, change the first line from "set +x" to "set -x" and paste the output. Thanks.

ScottS

unread,
Apr 10, 2013, 4:20:02 PM4/10/13
to tas...@googlegroups.com
Error: could not get driver version for /dev/input/mice, Not a typewriter/storage/sdcard0/Download/pastie-7437125.txt[49]: [--1: unexpected '['

and when I changed '+x' to '-x', I receive an unknown set error.

GermainZ

unread,
Apr 11, 2013, 1:29:05 PM4/11/13
to tas...@googlegroups.com
Alright, try this please (download it, don't copy/paste its content):
https://www.dropbox.com/s/ugc9j6f1bqu0qw0/geteventsendevent.sh

ScottS

unread,
Apr 11, 2013, 2:00:45 PM4/11/13
to tas...@googlegroups.com
Error:

Catch by [n]umber of events or [t]imeout? >n
Events to catch? >2
Gonna catch 2 events!

Starting in...
3
2
1
0Go!


could not get driver version for /dev/input/mice, Not a typewriter
/storage/sdcard0/Download/geteventsendevent.sh[51]: [--1: unexpected '['

GermainZ

unread,
Apr 11, 2013, 2:30:40 PM4/11/13
to tas...@googlegroups.com
Try this (same link, modified script):
https://www.dropbox.com/s/ugc9j6f1bqu0qw0/geteventsendevent.sh

Also try changing the first line to "set -x" again (replace the plus "+" with a minus "-") if it gives an error, and run again.

ScottS

unread,
Apr 11, 2013, 2:47:58 PM4/11/13
to tas...@googlegroups.com
+x error:

Catch by [n]umber of events or [t]imeout? >n
Events to catch? >100
Gonna catch 100 events!

Starting in...
3
2
1
0
Go!

could not get driver version for /dev/input/mice, Not a typewriter
/storage/sdcard0/Download/geteventsendevent.sh[52]: [--1: unexpected '['

-x error:

+ printf %s > Catch by [n]umber of events or [t]imeout?
Catch by [n]umber of events or [t]imeout? >+ read type
n
+ printf %s > Events to catch?
Events to catch? >+ read arg
100
+ echo Gonna catch 100 events!
Gonna catch 100 events!
+ countDown getevent -t -c 100
+ echo Starting in...
Starting in...
+ i=4
+ :
+ [ 4 -lt 1 ]
+ i=3
+ echo 3
3
+ sleep 1
+ :
+ [ 3 -lt 1 ]
+ i=2
+ echo 2
2
+ sleep 1
+ :
+ [ 2 -lt 1 ]
+ i=1
+ echo 1
1
+ sleep 1
+ :
+ [ 1 -lt 1 ]
+ i=0
+ echo 0
0
+ sleep 1
+ :
+ [ 0 -lt 1 ]
+ break
+ printf %s\n\n\n Go!
Go!

+ getevent -t -c 100
+ reader
+ t2=-1
+ read -r t1 a b c d _
+ IFS=
+ grep -v -E add device|name:

could not get driver version for /dev/input/mice, Not a typewriter
+ t1=[
/storage/sdcard0/Download/geteventsendevent.sh[52]: [--1: unexpected '['

GermainZ

unread,
Apr 11, 2013, 2:55:39 PM4/11/13
to tas...@googlegroups.com
Ok, add this line:
echo $t1
Just after this line:
grep -v -E "add device|name:" | while IFS=' ' read -r t1 a b c d _; do
So it looks like this:
    grep -v -E "add device|name:" | while IFS=' ' read -r t1 a b c d _; do
        echo $t1
        t1=${t1%%-*}

And paste the output.

Thanks.

ScottS

unread,
Apr 11, 2013, 6:40:12 PM4/11/13
to tas...@googlegroups.com
Error:

Catch by [n]umber of events or [t]imeout? >n
Events to catch? >100
Gonna catch 100 events!
Starting in...
3
2
1
0
Go!

could not get driver version for /dev/input/mice, Not a typewriter
[
/storage/sdcard0/Download/geteventsendevent-1.sh[53]: [--1: unexpected '['


Keep it up...this type of script is something many of us would really like to have :-)

Rich D

unread,
Apr 11, 2013, 7:22:39 PM4/11/13
to tas...@googlegroups.com

Scott,  just to double check.. what command are you using in the terminal to run the file?

Rich..

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ScottS

unread,
Apr 11, 2013, 9:07:15 PM4/11/13
to tas...@googlegroups.com
I'm executing it as a script, using SD Manager in root mode, as recommended.

Rich D

unread,
Apr 11, 2013, 9:17:40 PM4/11/13
to tas...@googlegroups.com

> I'm executing it as a script, using SD Manager in root mode, as recommended.
>

I was actually asking if you were using the "exec sh" command to run the download file?

GermainZ

unread,
Apr 12, 2013, 4:38:59 AM4/12/13
to tas...@googlegroups.com
Alright, it should be an easy fix. I suspect it's outputting some line like this:
[ device ] something
And it's messing the script up. I don't know what it is exactly tho, so I'm gonna need your help first. ;)

Open a terminal emulator, run this command (and paste the output) and touch your device or something so it's fully executed:
getevent -c 1

Thanks.


@Rich D
It shouldn't matter as long as it's actually executing. I personally use ADB and run the script directly (e.g. "cd sdcard/Scripts; ./script.sh"), or a terminal emulator set to use bash instead of sh (bash provides auto-completion with the TAB key, which usually has a shortcut in the app such as pressing Vol Up + T).

ScottS

unread,
Apr 12, 2013, 10:08:49 AM4/12/13
to tas...@googlegroups.com
I initially attempted this in a basic emulator, however, I received permission errors; because the App wasn't running in root state?

This is from using the SD Manager Console. It seems to have recored some activity/events.

exec sh -c "cd '/storage/sdcard0' ; exec /system/bin/sh"
'/storage/sdcard0' ; exec /system/bin/sh" <
root@scorpion_mini:/storage/sdcard0 # getevent -c 1
add device 1: /dev/input/event5
name: "atmxt-i2c"
add device 2: /dev/input/event1
name: "light-prox"

could not get driver version for /dev/input/mice, Not a typewriter
add device 3: /dev/input/event4
name: "msm8960-snd-card Headset Jack"
add device 4: /dev/input/event3
name: "msm8960-snd-card Button Jack"
add device 5: /dev/input/event0
name: "keypad_8960"
add device 6: /dev/input/event2
name: "pmic8xxx_pwrkey"
/dev/input/event5: 0003 0035 00000135
root@scorpion_mini:/storage/sdcard0 #

easiuser

unread,
Apr 12, 2013, 10:15:44 AM4/12/13
to tas...@googlegroups.com
I am getting a similar error the Scott S gets:
/storage/primary/legacy/data/User/Scripts/TouchMacro.sh[50]: [--1: unexpected '['
/storage/primary/legacy/data/User/Scripts/TouchMacro.sh[50]: break: can't break

Per your request below getevent -c 1 returns:
add device 1: /dev/input/event5
  name:     "proximity"
add device 2: /dev/input/event4
  name:     "lightsensor-level"
add device 3: /dev/input/event3
  name:     "compass"
add device 4: /dev/input/event2
  name:     "spade-keypad"
add device 5: /dev/input/event1
  name:     "atmel-touchscreen"
add device 6: /dev/input/event0
  name:     "h2w headset"
/dev/input/event3: 0003 0002 000001e3

Hope this helps.

On Friday, April 12, 2013 3:38:59 AM UTC-5, GermainZ wrote:

TomL

unread,
Apr 12, 2013, 10:30:03 AM4/12/13
to tas...@googlegroups.com
@Scott, are you running the script on an emulated Android device, or on an actual Android device?

Tom

ScottS

unread,
Apr 12, 2013, 10:31:29 AM4/12/13
to tas...@googlegroups.com
On my actual, rooted device.

ScottS

unread,
Apr 12, 2013, 10:35:37 AM4/12/13
to tas...@googlegroups.com
It appears I'm not the only one who's having issues, so it's not how I'm trying to run the script, unless others are also improperly running the script.

With that said, how can we help Germain identify the issue herein?

Germain...what do you need to know from us, shell-related, to make appropriate edits to your code?

GermainZ

unread,
Apr 12, 2013, 11:25:23 AM4/12/13
to tas...@googlegroups.com
Alright, one more thing I thought of...
Try running this command and paste the output:
getevent -t -c 1

I'm pretty certain the way your getevent outputs the timestamps is different. On my device, it's something like:
15646-165468:
I'm guessing it's this on your device:
[ 15646-165468 ]

I should be able to fix it if I can know how it's shown for sure. Thanks.


Also, the reason you can't run scripts directly from the SD Card is because it's mounted as noexec. Copying the file to /tmp/, for example, allows you to execute it.

ScottS

unread,
Apr 12, 2013, 11:56:13 AM4/12/13
to tas...@googlegroups.com
Learning as I go :-) I discovered I needed to run 'su' in the terminal emulator first. Here's my output:

u0_a9@scorpion_mini:/ $ su
getevent -c 1
root@scorpion_mini:/ # getevent -c 1

add device 1: /dev/input/event5
name: "atmxt-i2c"
add device 2: /dev/input/event1
name: "light-prox"
could not get driver version for /dev/input/mice, Not a typewriter
add device 3: /dev/input/event4
name: "msm8960-snd-card Headset Jack"
add device 4: /dev/input/event3
name: "msm8960-snd-card Button Jack"
add device 5: /dev/input/event0
name: "keypad_8960"
add device 6: /dev/input/event2
name: "pmic8xxx_pwrkey"
/dev/input/event5: 0003 0035 0000033c
root@scorpion_mini:/ #

Script: I moved the script to the 'system' folder and ran it again:

Catch by [n]umber of events or [t]imeout? >n
Events to catch? >100
Gonna catch 100 events!
Starting in...
3
2
1
0
Go!

could not get driver version for /dev/input/mice, Not a typewriter
[
/tmp/geteventsendevent-1.sh[53]: [--1: unexpected '['

GermainZ

unread,
Apr 12, 2013, 12:02:58 PM4/12/13
to tas...@googlegroups.com
You forgot the -t switch:
getevent -t -c 1

ScottS

unread,
Apr 12, 2013, 12:06:47 PM4/12/13
to tas...@googlegroups.com
su
root@scorpion_mini:/ # getevent -t -c 1

add device 1: /dev/input/event5
name: "atmxt-i2c"
add device 2: /dev/input/event1
name: "light-prox"
could not get driver version for /dev/input/mice, Not a typewriter add device 3: /dev/input/event4
name: "msm8960-snd-card Headset Jack"
add device 4: /dev/input/event3
name: "msm8960-snd-card Button Jack"
add device 5: /dev/input/event0
name: "keypad_8960"
add device 6: /dev/input/event2
name: "pmic8xxx_pwrkey"
[ 41686.681852] /dev/input/event5: 0003 0035 0000012c
root@scorpion_mini:/ #

GermainZ

unread,
Apr 12, 2013, 1:15:50 PM4/12/13
to tas...@googlegroups.com
This one should work (still the same link):
https://www.dropbox.com/s/ugc9j6f1bqu0qw0/geteventsendevent.sh

The only problem that remains is that some people might get garbage output because some other device is active (e.g. compass), I'll fix that later (it will require user intervention, tho). You can fix it now as well by slightly modifying the script.

Let me know how it works out.

ScottS

unread,
Apr 12, 2013, 1:28:25 PM4/12/13
to tas...@googlegroups.com
Different error.

Catch by [n]umber of events or [t]imeout? > n
Events to catch? > 200
Gonna catch 200 events!

Starting in...
3
2
1
0
Go!

could not get driver version for /dev/input/mice, Not a typewriter
/tmp/geteventsendevent.sh[51]: 44657.135943--1: unexpected '.'

GermainZ

unread,
Apr 12, 2013, 1:37:06 PM4/12/13
to tas...@googlegroups.com
"set -x" please.
You can "sh /sdcard/geteventsendevent.sh" too if you prefer, instead of copying/running.

ScottS

unread,
Apr 12, 2013, 1:44:55 PM4/12/13
to tas...@googlegroups.com
error:

+ printf %s > Catch by [n]umber of events or [t]imeout?
Catch by [n]umber of events or [t]imeout? > + read type
n
+ printf %s > Events to catch?
Events to catch? > + read arg
200
+ echo Gonna catch 200 events!
Gonna catch 200 events!
+ countDown getevent -t -c 200
+ reader
+ t2=-1
+ getevent -t -c 200

+ read -r t1 a b c d _
+ IFS=
+ grep -v -e add device -e name:
+ sed -e s/^\[ // -e s/-/./ -e s/:// -e s/\]// -e s/.[0-9]* / /

could not get driver version for /dev/input/mice, Not a typewriter
/tmp/geteventsendevent.sh[51]: 45113.177547--1: unexpected '.'

GermainZ

unread,
Apr 12, 2013, 1:54:16 PM4/12/13
to tas...@googlegroups.com
Uhhh...

Try running this (make a new script): 
grep -v -e "add device" -e "name:" | sed -e "s/^\[ //" -e "s/-/./" -e "s/://" -e "s/\]//" -e "s/.[0-9]* / /" | while IFS=' ' read -r t1 _; do
    echo $t
done
 
Also paste the exact output of this command again (spaces do matter, make sure none are stripped):
getevent -t -c 4 | grep -v -e "add device" -e "name:"

GermainZ

unread,
Apr 12, 2013, 1:55:56 PM4/12/13
to tas...@googlegroups.com
Oh snap, forgot about regex for a bit there.
Replace this part before trying my suggestions above please:

-e "s/.[0-9]* / /"
With this:
-e "s/\.[0-9]* / /"

On Friday, April 12, 2013 8:44:55 PM UTC+3, ScottS wrote:

ScottS

unread,
Apr 12, 2013, 2:07:28 PM4/12/13
to tas...@googlegroups.com
I get a syntax error:

exec sh '/tmp/grep_test.txt'
rep_test.txt' <
/tmp/grep_test.txt[1]: syntax error: 'while' unmatched

GermainZ

unread,
Apr 12, 2013, 2:14:35 PM4/12/13
to tas...@googlegroups.com
You probably edited it wrong. Grab this:
https://www.dropbox.com/s/ugc9j6f1bqu0qw0/geteventsendevent.sh

ScottS

unread,
Apr 12, 2013, 2:25:58 PM4/12/13
to tas...@googlegroups.com
+set:
Catch by [n]umber of events or [t]imeout? > n
Events to catch? > 200
Gonna catch 200 events!
Starting in...
3
2
1
0
Go!


could not get driver version for /dev/input/mice, Not a typewriter
/tmp/geteventsendevent.sh[51]: 46506--1: -- requires lvalue

-set:
+ sed -e s/^\[ // -e s/-/./ -e s/:// -e s/\]// -e s/\.[0-9]* / /

+ grep -v -e add device -e name:
could not get driver version for /dev/input/mice, Not a typewriter
/tmp/geteventsendevent.sh[51]: 46683--1: -- requires lvalue

GermainZ

unread,
Apr 12, 2013, 2:54:12 PM4/12/13
to tas...@googlegroups.com
Try replacing (line 6):
t2=-1

With:
t2=0

easiuser

unread,
Apr 12, 2013, 3:07:26 PM4/12/13
to tas...@googlegroups.com
I am not getting the driver error but I do get

g.sh[51]: 36116--1: -- requires lvalue

Changing line 6 appears to have no effect.

GermainZ

unread,
Apr 12, 2013, 3:57:42 PM4/12/13
to tas...@googlegroups.com
Well, that doesn't make any sense to me.
"set -x", please?

easiuser

unread,
Apr 12, 2013, 4:42:45 PM4/12/13
to tas...@googlegroups.com
+ printf %s >  Catch by [n]umber of events or [t]imeout?
Catch by [n]umber of events or [t]imeout? > + read type
n
+ printf %s >  Events to catch?
Events to catch? > + read arg
5
+ echo Gonna catch 5 events!
Gonna catch 5 events!
+ countDown getevent -t -c 5
+ getevent -t -c 5
+ read -r t1 a b c d _
+ IFS=
+ sed -e s/^\[ // -e s/-/./ -e s/:// -e s/\]// -e s/\.[0-9]* / /
+ grep -v -e add device -e name:
g.sh[51]: 42121--1: -- requires lvalue
1|u0_a39@android:/sdcard/tmp #

GermainZ

unread,
Apr 12, 2013, 5:18:15 PM4/12/13
to tas...@googlegroups.com
Alright, posted an update... hopefully this will work. The link is still the same:
https://www.dropbox.com/s/ugc9j6f1bqu0qw0/geteventsendevent.sh
 
Thanks! :D

GermainZ

unread,
Apr 12, 2013, 6:45:59 PM4/12/13
to Tasker
http://db.tt/ngj2HjOP
Yet another quick update, processing should be faster now as well.

GermainZ

unread,
Apr 13, 2013, 4:46:59 PM4/13/13
to tas...@googlegroups.com
Huge update, check it out. :)
https://www.dropbox.com/s/ugc9j6f1bqu0qw0/geteventsendevent.sh

I also had a friend with a similar version of the problematic "getevent" test it, and according to him and his screenshots, it works.

James Davis

unread,
Apr 13, 2013, 7:44:19 PM4/13/13
to tas...@googlegroups.com

Hi thanks for all your work on this. It is unfortunately not working for me though. At this point I can't type in any input.

GermainZ

unread,
Apr 13, 2013, 8:09:56 PM4/13/13
to Tasker
Install busybox.
I'll add a check in the script later to make sure busybox and required
applets are installed.

On Apr 14, 2:44 am, James Davis <spjado...@gmail.com> wrote:
> <https://lh4.googleusercontent.com/-xxd1Fv5X7g4/UWntqmikjtI/AAAAAAAAAE...>

James Davis

unread,
Apr 13, 2013, 9:00:43 PM4/13/13
to tas...@googlegroups.com

I'm stupid thought I already had it installed. Lol. Ok now I can input but I am still getting an error.

easiuser

unread,
Apr 14, 2013, 1:56:23 PM4/14/13
to tas...@googlegroups.com
Thanks so much for all your hard work.  I finally got past all the syntax errors but it now seems to record events even if I don't touch the screen.  Sample output below.  Is this normal? If I start touching the screen I start getting "sendevent dev/input/event1" listings.

getevent -> sendevent converter by GermainZ

1. Catch events by number
2. Catch event with a custom timeout (BETA)
3. List input devices
4. Choose input device to monitor (default:all)
5. Info
6. Exit
Enter your choice [1 - 6] > 1

*****************************************************

Getting spam events? Check out option 4!
Events to catch? > 20
Gonna catch 20 events!

Starting in...
3
2
1
Go!

*****************************************************

sendevent /dev/input/event3    3     0    22
sendevent /dev/input/event3    3     1 4294967021
sendevent /dev/input/event3    3     2   632
sendevent /dev/input/event3    3    17   425
sendevent /dev/input/event3    3    10 4294966764
sendevent /dev/input/event3    0     0     0
sendevent /dev/input/event3    3     0    19
sendevent /dev/input/event3    3    16 4294966971
sendevent /dev/input/event3    3    17   438
sendevent /dev/input/event3    3    10 4294966777
sendevent /dev/input/event3    0     0     0
sendevent /dev/input/event3    3     1 4294967018
sendevent /dev/input/event3    3    16 4294966987
sendevent /dev/input/event3    3    17   452

GermainZ

unread,
Apr 14, 2013, 3:17:26 PM4/14/13
to Tasker
Busybox is supposed to symlink applets. Just replace "sed" by "busybox
sed" for now, I'll specifically call busybox in the next release.

On Apr 14, 4:00 am, James Davis <spjado...@gmail.com> wrote:
> <https://lh5.googleusercontent.com/-SPBkMz8b9-U/UWn_bTVWCTI/AAAAAAAAAE...>

GermainZ

unread,
Apr 14, 2013, 3:20:39 PM4/14/13
to Tasker
Check out option 4.

I've also posted the script on XDA BTW, if anyone is interested:
http://forum.xda-developers.com/showthread.php?t=2233865

ScottS

unread,
Apr 14, 2013, 5:16:40 PM4/14/13
to tas...@googlegroups.com
Seems it is catching way too many events.

I used option 4 to only grab screen touches (assuming event5 'atmxt-i2c' is my touch screen), and I get a tone of events. I only touch the screen a few times, yet I fill the results using as much as 500 events to catch; I still don't get to my planned 'Sleep' point. Example of output is below:

Events to catch? > 500
Gonna catch 500 events!


Starting in...
3
2
1
Go!

*****************************************************

sendevent /dev/input/event5    3    53   729
sendevent /dev/input/event5    3    54    10
sendevent /dev/input/event5    3    58    22
sendevent /dev/input/event5    3    50     2
sendevent /dev/input/event5    3    57     0
sendevent /dev/input/event5    0     2     0
sendevent /dev/input/event5    0     0     0
...



James Davis

unread,
Apr 14, 2013, 8:11:52 PM4/14/13
to tas...@googlegroups.com

Thanks for all your help so far. Iknow I'm becoming a nuisance lol. I get events registered while not touching anything and I'm still getting printf: not found.

easiuser

unread,
Apr 14, 2013, 9:38:43 PM4/14/13
to tas...@googlegroups.com
Thanks,

Working great.

GermainZ

unread,
Apr 15, 2013, 5:20:35 AM4/15/13
to tas...@googlegroups.com
Well, one screen touch with your finger = a whole lot of touches, because your finger moves and doesn't only touch one spot.
I'd suggest trying to figure out how many events are needed per actual exact touch (do that by copying the first 4 lines and testing, then the first 6 lines, then the 8 first lines, etc) and split what you want to do in multiple recordings, then put it all back together.

For example, if you want to: Press home button -> Touch the screen at one particular position -> Touch the screen at another position, you could do something like this:
1- Run the script and record the home button press; copy & save to some file.
2- Run the recording again and only touch the screen at the wanted position; only pick the necessary amount of events for one actual touch.
3- Do the same for the other touch.
4- Put the 3 pieces in one file & test it.

Hope it helps :)

GermainZ

unread,
Apr 15, 2013, 5:22:34 AM4/15/13
to tas...@googlegroups.com
Do the same for printf, then: replace all instances of "printf" with "busybox printf".
Also repeat this for any other commands that give you an error. I'd appreciate if you could make a list if any other commands need replacing and let me know (so far, sed & printf). :)

GermainZ

unread,
Apr 15, 2013, 3:10:29 PM4/15/13
to tas...@googlegroups.com
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. Check the XDA thread for more details about this.


As usual, the link is still the same:

https://www.dropbox.com/s/ugc9j6f1bqu0qw0/geteventsendevent.sh

James Davis

unread,
Apr 15, 2013, 6:43:40 PM4/15/13
to tas...@googlegroups.com

Ok with your latest update and a new install of busybox, I am not getting any errors. The problem now is I'm getting input without touching anything. Any idea why this might be?

GermainZ

unread,
Apr 16, 2013, 3:00:51 AM4/16/13
to Tasker
Use option 3 to list your devices, find the one you're interested in,
and use option 4 to only monitor that input device.
If in doubt, post option 3's output here.

BTW, the script already says "Getting spam events? Check out Option
4!", should I make that more obvious/visible or is the meaning/wording
not clear enough?

On Apr 16, 1:43 am, James Davis <spjado...@gmail.com> wrote:
> <https://lh4.googleusercontent.com/-vAcTp7y5rrE/UWyCiVH-cVI/AAAAAAAAAF...>
> Ok with your latest update and a new install of busybox, I am not getting
> any errors. The problem now is I'm getting input without touching anything.
> Any idea why this might be?
>
>
>
> On Monday, April 15, 2013 3:10:29 PM UTC-4, GermainZ wrote:
>
> > 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

ScottS

unread,
Apr 16, 2013, 1:36:50 PM4/16/13
to tas...@googlegroups.com
Is this more like a macro, or is each segment of events specific to that event, regardless of where it is?

I'm attempting to get the events for selecting 'None' on the Android Settings/Security/Screen Lock page. So, do I need to record how to get to the Screen Lock page as well, or do I just need the events on the Screen Lock page to select 'None'?


GermainZ

unread,
Apr 16, 2013, 1:48:23 PM4/16/13
to tas...@googlegroups.com
It's a stupid macro, it doesn't even know where you are in the first place, only that you're tapping the screen/using the phone's buttons :)

ScottS

unread,
Apr 17, 2013, 11:39:25 AM4/17/13
to tas...@googlegroups.com
@GermainZ: It's working well; thanks for script!



GermainZ

unread,
Apr 17, 2013, 12:30:56 PM4/17/13
to tas...@googlegroups.com
The old version was done in 15 minutes or so, I put some time into this one to make it newbie friendly, and more generally, easy to use. ;)
To run the script, either copy the script's content and paste it into Tasker's "Run Shell" action (newline characters are preserved, though the formatting will become weird), or put this in the "Run Shell" action:
sh /path/to/script
For example:
sh /sdcard/testscript.txt

On Wednesday, April 17, 2013 12:20:12 PM UTC+3, Jon Sherman wrote:
OK. so i have read through every comment and i have it working. I figured out how to select the text i want as far as the "touches" i wanna use. Now im just trying to figure out how to get it to run in Tasker. i made a testscript.txt with what i want it to run but how exactly do i get it to run in tasker??


btw, the old version was very confusing and this new update is VERY clear and easy ti pick up if you have never done any type of command line prompt. great job on this.

GermainZ

unread,
Apr 17, 2013, 12:32:09 PM4/17/13
to tas...@googlegroups.com
Good to know :D

Jon Sherman

unread,
Apr 17, 2013, 1:18:47 PM4/17/13
to tas...@googlegroups.com
Awesome! Got it working to do a few successful taps. Now the only thing is that some of the taps are holding. Like a long press. Do I need every line that it captures or only 1? Here is my send event script that taps 3 times but the last press is a long press:

sendevent /dev/input/event2 3 57 19725
sendevent /dev/input/event2 3 53 364
sendevent /dev/input/event2 3 54 1211
sendevent /dev/input/event2 3 50 13
sendevent /dev/input/event2 3 48 9
sendevent /dev/input/event2 3 49 6
sendevent /dev/input/event2 3 60 0
sendevent /dev/input/event2 0 0 0


sendevent /dev/input/event2 3 53 363

sendevent /dev/input/event2 3 50 12
sendevent /dev/input/event2 3 61 2
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 3 53 362
sendevent /dev/input/event2 3 50 14
sendevent /dev/input/event2 3 61 0
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 3 57 4294967295
sendevent /dev/input/event2 0 0 0
sleep 2
sendevent /dev/input/event2 3 57 19726
sendevent /dev/input/event2 3 53 44
sendevent /dev/input/event2 3 54 890
sendevent /dev/input/event2 3 50 16
sendevent /dev/input/event2 3 49 5
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 3 57 4294967295
sendevent /dev/input/event2 0 0 0
sleep 1
sendevent /dev/input/event2 3 57 19727
sendevent /dev/input/event2 3 53 683
sendevent /dev/input/event2 3 54 906
sendevent /dev/input/event2 3 50 11
sendevent /dev/input/event2 3 48 8
sendevent /dev/input/event2 3 60 5
sendevent /dev/input/event2 0 0 0
sendevent /dev/input/event2 3 53 681

Jon Sherman

unread,
Apr 17, 2013, 1:51:32 PM4/17/13
to tas...@googlegroups.com
Never mind! Figured it out Lol. I didn't have it capture enough events and it cut it short. Redid the capture and it works awesome now. Thank you thank you thank you!

ScottS

unread,
Apr 23, 2013, 12:57:31 PM4/23/13
to tas...@googlegroups.com
My phone received an OTA and the 'macros' created no longer function. It appears the script may need to be run again upon any phone OS updates.

ScottS

unread,
Apr 23, 2013, 1:30:29 PM4/23/13
to tas...@googlegroups.com
Disregard...I had forgotten to re-root after the OTA. After re-enabling root, the scripts worked :-)

GermainZ

unread,
Apr 23, 2013, 2:14:22 PM4/23/13
to tas...@googlegroups.com
The script itself doesn't need root (it only uses getevent), but sendevent does (the outputted script uses it).
Maybe I should add a warning if the user isn't rooted or something?

ScottS

unread,
Apr 23, 2013, 2:33:35 PM4/23/13
to tas...@googlegroups.com
Probably not a bad idea to mention root, especially for us generic users. If one could not execute the events, there wouldn't be much need to get them.

Manu Pinazo

unread,
May 11, 2013, 6:26:23 AM5/11/13
to tas...@googlegroups.com
Really nice script!
Dealing with getevent alone is quite a pain...

However, it would be nice if there was an option to automatically output the resulting script to a file in the sdcard...

GermainZ

unread,
May 11, 2013, 9:43:37 AM5/11/13
to tas...@googlegroups.com
I'll add that when I find some time to update the script :)

Jonathan Seymour

unread,
May 23, 2013, 6:23:16 PM5/23/13
to tas...@googlegroups.com
Legend.  I managed to figure out how to get this working last night, after about an hour of trying (I was only looking a the first page of this thread..)  

Cheers mate.
Reply all
Reply to author
Forward
0 new messages