[FIXED] Unicode input

Started by fellowusertoo, July 23, 2011, 15:12:08

Previous topic - Next topic

fellowusertoo

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.

Matzon

At this point, I think your best bet is to dig into the code, seeing as there are no unicode using devs.

fellowusertoo

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

princec

LWJGL's AWT integration is, as far as I can see, every bit as good as JOGL's.

Cas :)

xand

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 which (incorrectly) only uses 8 bit of the 16 bit character code. This 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?


jediTofu

LWJGL should also add support for WM_UNICHAR?

EDIT: also fix for WM_CHAR, would just be "(int)(wParam & 0xFFFF)"?
cool story, bro

spasi

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?

Matzon

nice work!, out of curiosity - how did you test this?
Just adding a new keyboard layout in windows or ?

spasi

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.

Matzon


spasi

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 suggests, so that people can build in-game components to handle such input. Something like Scaleform IME.

xand

I have tested it, it works fine. Thank You for your great work.

Socob

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.)

kappa

Added Unicode support to window titles on Linux, do test next nightly build of LWJGL 2.8 to confirm.

Socob

@kappa
Seems to work perfectly, thanks a lot!