B4J Question Java for Send keys

Magma

Expert
Licensed User
Longtime User
Hi there...

For reading keys in java inline code using this:

B4X:
Sub KeyPressed_Filter (e As Event)

        Dim jo As JavaObject = e
        Dim EventType As String = jo.RunMethodJO("getEventType", Null).RunMethod("getName", Null)
        Log(EventType)

        Select Case EventType
            Case "KEY_PRESSED"
                Dim keycode As String = jo.RunMethod("getCode", Null)
                Log(keycode)
        end select

end sub

When sending... how is possible the same "capture/record" of keys to send... ?

This for example takes Control key as "CONTROL" is it possible to send as "CONTROL" and press control (not as int keycode) ?
which is the magic word... getCode --> SendCode... with robot...?
B4X:
Dim keycode As String = jo.RunMethod("getCode", Null)

Thanks in advance...
I do not want to use jnativehook for that.. only... is better to java inline if it is possible ofcourse...
 
Last edited:

Magma

Expert
Licensed User
Longtime User
Found a list with "int" and text (correspondence of getCode)
(is it the right list?)

So I will create a map... and search it every time i want to perform/produce a stroke..

But for the history isn't it a way to send it like you capture it ?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
You want to send keyinput to your own app?
no generally, at any app in foreground.

actually I want different routine for press... different for release... but if it is possible what i am capturing (for ex. CTRL)... to no need conversion... the same to send...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

I do not know a way without using this. I guess it is using jnativehook internally which you don´t want.
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
...hmm... let me "explain-and-reverse" the "stuff" I need...

First... well... I am getting the Text Explanation of key... with code of #1 post.

I have found a java code that Pressing and Releasing keys but with "int" code of keys ... :-( - I want to maximize compatibility between them ---> but one is text-explain and the other direct "int" code of key... :-(

For example: the java code of pressing key... to the foreground app (but with int)

inline java code that works...
B4X:
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
public class mykbclasses{
       public void KKeyPress(int ccode) {
            
               try {
               Robot robot = new Robot();
               
               robot.keyPress(ccode);
          
                 } catch (AWTException e) {
             e.printStackTrace();
         } 
}

scenario-1
I need to get the text-explain (i have this) and press with text-explain (i havent this)

scenario-2
I need to get "int" code of keys (not having that) and press with "int" code (i have that)

One of both scenarios will work for me...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…