Android, writing events low level touch screen automated shell test, part #1

Hello everybody,

Some information I have already covered in the article:
How to click screen using shell script (Froyo)
– In the beginning of this article you will find how to reproduce click for before Froyo Android

So lets start from the beginning, for implementation of automated test you need only 2 simple and essential shell commands:

~$ adb shell getevent
~$ adb shell sendevent $device $command $argument $value

First command is dumping all events from all interfaces (usually /dev/input/event0-4) in real time into the terminal output. For high usability you can use grep with regular expression to set a filter for output (it is so useful because of there are a lot of events out of our interest) for example, we need to trace only touch interface events:
— Assume /dev/input/event2 is a touch screen interface

~$ adb shell getevent | grep event2

or we need to get only click coordinates:

~$ adb shell getevent | grep event2: 0003 003[56]

By this way we can very simply determinate UI elements position at the screen! Sure, after we will conver hexa values of getevent to the decimal ๐Ÿ™‚ For this you can use a pretty nice online tool with various converters on the board: easy calculation converter
For checking consistency of your regular expressions, you are using with grep command, you are welcome to use: my favourite regexpal, sure you can use your favourite tools ๐Ÿ™‚

Okay, lets try to determinate what roadblocks you may have firing this commands:
1. “adb is not a command” or something like this
– Check in what folder you are, and change it to the …/android_sdk_location/tools
– adb (Android debug bridge) is situated here

2. “adb server is not running” or something like this
– try to start adb daemon using command adb start-server

3. You have fired an event, all was properly set, but nothing happens!
– Make sure you are not using HEXA args/values, when you are using sendevent command
– you must specify all data in the decimal format (0-9)

Let me provide you with some examples:

~$ adb shell getevent | grep event2

-> I’m doing single tap on the screen

Following events sequence will be dumped:

/dev/input/event2: 0003 0030 00000068
/dev/input/event2: 0003 0032 0000000a
/dev/input/event2: 0003 0035 0000022e
/dev/input/event2: 0003 0036 00000039
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0003 0012 0000002f
/dev/input/event2: 0003 0014 00000001
/dev/input/event2: 0000 0000 00000000
/dev/input/event2: 0003 0030 00000000
/dev/input/event2: 0003 0032 0000000a
/dev/input/event2: 0003 0035 0000022e
/dev/input/event2: 0003 0036 00000039
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0003 0012 00000020
/dev/input/event2: 0003 0014 00000000
/dev/input/event2: 0000 0000 00000000

Okay, now we can analyse it and determinate what these numbers mean:

1. Finger is touching the screen:
/dev/input/event2: 0003 0030 00000068
/dev/input/event2: 0003 0032 0000000a

2. At screen coordinates:
/dev/input/event2: 0003 0035 0000022e
/dev/input/event2: 0003 0036 00000039

3. Still not recognized part, but I assume it describes number of pointers and its ID:
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0003 0012 0000002f
/dev/input/event2: 0003 0014 00000001

4. Pure event separator:
/dev/input/event2: 0000 0000 00000000

5. Finger is releasing the point at the screen:
/dev/input/event2: 0003 0030 00000000
/dev/input/event2: 0003 0032 0000000a

6. At the screen position:
/dev/input/event2: 0003 0035 0000022e
/dev/input/event2: 0003 0036 00000039

7. Not recognized series, possibly describing number of touches and ID of the current touch:
/dev/input/event2: 0000 0002 00000000
/dev/input/event2: 0003 0012 00000020
/dev/input/event2: 0003 0014 00000000

8. Pure event separator, always should close events sequence
/dev/input/event2: 0000 0000 00000000

So what information can we extract from these dump?
A lot of information! ๐Ÿ™‚

1. How to set X,Y coordinate of the click:
/dev/input/event2: 0003 0035 0000022e
/dev/input/event2: 0003 0036 00000039

Convert it to decimal and you will get the valuable ids:
Where 0003 53 and 0003 54 set x and set y commands
accordignaly. 558 is X, 57 is Y, to reproduce it you can
send these events:

~$ adb shell sendevent /dev/input/event2 0003 53 558

~$ adb shell sendevent /dev/input/event2 0003 54 57

2. I think it will be interesting for you to reflect other events
by yourself ๐Ÿ™‚ Please let me know if you do not succeed to do
something yourself.

INFO: Click all params decoded. Shell script sample.

PART 2: implementing simple shell script with ClickOnScreen(x,y) function.

Happy clicking (:

Best regards,
Yahor