Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 26, 2013 7:30 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: EditField.Callback()
PostPosted: Mon Aug 20, 2012 2:40 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
Code:
textInput.addCallback(new EditField.Callback() {
   public void callback(int key) {
      System.out.println("Received key: " +key);
      if (key == Event.KEY_GRAVE || key == Event.KEY_F12) {
         textInput.setText("BLAH");
         updateText("test");
         return;
      }
   }
});


If I hit 'grave' or any alpha character I get "Received key: 0", but F12 and other F keys return values > 0

The docs say : "key - One of KEY_NONE, KEY_ESCAPE, KEY_RETURN, KEY_DELETE". I'm not sure if I understand this, why not just pass in the real key instead of KEY_NONE? Why dot he F_XX keys work?

Is there any way to get that info without having to parse the input field?


Top
 Profile  
 
 Post subject: Re: EditField.Callback()
PostPosted: Mon Aug 20, 2012 5:50 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
The reson is backwards compatibility - Editfield has a setter which toggles this behavior: setForwardUnhandledKeysToCallback

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: EditField.Callback()
PostPosted: Mon Aug 20, 2012 5:10 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
hrm, I tried that, but doesn't seem to change behavior, I also tried false. ~ and V (or v) all return 0. F_12 and shift/return/delete return values:

Code:
private EditField textInput;
....
textInput.setMaxTextLength(40);
textInput.setForwardUnhandledKeysToCallback(true);
textInput.setAutoCompletionOnSetText(false);
textInput.addCallback(new EditField.Callback() {
   public void callback(int key) {
      System.out.println("Key: " + key);
      if (key == Event.KEY_GRAVE || key == Event.KEY_V || key == Event.KEY_F12) {
         textInput.setText("BLAH");
         return;
      }
   }
});


I have TWL.jar from website from about a week ago. I also tried to set it inside the call back it's self with same affect.


Top
 Profile  
 
 Post subject: Re: EditField.Callback()
PostPosted: Mon Aug 20, 2012 6:21 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
You get only a key != 0 when an unhandled key is pressed. Keys which are added to the text all send a key == 0, this can't be easily changed. Why do you need that?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: EditField.Callback()
PostPosted: Mon Aug 20, 2012 7:42 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
MatthiasM wrote:
You get only a key != 0 when an unhandled key is pressed. Keys which are added to the text all send a key == 0, this can't be easily changed. Why do you need that?


Basically if they hit the grave key (tilde) I'd like to hide the window. Right now it takes it into the input field.


Top
 Profile  
 
 Post subject: Re: EditField.Callback()
PostPosted: Mon Aug 20, 2012 8:13 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
Well - you shouldn't do that via the EditField's callback anyway - do that in the parent widget/window. Like this:
Code:
public boolean handleEvent(Event evt) {
   if(evt.getType() == Event.Type.KEY_PRESSED && evt.getKeyCode() == Event.KEY_GRAVE) {
      // hide window
      return true;
   }

   if(super.handleEvent(evt))
      return true;

   // handle other events
   return false;
}
The super.handleEvent() will pass the keyboard events to the currently focused children.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: EditField.Callback()
PostPosted: Mon Aug 20, 2012 9:34 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
ok, this works very well. thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group