Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Is there a way to make Prima widgets accept double byte characters?

by ZJ.Mike.2009 (Scribe)
on Jun 03, 2011 at 13:57 UTC ( [id://907982] : perlquestion . print w/replies, xml ) Need Help??

ZJ.Mike.2009 has asked for the wisdom of the Perl Monks concerning the following question:

With Prima (1.3), I cannot enter Chinese characters in the InputLine widget from the keyboard through the system's default Input Method Editor (I'm running Win XP SP3 Chinese version). However, Chinese characters can be pasted to the InputLine and display properly in it so I'm wondering if there's a workaround to make the InputLine accept Chinese characters or any other double-byte characters from the keyboard input. What kind of design causes a widget to refuse double-byte character input from the keyboard? Is it easy to add its support?

Can anyone give me some ideas? Thanks in advance.

Replies are listed 'Best First'.
Re: Is there a way to make Prima widgets accept double byte characters?
by Anonymous Monk on Jun 03, 2011 at 14:37 UTC
        Anonymous Monk, thank you for the two suggestions.

        I took a look at the module and experimented with a few minor modifications of the on_keydown subroutine, but without luck.

        I'm thinking the problem might be elsewhere. It doesn't seem to be an on_keydown event. Nor does it seem to be related to the wantUnicode property (I think the code generated through the IME on my system is not Unicode by default)

        The thing is: even if I try to enter English words (latin letters) to the InputLine widget(or Edit widget) through the Chinese oriented Input Method Editor (IME) that can let me choose what to enter among a number of input candidates using the space or numerical keys on the keyboard, instead of directly entering characters found on the keyboard, I will fail. The InputLine widget seems to only accept inputs directly from the input device, ie the keyboard.

        Thanks anyway :)
Re: Is there a way to make Prima widgets accept double byte characters?
by dk (Chaplain) on Jun 06, 2011 at 11:59 UTC

    As I answered to your bug report , I have no knowledge on how to emulate Chinise input, so it might be a bug, might be something else , - but anyway I can't possibly fix it because I can't reproduce it. If you feel like debugging Prima and sending a patch, then yes, by all means, please do that.


        I was reluctant to get inside CIJK because I somehow thought that I have to have a real chinese keyboard, but I gave it a go and installed Chinese layout and lo, I could type unicode! Miracle ))

        Well anyway, yes, WM_CHAR was an easy spot, but strangely enough it only conveyed question mark symbols, never the real chars. Same with WM_IME_CHAR. Finally I found a working method, from GTK - they catch WM_IME_COMPOSITION and explicitly extract the chars by calling ImmGetCompositionStringW.

        I've tried that too, but after typing a test char the Chinese IME died and refused to come up :) Again, thinking that usually IME-aware apps use wide-char win32 API, I've changed calls to RegisterClass and CreateWindow to their wide-char counterparts, and that seemingly helped.

        So I've committed the change, but the problem is, I have no knowledge of Chinese, and my semi-random key strokes that produce a seemingly ok chiniese character doesn't mean that the input is accepted correctly. It seems so, but I'm not 100% sure. So if anyone's willing, you're more than welcome grab the latest Prima from github ( ) and see if that works for your favourite language and IME.

        @Anonymous Monk, thank you for the suggestion. I know nothing about the C language but is it that I only need to add something in the switch block in the global.c source, like:
        case WM_IME_CHAR: ev. key. code = mp1;
        Anyway this is probably the crux of the problem. Thank you :)
      @dk, thank you for the prompt response. I like Prima anyway. Thank you for sharing with us.