2

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 Answers2

0

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

Mun0n
  • 4,438
  • 4
  • 28
  • 46
  • The issue is that the menu ie. the other commands added to the form do not respond...like I have a next command and info command apart from the cancel command...the menu is displayed well enough but the logic I placed with the commands does not get executed...thats why I was asking if its possible to explicitly call that logic from within the keyreleased method like check if the command pressed is next or info – user1513850 Nov 21 '13 at 16:21
  • did you try to set some functionallity to the keyReleased with the apropiate keyCode? – Mun0n Nov 21 '13 at 16:29
  • like in the example if I call function a() it works but I'm having an issue with the check to run for the softkey with the menu commands...let me give you an example 'if (evt.getCommand() == backCommand) { function a(); } else if (evt.Command == nextCommand) { function next(); } else if (evt.Command() == infoCommand) { function info(); }' – user1513850 Nov 21 '13 at 17:03
  • would like to have something like that in the keyreleased method have tried but haven't found any way of checking for command inside the keyreleased/pressed method – user1513850 Nov 21 '13 at 17:05
  • 1
    Set up buttons instead of commands and added the functionality to the softkeys...it works now thanks – user1513850 Nov 21 '13 at 19:02
0

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.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65