Softbuttons not responding after overriding keypressed and keyreleased

49 views Asked by At

I am developing an application that requires me to override keypressed and released methods in lwuit so as to map specific functons into gamekeys.

The gamekeys work fine when I do this but I'm having trouble adding more than two commands to application. Normally actionlistener would automatically handle the mapping of multiple commands but it does not.

Is it possible to map more than one command to a softkey (like with keycode -7) and have an if statement to dynamically check which command is pressed.

 public void keyReleased(int keyCode) {

      switch (keyCode) {
        case -6: // left cmd key
             function a();
            return;
        case -7: // right cmd key
//Need this to handle more than one command function

            return;

    }
   //function to handle gamekeys
}

Hope I am clear enough with my issue. Please help

2

There are 2 answers

5
Mun0n On BEST ANSWER

In my opinion what you wanna do is not possible. There are always a cancel command in a softkey and the menu (if there are more than one command added) in the other softkey.

To get the correct keyCode, to set another funtionallity to the softkey you should get the correct keyCode. Make a System.out.println("keycode " + keyCode); before the first line in the method keyReleased

0
Shai Almog On

You need to replace the MenuBar class if you want to do custom key/menu handling. Just subclass the MenuBar and define your new class within the LookAndFeel.