Simulate KeyPress event

madSac

Active Member
Licensed User
I wanted to send input from my application...say input in contact menu or currently active textbox.I searched this forum but found nothing.

Again i found something interesting in google Simulating keypress events on Android | The Code Artist
I think it need shell access.Can anyone tell how to use it ? and any specific condition that it will work or not work ?
I think it need root access then how check if device can provide root access ?

I found that lib named as CMD to run shell commands ..but it didnot work in all devices !

Please suggest a way...to acquire what i need.
 

Informatix

Expert
Licensed User
I wanted to send input from my application...say input in contact menu or currently active textbox.I searched this forum but found nothing.

Not surprising. It is prohibited by Google. For security reasons, you're not allowed to send keys programmatically to other apps.

Again i found something interesting in google Simulating keypress events on Android | The Code Artist
I think it need shell access.Can anyone tell how to use it ? and any specific condition that it will work or not work ?
I think it need root access then how check if device can provide root access ?

I found that lib named as CMD to run shell commands ..but it didnot work in all devices !

Please suggest a way...to acquire what i need.

From an ADB console, you can send any key you want (and that's very useful when your screen is broken) but this console is on the PC side, not on the phone side.
With non-rooted devices, I'm almost certain there's no possibility to do it from the device (or it's a security leak and it will be fixed in the next Android release). On rooted devices, there are existing hacks (event injections) but I won't give you links because I don't support that. If you're doing an app just for you on your rooted phone, you'll find everything needed by using the Google search engine. ;)
 
Upvote 0

madSac

Active Member
Licensed User
Not surprising. It is prohibited by Google. For security reasons, you're not allowed to send keys programmatically to other apps.



From an ADB console, you can send any key you want (and that's very useful when your screen is broken) but this console is on the PC side, not on the phone side.
With non-rooted devices, I'm almost certain there's no possibility to do it from the device (or it's a security leak and it will be fixed in the next Android release). On rooted devices, there are existing hacks (event injections) but I won't give you links because I don't support that. If you're doing an app just for you on your rooted phone, you'll find everything needed by using the Google search engine. ;)
Probably i wanted to release and application for public.I thought that google would have provided API.
So,How these virtual keyboard work ?
 
Upvote 0

madSac

Active Member
Licensed User
So can I make an application which is always at top of all applications but covers very less area ? So that it will be always at top and active and then it can send keypress event.
 
Upvote 0

Informatix

Expert
Licensed User
So can I make an application which is always at top of all applications but covers very less area ? So that it will be always at top and active and then it can send keypress event.

No, because the reason is still that you cannot send key events to other apps.
You can do an Input Method (probably not with B4A) but that will replace the keyboard and can be annoying if a keyboard is needed. And as any Input Method, it needs user actions to install it and send keys.
 
Last edited:
Upvote 0

madSac

Active Member
Licensed User
It will be much better to leave the idea as designing a better keyboard will become primary and other primary features will go secondary.
By the way thank you.....
 
Upvote 0

Informatix

Expert
Licensed User
Why you stated this ? Can't i make a system application using B4A ?

Creating a system app only makes sense if you run your app on a rooted device. An Input Method is not a system app and is a lot easier to code in Java than in B4A. Please read the link I provided. The first line says:
To create an input method (IME) for entering text into text fields and other Views, you need to extend android.inputmethodservice.InputMethodService.
 
Upvote 0
Top