TextField inputs

Hello,



i have a chat panel and a text field that contains new messages to be send

i need to input ‘@’ to adress players by nickname

is it possible to input those chars ?

does not seem to be



here, inputEvent always is null for @

Code:
TextField messageToSend = screen.findNiftyControl("messageToSend", TextField.class); messageToSend.getElement().addInputHandler(new KeyInputHandler() { @Override public boolean keyEvent(NiftyInputEvent inputEvent) { if(inputEvent==null) return false; if(inputEvent.toString().equals("SubmitText")) SendMessage(); return false; } });

thx
1 Like

This works for me using the 1.3 controls demo on the Nifty GUI blog using native LWJGL. I can input the @ character in the textfield without any problems o_O



If you really can’t input the @ character in a regular textfield - one where you didn’t mess with the InputHandler :slight_smile: - then we’ll need to track down this problem to the JME InputDevice implementation and we’ll need to check if the @ character ever appears somewhere in the InputSystemJme class inside Jme.





Besides this the problem with your “addInputHandler()” messing is that this is simply not enough. What’s missing is the inputMapping that actual takes a raw keyboard event and translates it into a NiftyInputEvent. Setting the inputMapping from Java is not supported right now from code as far as I see. You’ll need to set this when the element/control is created. I suggest reading page 71-73 of the Nifty manual for more details if you’re interessted in that sort of special processing.



A simple @ character should really work. Someone else having trouble to enter a @ character into a Textfield using JME? o_O

I just tried, can type @fsdf@ into a TextField…can even cut and paste it out to here :stuck_out_tongue:



The @ symbols appeared in the string inside the code when I queried the text on the field as well.

1 Like

thanks @zarch :slight_smile:



maybe you’re using a font @rompelstilchen without the @ character? o_O

@void256:

I have a problem which not directly related to @ character but I want to listen to every keyboard event in a Textfield to make a Keyboard customization UI for my game.



Eg: So if I want “Duck” bound to Ctrl Key, I want the Textfield listen to that Key…



You know I read the Manual, and don’t find a work around in Nifty so for now I have to use JME Input manager to listen to whole keyboard event of the system.



Then simply put the Label “Ctrl” to the Textfield when JME’s registered ActionListener got the event.

But I still want to capture every keyboard event fired from the Textfield, can you tell me how?

@void256 said:
This works for me using the 1.3 controls demo on the Nifty GUI blog using native LWJGL. I can input the @ character in the textfield without any problems o_O

If you really can't input the @ character in a regular textfield - one where you didn't mess with the InputHandler :) - then we'll need to track down this problem to the JME InputDevice implementation and we'll need to check if the @ character ever appears somewhere in the InputSystemJme class inside Jme.


Besides this the problem with your "addInputHandler()" messing is that this is simply not enough. What's missing is the inputMapping that actual takes a raw keyboard event and translates it into a NiftyInputEvent. Setting the inputMapping from Java is not supported right now from code as far as I see. You'll need to set this when the element/control is created. I suggest reading page 71-73 of the Nifty manual for more details if you're interessted in that sort of special processing.

A simple @ character should really work. Someone else having trouble to enter a @ character into a Textfield using JME? o_O



i use the latest sdk version so ....
weird indeed, sometimes the game starts, i can't input anything
sometimes, as i type some letter, it seems to do a paste of what is in the clip board (but the ctrl key is not stuck down on the keyboard)
other times, it works great, i'll dig it out
thx for your answers

@atomix:

This can be done with a custom control. In fact this has been done by lefty2shoes (marc f.) for the game xspace some years ago already:

http://lefty2shoes.com/blog/images/new_fe02.png



Unfortunately I can’t for the f*** of it find the source of this xspace specific control right now :confused: But I’ll ask Marc if he wants to donate it as a standard control since this feature seems to be requested quite regulary :slight_smile:



You can try to build your own of course which is not that difficult. You might want to read or re-read the pages 71-73 of the manual. You’ll need to implement your own NiftyInputMapping for this. You basically need to map every key and translate it into a NiftyInputEvent (probably just storing the key in the character member of the NiftyInputEvent). In the Nifty Controller class of your custom control you get access to the NiftyInputEvent (and with it to the original character/key) and then you can do whatever you want with the key. The only thing that is left to do is to add some kind of state management to your control, so that it gets activates with the return key is pressed and will “listen” for the next key input event to record the key and display it in the field.



It bugs me that exact this behaviour already exists in the world as a control somewhere. But as I’ve said, maybe this control can resurrect and come back … :slight_smile:

1 Like

Yes, it’s definitely what I want to do! The idea of Mapping come to me at first but since the Textfield control has some similar feature, I used it. OK, let me have some days, I 'll make that KeyCaptureControl again :stuck_out_tongue: