How do i convert a key code captured with a KeyInputEvent to text?
:facepalm: For example by registering a listener like you tried to avoid in your last post that does System.out.println(“n”) when the “n” key is pressed. Please, don’t let us pull everything out of your nose and read this: http://www.mikeash.com/getting_answers.html This kind of post is utterly bad, what do you expect one to answer, seriously? What do you mean by “convert to text” anyway?
If this doesn’t help you:
Then you will have to ask better questions.
By converting to text I mean to get the key name in a string.For example, if you press SPACE BAR, then that method to return a new String(“SPACE BAR”)
The getKeyChar() return a char, not a string, and it work only for keys like “e”,“a”,"+"…
ve solved the problem mapping all keys like space bar, enter, delete etc in a HushMap and take the names from if the key name represent a string and not a char that getKeyChar() can return it.<br /> Sorry if sometimes you dont understand exactly what i want to mean, my english is not the best, and you don
t have to be sarcastic with the post<br /> <a href='http://www.mikeash.com/getting_answers.html '>http://www.mikeash.com/getting_answers.html </a> link...ive done researches before posting this and while the topic was up…
Anyway, thank you all. problem solved.
By converting to text I mean to get the key name in a string.For example, if you press SPACE BAR, then that method to return a new String("SPACE BAR")
In which language? There is no text representation for keys other than the ones you provide. After all, event the space bar could be "Space Bar", "Space", "Some foreign name", etc. Is the control key "Control" or "Ctrl", etc..
So the solution you came up with is really the only one since only you really know what the text should be.
Regarding asking good questions, don't take the link personally. Your initial question was vague and incomplete. If you'd included the information I quoted above in your first post you would have saved everyone a lot of time. So I think the "asking good questions" link was probably warranted. But I guess you may not have even read it.
off-topic, actually i did read it:)
you don`t have to be sarcastic with the post
I was not being sarcastic, why is everybody thinking I'm sarcastic all the time? ^^
Assuming you’re talking about jME3’s KeyEvent (and not AWT’s KeyInputEvent), then you can use the KeyNames class for that.