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...
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,
With these 3, OS will understand the input given by us and perform the action to the corresponding input.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
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).
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,
- Run it in the android shell.
- Should have root permission.
Recent Comments