LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: fellowusertoo on July 23, 2011, 15:12:08

Title: [FIXED] Unicode input
Post by: fellowusertoo on July 23, 2011, 15:12:08
Keyboard.getEventCharacter() keeps returning ? whenever a unicode character is typed in.


char c = Keyboard.getEventCharacter();
System.out.println((int)c); // if this is a unicode character, it will keep printing 63 (which means ?)

char c = (char)29233; // Chinese letter "爱"
System.out.println((int)c); // in this case, it prints 29233 (which is correct).


How can I get unicode input (especially, Chinese characters)? Thanks in advance.
Title: Re: Unicode input
Post by: Matzon on July 23, 2011, 15:54:05
At this point, I think your best bet is to dig into the code, seeing as there are no unicode using devs.
Title: Re: Unicode input
Post by: fellowusertoo on July 24, 2011, 00:56:39
I've found out that this is a bug in java. Microsoft's input method would just return ? for unicode characters. It even happens for TWL.
Only pure java... AWT or Swing input methods will work consistently for unicode input.

But I really need unicode input as my target application definitely requires handling of East Asian scripts (especially Chinese).

So, the only solution is to use AWT with LWJGL. But since that requires a rewrite on my own part
and JOGL has better support for binding with AWT (I like NEWT a lot). I've decided to use JOGL. A pity though, I really really liked LWJGL's simplicity.

Thanks for all the help. =D
Title: Re: Unicode input
Post by: princec on July 24, 2011, 13:32:45
LWJGL's AWT integration is, as far as I can see, every bit as good as JOGL's.

Cas :)
Title: Re: Unicode input
Post by: xand on August 15, 2011, 00:49:36
Have the same problem, but with russian.
At english  system out prints keycode 16  char q  charToInt 113
at russian key 16  char ?  charToInt 233
but right is key 16  char й  charToInt 1081

One good man told me
QuoteFrom reading LWJGL source code it could be related to this method (http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java?revision=3596&view=markup#l784) which (incorrectly) only uses 8 bit of the 16 bit character code. This (http://msdn.microsoft.com/en-us/library/ms646276(v=vs.85).aspx) is the official Windows API documentation which says it's a 16 bit Unicode value.

It will be solved, or I need to find another way?

Title: Re: Unicode input
Post by: jediTofu on August 15, 2011, 04:41:18
LWJGL should also add support for WM_UNICHAR?

EDIT: also fix for WM_CHAR, would just be "(int)(wParam & 0xFFFF)"?
Title: Re: [BUG] Unicode input
Post by: spasi on August 16, 2011, 22:24:08
The next nightly build will have unicode support on Windows. I was able to test it with Greek and Russian but had trouble with Chinese. Could you please check it out and let me know if it works?
Title: Re: [BUG] Unicode input
Post by: Matzon on August 17, 2011, 04:57:56
nice work!, out of curiosity - how did you test this?
Just adding a new keyboard layout in windows or ?
Title: Re: [BUG] Unicode input
Post by: spasi on August 17, 2011, 09:06:28
Yes, I added new input languages and used the KeyboardTest to verify that it worked. Also used chcp <codepage> in the command prompt to be able to see non-english characters properly. Sys.alert and Display.setTitle have been tested with unicode text too.
Title: Re: [BUG] Unicode input
Post by: Matzon on August 17, 2011, 10:01:18
chcp aha!
Title: Re: [BUG] Unicode input
Post by: spasi on August 19, 2011, 11:21:36
So, I did some more testing with chinese and it seems to work fine, except it's kinda useless in fullscreen mode. We need to expose IME events like this RFE (http://lwjgl.org/forum/index.php/topic,4129.0.html) suggests, so that people can build in-game components to handle such input. Something like Scaleform IME (http://www.scaleform.com/ime).
Title: Re: [BUG] Unicode input
Post by: xand on August 19, 2011, 19:23:47
I have tested it, it works fine. Thank You for your great work.
Title: Re: [FIXED] Unicode input
Post by: Socob on August 20, 2011, 09:11:59
The Unicode support on Windows does indeed seem to work.
However, there are still problems on the Linux platform. Am I correct in assuming that this fix only addresses the issue on Windows? In particular, I have encountered the problem with the Display.setTitle() method. On Windows, if you do something like this: Display.setTitle("éöäü") it works fine, but on Linux, you get "éöäü" as the output, which indicates that LWJGL still assumes an 8-bit encoding. Is there any chance of this being solved as well?

(I am of course using the latest nightly build of LWJGL, and Linux Mint 11, if that matters.)
Title: Re: [BUG] Unicode input
Post by: kappa on August 20, 2011, 11:59:20
Added Unicode support to window titles on Linux, do test next nightly build of LWJGL 2.8 to confirm.
Title: Re: [BUG] Unicode input
Post by: Socob on August 20, 2011, 12:45:28
@kappa
Seems to work perfectly, thanks a lot!
Title: Re: [FIXED] Unicode input
Post by: CheatCat on August 22, 2011, 11:20:48
That fix seem to broke stuff for me. I got SIGSEGV on the latest nightly bulid, what I didn't got in rev 3307. Here is the error log: http://pastebin.com/5HdfQx9H
Title: Re: [FIXED] Unicode input
Post by: spasi on August 22, 2011, 14:02:40
The java.lang.String.getBytes() in the log looks suspicious. It shouldn't be there, getBytes isn't called with the recent changes. Are you absolutely sure you're using the latest binaries?
Title: Re: [FIXED] Unicode input
Post by: kulpa on August 22, 2011, 14:49:03
Yesterday I observed the same issue with the svn version.
I get it, when I omit setting the `java.library.path` property.
(with it everything works fine, so not a big deal)

http://pastebin.com/cE0Scdv4
Title: Re: [FIXED] Unicode input
Post by: Matzon on August 22, 2011, 15:26:59
bump native version id ?
Title: Re: [FIXED] Unicode input
Post by: fellowusertoo on October 01, 2011, 10:56:39
OMG! this was actually fixed. I didn't know, I adventured into JOGL and found it lacking. Then tried Eclipse SWT, which has a weird problem where keyboard presses don't go up for some reason, till now, nobody has responded to the SWT thread (here: http://www.eclipse.org/forums/index.php/t/239408/ (http://www.eclipse.org/forums/index.php/t/239408/)).

THANK YOU SO MUCH!!!!!!