Android Question Detect key press

Ayushjain

New Member
Hi...
I am not able to figure out how to start.
This will be a kind of service that starts only when a key is pressed using the keyboard (hard/soft), keep the service running till the keyboard (or the edit text box, in case of hard keyboard) is visible.
I have checked many threads that teach how to check if keyboard is visible, so no problem with this part.
And it should read the text that has been typed.

I am a novice developer in basic4android... I have good knowledge in visual basic, which is the reason why i chose B4A to code the application/service idea i have in mind.

Please help.. Thanks
 

Ayushjain

New Member
Hi Erel, Thanks for replying.
I want to catch key press only to start my service app (the key press acts as a confirmation that the keyboard and edittext are visible)
Is there any other way to know if the edit text is visible?
 
Upvote 0

ddahan

Member
Licensed User
Longtime User
Erel, I'm interested in the second part of your answer, is it possible when other applications are visible ?
 
Upvote 0

Ayushjain

New Member
Do you want to catch the key press in your activity or when other applications are visible?

Hi Erel,
I want to know a way that tells my service app to start whenever the edit text has focus... So i thought key press would be the best way... But if there is a better way, then pls tell me.
After my service app starts, it should be able to log the keys pressed and act accordingly...
Pls help, thanks
 
Upvote 0

enrique1

Member
Licensed User
Longtime User
Hi,

Can you please tell me how can I intercept keyboard key pressed in an Activity in foreground? I need it to alert about one issue. For instance, if "a" letter is pressed, a MsgBox would be showed.

Thanks!
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Can you give a little more background on how your app works? For instance, is the user typing something into an Edittext, and if they select letter "a" then msgbox is to be shown?
 
Upvote 0

enrique1

Member
Licensed User
Longtime User
Yep, I need to detect when "a", "s", "d", "w", "ctrl", "shift" and "space" are pressed in a webview in order to control an one online game. My latest post was a simple explanation to clarify the issue ^^.

Thanks for your answer JonPM
 
Upvote 0

enrique1

Member
Licensed User
Longtime User
Solved! Editing the online game, I can write with javascript the values in the HTML, then, I can trap them from the webview with WebViewExtras library.

Here you have the simple code ;) :

I've used WebViewExtras, exactly these methods:

B4X:
Dim aux As WebViewExtras

Sub Activity_Create(FirstTime As Boolean)
(...)
aux.addJavascriptInterface(WebView1, "B4A")
(...)
End sub

Sub WebView1_PageFinished (Url As String)
(...)
Javascript="B4A.CallSub('ProcessHTML', false, javascriptCodeHereToGetAValue")"
aux.executeJavascript(WebView1, Javascript)
(...)
End sub

Sub ProcessHTML(Html As String)
'Actions here
End Sub
 
Upvote 0
Top