Android Input Device Events

Hi friends,

I have got task dealing with touch monitor. I have to implement multitouch in our project. In the middle, I wanted to see input events. My teammate gave me the keyword to see the input event and to manually send input event to any devices. I would like to put it here. So, Me and You can refer, when we want it...

Android getevent and sendevent 

ya, as you guess...
  • getevent is to read the input event from the device(/dev/input/device-name) and
  • sendevent is to write the input event to the device(/dev/input/device_name) manually
Before, the getevent and sendevent... Lets have a brief look into the input event...
Input Event : Basically inputs are written has (sequence of ) events in the device(/dev/input/event(device) in case of Linux). All input events comprise of three values namely,
  • Type  : type of the event like Key, Sync, Misc, LED, etc.
  • Code  : value corresponding to the key, which is pressed.
  • Value : Zero for release and One for click/press, in case of key press and mouse click event. some running number in other case( I don't have too much knowledge in it).
With these 3, OS will understand the input given by us and perform the action to the corresponding input.
 
Example : when we press key 2 in the keyboard... event sequence will be like the below

In ubuntu,  (I wrote a c program to read the input even from device and the output is below)
Event: type 4 (Misc), code 4 (ScanCode), value 458783   [Conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 1                             [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]
Event: type 4 (Misc), code 4 (ScanCode), value 458783    [conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 0                             [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]

In andriod,
Event: type 1 (Key), code 3 (2), value 1                             [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]
Event: type 1 (Key), code 3 (2), value 0                             [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]

This is for pressing the key 2 once... This will be written into the device, OS will read it and perform the actions.

ok now...

getevent : will print the event written into the device.
syntax    : getevent device
example : getevent /dev/input/event0
output    :  In android, it didn't say the scancode... but all the inputs are handled as scancodes. output is,
0001 0003 00000001
0000 0000 00000000
0001 0003 00000000
0000 0000 00000000

sendevent : will allow us to give the input in the terminal.
syntax       : sendevent device type code value.
example    : for writing key 2 into the device.
shell@android:/ # sendevent dev/input/event0 0000 0000 00000000
shell@android:/ # sendevent dev/input/event0 0001 0003 00000001
shell@android:/ # sendevent dev/input/event0 0000 0000 00000000
shell@android:/ # sendevent dev/input/event0 0000 0000 00000000


P.S. : Remember the two points below,

  1.  Run it in the android shell.
  2.  Should have root permission.


4 comments:

Unknown said...

Hi,nice to find your blog about android input device. I'm a android driver developper, a freshman. Can you give me your c program which publish the process of pressing event?? I'm trying to connect some capacitive buttons with HOME, BACK, MENU in the app. thanks a lot.
ming.zhao@hotmail.fr

ALAGAPPAN said...

Hi Zhao ming, I regret that I can't share any program...

I just explained about getevent and sendevent, which is already there in the android to read and write in the input device.

sendevent source - http://androidxref.com/4.2.2_r1/xref/system/core/toolbox/sendevent.c

getevent source -
http://androidxref.com/4.2.2_r1/xref/system/core/toolbox/getevent.c

I feel, you will get your way to publish pressing event in sendevent source.

satish saley said...

Nice post.
Still I am confused about actual meaning of these three columns in getevent

0001 0003 00000001
0000 0000 00000000
0001 0003 00000000
0000 0000 00000000

ALAGAPPAN said...

Satish saley,

getevent will read the dev and show us the input in the form : type(of input), code(of the key), value.

Type of input - whether keyboard event, mouse event, touch event, so on.
Code of input - scancode of the key pressed - keyboard event, x/y axis/ move & click for mouse, x/y axis/click for touch, so on
value - pressed/released for keyboard, x/y value for mouse and touch, so on.

0001 - EV_KEY -> It is key(board) event.
0003 - KEY_2 -> It is Number key 2.
0001 - Pressed.

0000 0000 0000- EV_SYN -> It is SNYC event. TO say the OS that the events are written, you can take and proceed further.
So OS will understand, Number key 2 is pressed.

0001 - EV_KEY -> It is key(board) event.
0003 - KEY_2 -> It is Number key 2.
0000 - Released.

0000 0000 0000- EV_SYN -> It is SNYC event. TO say the OS that the events are written, you can take and proceed further.
So OS will understand, Number key 2 is released.

Check this file for more input about type/code/value : http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/input.h?v=2.6.11.8

Newer Post Older Post Home

About Me

My photo
Hi everyone,myself Alagappan...electronic and communication engg. student... living in madurai... interested in everything... want to achieve something great in my lifetime...

Followers


Recent Comments