B4J Question Create Custom Shortcut Key

cambopad

Active Member
Licensed User
Longtime User
Hi all!

How can I create custom shortcut keys for my program made with B4J to do something when the user pressed the combination of keys?
For example, if the users pressed Ctrl+O, I want to show a form or just do something that I want.

Can anyone share me some tips?
 

Cableguy

Expert
Licensed User
Longtime User
You can use a menubar wich can integrate combo keys shortcuts like the one you mentioned... Or try to catch the form keys pressed events and figure out wich keys were pressed
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
needs javaobject library
B4X:
Sub Process_Globals
  Private fx As JFX
  Private MainForm As Form
  Dim otherform As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
  MainForm = Form1
  MainForm.Show
  asJO(Me).RunMethod("doWindow",Array(asJO(MainForm).GetFieldJO("stage")))
End Sub

Sub myevent_newwindow
  otherform.Initialize("",200,200)
  otherform.show
End Sub

Sub asJO(o As JavaObject) As JavaObject
  Return o
End Sub

#if java
import javafx.scene.input.KeyCode;
import javafx.stage.Stage;
import javafx.scene.input.KeyEvent;
import javafx.event.EventHandler;
import anywheresoftware.b4a.keywords.Common;

public static void doWindow(Stage stage){
stage.addEventHandler(KeyEvent.KEY_PRESSED,new EventHandler<KeyEvent>(){
     @Override public void handle(KeyEvent keyEvent){
       if (keyEvent.isAltDown() && (keyEvent.getCode() !=KeyCode.ALT)){
         if (keyEvent.getCode() == KeyCode.W){ // ALT W for new window
           System.out.println("Alt + " + keyEvent.getCode());
           keyEvent.consume();
           ba.raiseEventFromUI(this, "myevent_newwindow", null);
          }
        }
      }
    }
  );
}
#end if
 
Upvote 0
Top