The slowness comes from followings.
- fork process to run sendevent command;
- open
/dev/input/eventX
- in sendevent_main()
- write event data to above file - in
sendevent_main()
;
- close the file - in
sendevent_main()
.
I got it faster by changing the sendevent_main()
as follows.
- open
/dev/input/eventX
;
- open the file with a list of events;
- create a loop and do followings
3.1 read the event one by one from above file
3.2 write the event one by one to `/dev/input/eventX'
- close files.
So in above changes, the event read and write is done in a loop without overhead ofopen
and close
for each event as before.
With this change, it is much faster to send event to /dev/input/eventX
.
But it brings in another problem, some events' behavior is NOT correct as expected. Is it sending event too fast to be handled by application?
I am still checking and changing the code, such as add usleep(10000)
between event sending. But it goes back to the original slowness.
Struggling.....