B4J Question OnScreenKeyboard.jar

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
the attached file is a jar file that show a nice onscreenkeyboard.
It's a possible to make a lib or bas module from it?
A lib/bas where i can set the position (left and top), possibly also the dimensions
and show separately only the numeric keyboard, only alphabetical or both and use it in
a B4x code.
I decompiled the jar file and put all the classes in one section
(to try to use them inline java)

#If Java
......
#End If

When I compile this error appears:
B4X:
Compiling generated Java code.    Error
javac 1.8.0_212
src\b4j\example\main.java:4098: error: lambda expressions are not supported in -source 1.7
    EventQueue.invokeLater(() -> (new KeyboardUI()).setVisible(true));
                              ^
  (use -source 8 or higher to enable lambda expressions)
1 error

Thanks you all
 

Attachments

  • OnScreenKeyboard.jar
    198.3 KB · Views: 323

Daestrum

Expert
Licensed User
Longtime User
If you compile under Java 11+ the lambdas will compile.
If you need java 8, you will need to rewrite the lambdas as normal java code.

so as per your error the code
B4X:
EventQueue.invokeLater(() -> (new KeyboardUI()).setVisible(true));
would need to be rewritten like
B4X:
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            new KeyboardUI().setVisible(true);
        }
    });
 
Last edited:
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Ok, thanks Daestrum
but now other errors appear
B4X:
javac 1.8.0_212
src\b4j\example\main.java:124: error: unclosed character literal
  private 'static' boolean IS_NUM_LOCK_ON = false;
          ^
1 error
I don't have much practice with insertion and direct use of Java code, can you help me to use with B4J code the OnScreenKeyboard.jar?
Best regards
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
It should be private static, not private 'static'.
of course erel
in fact in the #If java region it is represented like this
but it shows that error
(and I think it will display more errors later)

B4X:
#If Java
import java.awt.AWTException;
import java.awt.Robot;

public class Keyboard {
  private static boolean IS_NUM_LOCK_ON = false;
 
  private static boolean IS_CAPS_LOCK_ON = false;
 
  private static boolean IS_SCROLL_LOCK_ON = false;
 
  private static boolean IS_SHIFT_PRESSED = false;
 
  private static boolean IS_CTRL_PRESSED = false;
 
  private static boolean IS_ALT_PRESSED = false;
 
  private static boolean IS_WIN_PRESSED = false;
 
  private static Robot robot = null;
 
  static {
    try {
      robot = new Robot();
    } catch (AWTException aWTException) {}
  }
 
  public static void typeKey(int keycode){
  ........
  ........

maybe I'm wrong something, I repeat I'm not practical in the use of In Line java
in the #If Java region I put all the classes that extracted from the OnScreenKeyboard file
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Little example without the need for inline java - needs javaobject library
B4X:
#Region Project Attributes 
    #MainFormWidth: 600
    #MainFormHeight: 600 
    ' wherever you put the jar file
    #AdditionalJar: c:\temp\OnScreenKeyboard.jar
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim kb As JavaObject
    Dim tf As TextField
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    tf.Initialize("tf")
    MainForm.RootPane.AddNode(tf,10,10,200,20)
    MainForm.Show
' create instance of the keyboard
    kb.InitializeNewInstance("com.codeforwin.projects.onscreenkeyboard.KeyboardUI",Null)
' show the keyboard
    kb.RunMethod("setVisible",Array(True))
    'Clicking on virtual keyboard will type into the textfield or whatever control has focus
    ' hide keyboard
    'kb.RunMethod("setVisible",array(false))
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Little example without the need for inline java - needs javaobject library
Ok, Thanks Daestrum ?
also with little elegance it could be done with a shell.
the reason for being able to use inline java it's because
I want to be able to change the position and more
or are there other possibilities?

Best regards
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
To set the position you can use
B4X:
kb.RunMethod("setLocation",Array(20,20)) ' set top/left at 20,20 on screen
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
To set the position you can use
B4X:
kb.RunMethod("setLocation",Array(20,20)) ' set top/left at 20,20 on screen
Thank you very much
I have not seen well what all the parameters that I can manage for the keyboard
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Most of the settings for the keyboard layout are defined private, meaning only the class should change them (with reflection you can override them), but a lot are also final variables, which means once it has been assigned a value it cannot be changed.
Changing the size of the keyboard is possible, unfortunately as the key layout is loaded, it is unaffected by any change of size of the keyboard.(You just get blank area at the right if you enlarge the keyboard, or lose keys if you shrink it).

Another option is to use the built-in fxkeyboard, just add this line to get the keyboard on-screen
B4X:
    #VirtualMachineArgs:  -Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.touch=True -Dcom.sun.javafx.virtualKeyboard=javafx
 
Last edited:
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Thank Daestrum
yes I have seen that many settings are under private sub.
I can't see how to change the keyboard size (also if it is stretched).
Another problem is that if I close the form of the keyboard without
activating the visible property = false, close also the application.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You will need to find this line in the java source
B4X:
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

and change it to

B4X:
setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
 
Upvote 0
Top