FengJMEInputHandler Keyboard Handling Suggestion

I ran into a problem when using FengGUI within an applet.  Well, to be honest I've run into several, but this is the only one that I feel deserves commenting.



Problem:

When using a TextEditor in an applet the backspace, delete, tab, enter, arrow keys and more do not work.



Reason:

Keys are being improperly classified as regular letters.



In the FengJMEInputHandler there is a helper function called mapKeyEvent that translates the key code into a key classification for FengGUI.  The problem is that this function does not use the current input event, instead it calls directly to jlwgl's Keyboard.getEventKey() see below:



      public void performAction(InputActionEvent evt)
      {
         char character = evt.getTriggerCharacter();
         Key key = mapKeyEvent();
         if(evt.getTriggerPressed()) {
            keyHandled = disp.fireKeyPressedEvent(character, key);
            // Bug workaround see note after code
            if (key == Key.LETTER || key == Key.DIGIT)
               keyHandled = disp.fireKeyTypedEvent(character);
         } else
            keyHandled = disp.fireKeyReleasedEvent(character, key);
      }
 
      /**
       * Helper method that maps LWJGL key events to FengGUI.
       * @return The Key enumeration of the last key pressed.
       */
      private Key mapKeyEvent()
      {
         Key keyClass;
 
           switch(Keyboard.getEventKey())
           {



My recommendation is that the trigger index of the actual event be used instead as this is taken directly from the key code earlier during input handling.  The change would look like this:


      public void performAction(InputActionEvent evt)
      {
         char character = evt.getTriggerCharacter();
         Key key = mapKeyEvent(evt.getTriggerIndex());
         if(evt.getTriggerPressed()) {
            keyHandled = disp.fireKeyPressedEvent(character, key);
            // Bug workaround see note after code
            if (key == Key.LETTER || key == Key.DIGIT)
               keyHandled = disp.fireKeyTypedEvent(character);
         } else
            keyHandled = disp.fireKeyReleasedEvent(character, key);
      }
 
      /**
       * Helper method that maps LWJGL key events to FengGUI.
       * @param index
       * @return The Key enumeration of the last key pressed.
       */
      private Key mapKeyEvent(int index)
      {
         Key keyClass;
 
           switch(index)
           {



I tested this change with TextEditors in both applets and applications and it seems to work for them.

This seems like a change (if proper fix) that should be incorporated into the Wiki…

I needed to add this in the switch for my Tab key to work (switch text field focus):



case Keyboard.KEY_TAB:
    keyClass = Key.TAB;
    break;