As a follow up to an article that I wrote "Programmatically Injecting Events on Android" (available on: http://www.pocketmagic.net/2012/04/injecting-events-programatically-on-android ), here's a bit of code in a form of a native library with a JNI wrapper to make things easier.
See the WIKI on https://github.com/radhoo/android-event-injector/wiki