Throwing/Simulating KeyStrokes programatically

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby mandroid » Tue Apr 27, 2010 1:56 pm

hmm,

ok i see it's not possible, thats a pitty for me. I guess it has something to do with the sandbox-principle of Android, right?

nevertheless thank you for the response(s)!

greetings

mandroid
mandroid
Freshman
Freshman
 
Posts: 8
Joined: Tue Apr 27, 2010 8:47 am

Top

Re: Throwing/Simulating KeyStrokes programatically

Postby jeffreyaustinwhite » Tue Jul 06, 2010 8:32 pm

Anybody have an idea of how this might work in Android 2.2. This platform no longer supports IWindowManager and KeyPress.isDown() etc... I am really struggling to get this to work in the latest platform.

-Jeffrey Austin White
jeffreyaustinwhite
Freshman
Freshman
 
Posts: 2
Joined: Tue Jul 06, 2010 8:30 pm

Re: Throwing/Simulating KeyStrokes programatically

Postby jeffreyaustinwhite » Tue Jul 06, 2010 8:35 pm

Anybody have any idea how this might be programmed for Android 2.2. This platform does not support iWindowManager or KeyEvent.isDown() etc... I am really struggling to get a handle on this in the latest platform.

Thanks,
-Jeffrey Austin White
jeffreyaustinwhite
Freshman
Freshman
 
Posts: 2
Joined: Tue Jul 06, 2010 8:30 pm

Re: Throwing/Simulating KeyStrokes programatically

Postby sonic » Fri Jul 09, 2010 8:55 am

jeffreyaustinwhite wrote:Anybody have any idea how this might be programmed for Android 2.2. This platform does not support iWindowManager or KeyEvent.isDown() etc... I am really struggling to get a handle on this in the latest platform.

Thanks,
-Jeffrey Austin White


HI:
Code: Select all
  private void sendKeyEvent(String event) {
  int eventCode = Integer.parseInt(event);
  long now = SystemClock.uptimeMillis();
  Log.i("SendKeyEvent", event);
  try {
  KeyEvent down = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, eventCode, 0);
  KeyEvent up = new KeyEvent(now, now, KeyEvent.ACTION_UP, eventCode, 0);
  (IWindowManager.Stub
  .asInterface(ServiceManager.getService("window")))
  .injectKeyEvent(down, true);
  (IWindowManager.Stub
  .asInterface(ServiceManager.getService("window")))
  .injectKeyEvent(up, true);
  } catch (RemoteException e) {
  Log.i("Input", "DeadOjbectException");
  }
  }

you can find this source from [/frameworks/base/cmds/input/src/com/android/commands/input/Input.java].Though google does't support this any longer,you can use it and make the source successfully.I have't tried it yet,but i have heared somebody have prove it. :D
sonic
Freshman
Freshman
 
Posts: 3
Joined: Fri Jul 09, 2010 8:45 am

Re: Throwing/Simulating KeyStrokes programatically

Postby Da1duc » Tue Dec 21, 2010 3:32 pm

Here is a way to push key events:

http://dqminh.com/simulate-back-action-in-android#comment

This seems to be local only to the application (i.e. not at the system level). Thought it might be useful for some.

D
Da1duc
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Dec 21, 2010 3:05 pm

Re: Throwing/Simulating KeyStrokes programatically

Postby adithi » Wed Dec 29, 2010 5:54 am

can i simulate power button? :?
Last edited by adithi on Wed Dec 29, 2010 10:54 am, edited 1 time in total.
adithi
Freshman
Freshman
 
Posts: 3
Joined: Mon Dec 27, 2010 1:27 pm

Top

Re: Throwing/Simulating KeyStrokes programatically

Postby adithi » Wed Dec 29, 2010 10:51 am

hi,
your tutorials are very useful.in this i have doubts.What about IWindowManager and ServiceManager in this program.it shows that these cannot be resolved.is it an user defined class or interface.i have to simulate power button and lock the phone.is it possible.Please guide me :cry:
adithi
Freshman
Freshman
 
Posts: 3
Joined: Mon Dec 27, 2010 1:27 pm

Re: Throwing/Simulating KeyStrokes programatically

Postby iLikeAndroid » Thu Jul 07, 2011 12:11 am

Hi plusMinus,

I know I am posting on a very old post...

But I want to use the approach you have suggested here...
but I think we do not have access to IWindowManager or ServiceManager as a developer.

I am using Ginger Bread and want to send key events to the top application from my service. Is this possible.

Regards
Girish
iLikeAndroid
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Jul 07, 2011 12:06 am

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests