|
i think i solve the chinese input problem |
vkensou
Member #15,546
March 2014
|
i use allegro 5.1.8 change some code: in file <d3d_disp.cpp>'s method d3d_display_thread_proc() file <wwindow.c>'s method window_callback() add case WM_IME_CHAR: file <wkeyboard.c> add method void _al_win_kbd_handle_imechar(int code,ALLEGRO_DISPLAY_WIN *win_disp) if (!_al_event_source_needs_to_generate_event(&the_keyboard.es)) event.keyboard.type = ALLEGRO_EVENT_KEY_DOWN; _al_event_source_emit_event(&the_keyboard.es, &event); event.keyboard.type = ALLEGRO_EVENT_KEY_CHAR; _al_event_source_unlock(&the_keyboard.es); } file <aintwin.h> add method's declare : void _al_win_kbd_handle_imechar(int code,ALLEGRO_DISPLAY_WIN *win_disp); now in the event ALLEGRO_EVENT_KEY_CHAR,event.keyboard.unichar have the char code. Now we can input Chinese, and perhaps other IME input language can also. |
beoran
Member #12,636
March 2011
|
Not bad, but we'll have to port this to Linux, Android, OSX and iOS too, though... |
Elias
Member #358
May 2000
|
Linux already should work. -- |
SiegeLord
Member #7,827
October 2006
|
I think 'solve' is pretty strong here. In my testing this:
Log from ex_keyboard_events with this patch: KEY_DOWN code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT] KEY_DOWN code=069, char=' ' ( 0), modifiers=00000000, [KEY69] KEY_CHAR code=069, char='"' ( 34), modifiers=00000001, [KEY69] KEY_CHAR code=069, char='"' ( 34), modifiers=00000001, [KEY69] KEY_UP code=069, char=' ' ( 0), modifiers=00000000, [KEY69] KEY_UP code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT] KEY_DOWN code=005, char=' ' ( 0), modifiers=00000000, [E] KEY_CHAR code=005, char='e' ( 101), modifiers=00000000, [E] KEY_UP code=005, char=' ' ( 0), modifiers=00000000, [E] And without: KEY_DOWN code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT] KEY_DOWN code=069, char=' ' ( 0), modifiers=00000000, [KEY69] KEY_UP code=069, char=' ' ( 0), modifiers=00000000, [KEY69] KEY_UP code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT] KEY_DOWN code=005, char=' ' ( 0), modifiers=00000000, [E] KEY_CHAR code=005, char='ë' ( 235), modifiers=00000000, [E] KEY_UP code=005, char=' ' ( 0), modifiers=00000000, [E]
"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
torhu
Member #2,727
September 2002
|
By the way, MSDN says this about WM_IME_CHAR: "For a Unicode window, this message is the same as WM_CHAR." One less thing to fix, then. |
vkensou
Member #15,546
March 2014
|
to torhu in my patch i have handled both ANICODE window and UNICODE window to SiegeLord this patch only effect windows, have no effect to other os. |
Elias
Member #358
May 2000
|
The allegro window already is Unicode (in the version in git) so that's all we need. And it definitely would be good to fix this, but I think SiegeLord ran into some issues when he tried. -- |
SiegeLord
Member #7,827
October 2006
|
vkensou said: if you do not use ime to input, it should be no effect. The TranslateMessage call breaks some other input types. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Elias
Member #358
May 2000
|
I guess at some point we will need TranslateMessage. Worst case it would have to be some platform specific configuration option with which to turn it on. But for many applications having correct text input is rather crucial (but I have no idea what exactly breaks with it). -- |
SiegeLord
Member #7,827
October 2006
|
The current code works fine for everything except IME. My patch in the other thread catches all characters in all input methods I tried, but sometimes generates bogus events. This patch breaks a whole bunch of input methods and doesn't work for the Chinese IME input I am using. The difference between this patch and mine is that I also rewrite the rest of the unicode input, thus preserving the functionality of other input methods. Unfortunately, it generates bogus events which I don't think is acceptable. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Elias
Member #358
May 2000
|
Hm, what kind of bogus events? -- |
SiegeLord
Member #7,827
October 2006
|
E.g. entering the ë key (compare with above): KEY_DOWN code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT] KEY_DOWN code=069, char=' ' ( 0), modifiers=00000000, [KEY69] KEY_CHAR code=069, char=' ' ( 0), modifiers=00000001, [KEY69] KEY_UP code=069, char=' ' ( 0), modifiers=00000000, [KEY69] KEY_UP code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT] KEY_DOWN code=005, char=' ' ( 0), modifiers=00000000, [E] KEY_CHAR code=005, char='ë' ( 235), modifiers=00000000, [E] KEY_UP code=005, char=' ' ( 0), modifiers=00000000, [E]
"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Elias
Member #358
May 2000
|
So the only problem is extra KEY_CHAR events? -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
So you're saying you shouldn't get a KEY_CHAR event for KEY69 when making that foreign e? How are you supposed to know in advance that they didn't want a KEY_CHAR with KEY69? That may illustrate my lack of knowledge, because I don't even know what key 69 is. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Elias
Member #358
May 2000
|
Supposedly, Windows sends two WM_CHAR messages, one with just a space (or does the ' ' just mean it was something not printable?) and one with ë. -- |
Thomas Fjellstrom
Member #476
June 2000
|
The first one is probably saying "Hey, I'm getting a composed char here...". Getting a CHAR event with an unprintable char should just be ignored in most cases no? (Except for when you actually want to know when you're getting some kind of compose or IME event) -- |
SiegeLord
Member #7,827
October 2006
|
Edgar Reynaldo said: How are you supposed to know in advance that they didn't want a KEY_CHAR with KEY69? That's the crux of the issue. Windows sends only one WM_CHAR, the one with the ë character, which is re-sent as the second ALLEGRO_EVENT_CHAR. The first ALLEGRO_EVENT_CHAR is sent by my code, due to imperfect detection of when such events are to be sent. The algorithm used by my patch is very simple: 1. If we get a WM_CHAR, we send the ALLEGRO_EVENT_CHAR event (unless its a surrogate, in which case we wait for a second WM_CHAR). The second step is necessary for keys like the arrow keys which generate WM_KEYDOWN events but not WM_CHAR events, but generates bogus events as shown above. In principle we could detect KEY69 and not send an event for it... but I don't know, the whole thing is very fragile as is. Elias said: So the only problem is extra KEY_CHAR events? I don't know if it's the only problem, but it is the problem that made me abandon the approach . It requires more testing and maybe there are even worse problems. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Elias
Member #358
May 2000
|
I guess what we need to do is:
The first rule should ensure that there are no unexpected ALLEGRO_EVENT_CHAR. Only when Windows thinks there should be a unicode character added Allegro will do the same. The second would be a somewhat unfortunate hack and not really necessary, but for backwards compatibility makes sense to have the ALLEGRO_EVENT_CHAR for some other control keys which do not produce unicode as that's just how Allegro works now. -- |
SiegeLord
Member #7,827
October 2006
|
I guess it's a possibility (I recall considering the 'whitelisting' option instead of the current blacklist, but I don't remember my conclusion). It's certainly a pain to identify all these keys. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Elias
Member #358
May 2000
|
Yes, but it shouldn't be too many. Cursors, home, end, delete, backspace, escape, page up/down, return, tab. If we special case those and then have all the printable Unicode characters, that will be what is expected. -- |
vkensou
Member #15,546
March 2014
|
i learn a lot from yours.
|
|