What I would try is to create a KeyEvent object and dispatch it to the
UI thread.
Something like this (I haven't tried this; code below only to sketch
this up on the conceptual level):

KeyEvent.Callback callbackReceiver = new KeyEvent.Callback(...) { //
callback code };
KeyEvent.DispatcherState dispatcherState = new
KeyEvent.DispatcherState(...);
myMainActivity.runOnUiThread(new Runnable() { public void run() { new
KeyEvent(KeyEvent.ACTION_UP, KEYCODE_MENU).dispatch(callbackReceiver,
dispatcherState, null); } } ) ;

The KeyEvent defines keycode and action (key up on MENU in the
example). Dispatch it and callbackReceiver should be called.
But not so fast... I recommend to synchronize this through the event
loop using runOnUiThread. That way, you serialize your "custom"-event
with key events that are generated by the user.



On Feb 14, 1:26 am, saru <sarucs...@gmail.com> wrote:
> Hey i want to write a program in android to press  menu button or end
> button or answer button automatically. Please help me if you can.
> though i got some links 
> likehttp://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/
> BUT i am getting error because of using import
> android.os.ServiceManager; and import android.view.IWindowManager; as
> this packages can not be resolved

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to