Results 1 to 6 of 6

Thread: Unicode KeyPress and JvInspector

  1. #1

    Unicode KeyPress and JvInspector

    In Delphi, how to intercept the KeyPress Event like a WideChar instead of Char? It ignores all keys above 255 and return wrong values.

    Im also with problem with TJvInspector, how to edit Strings like WideStrings intead of regular Strings with it?

  2. #2

    Unicode KeyPress and JvInspector

    Use something like this:
    // this function is from "TntSystem.pas" fron TNT Unicode controls.
    function KeyUnicode(CharCode: Word): WideChar;
      AChar: AnsiChar;
      if CharCode <= Word&#40;High&#40;AnsiChar&#41;&#41; then begin
        AChar &#58;= AnsiChar&#40;CharCode&#41;;
        MultiByteToWideChar&#40;KeyboardCodePage, MB_USEGLYPHCHARS, @AChar, 1, @Result, 1&#41;;
      end else
        Result &#58;= WideChar&#40;CharCode&#41;;
    procedure TForm1.FormCreate&#40;Sender&#58; TObject&#41;;
     Application.OnMessage&#58;= MyMessage;
    procedure TForm1.MyMessage&#40;var Msg&#58; TMsg; var Handled&#58; Boolean&#41;;
     WideCh&#58; WideChar;
     if &#40;Msg.message = WM_CHAR&#41; then
       WideCh&#58;= KeyUnicode&#40;Msg.wParam&#41;;
       // Use WideCh for some purpose

  3. #3

    Unicode KeyPress and JvInspector

    Hi Lefepower!

    Thanks for the answer, but something is not working yet!

    I did try to use the Japanese あ (12354 Unicode) code Letter... But the Msg.wParam is getting 41090 then i did type this letter! I did try anothers japanese letters, and all is getting higher than 41000 codes. If i did type the letter on a TntEdit component, by example, and get its code using the KeyUnicode funciton, all is fine (it returns 12354). The problem is with Application Message i think, in the Msg.Wparam.

    Have you some idea of what is the problem?

  4. #4

    Unicode KeyPress and JvInspector

    Look what strange!

    If i did put a TNTEDIT and a TEDIT on my Form!

    If im inside the TNTEDIT control, Msg.wParam is returning 12354 for あ, if im inside the TEDIT control, Msg.wParam is returning 41090 for あ.

    Why this behavior? Does what change when i inside an TNTEDIT Control that Msg.wParam now works, should i set this to works in my whole application?

  5. #5

    Unicode KeyPress and JvInspector

    Hi Lifepower!!

    I still have no success in getting the real Unicode Japanese Unicode Keycodess to pass to my GUI SYSTEM in Asphyre System!

    I did try your suggestion, and everything that is in this discussion!

    Did you get any sucess with Japanese Input in your Game?

    I can sucefully Display Japanese Text in my Edit Controls, i can Read and Save Japanese Text in it, i can COPY and PAST Japanese text to it, but i still cant write Japanese directelly to it because of this!

    How does Ime works It can pass more than an caracter at time?

    I can suceffuly intercept the correct Msg.wParam in WM_IME_COMPOSITION...
    In all others WM_ , noone is called when i type Japanese letters.

    But the problem is that in WM_IME_COMPOSITION the Letter in not Ready
    yet.... im totally lost.... im using IME in Windows Vista, and it shows
    and Editor when i start typing in Ime Mode.. How it works in a Real Japanese
    Operating System with a Real Japanese Keyboard? When i type something, it send a WM_IME_COMPOSITION, but
    sometimes it changes the letter in editor, and it always send the first
    letter on "Ime Editor" when the editor is ON, and not the letter that actually typing...

    Somebody have some advices of how to use this?

  6. #6

    Unicode KeyPress and JvInspector

    According to Platform SDK:

    An application that processes keyboard input typically ignores all but the WM_CHAR and WM_UNICHAR messages, passing any other messages to the DefWindowProc function. Note that WM_CHAR uses 16-bit Unicode Transformation Format (UTF) while WM_UNICHAR uses UTF-32. The system uses the WM_SYSCHAR and WM_SYSDEADCHAR messages to implement menu mnemonics.
    The code I posted worked for me to introduce Russian, French and Spanish unicode characters in the game simultaneously. I haven't checked IME nor Japanese input.

    If im inside the TNTEDIT control, Msg.wParam is returning 12354 for あ, if im inside the TEDIT control, Msg.wParam is returning 41090 for あ.
    The difference in final values that you have detected might have something to do with characters having different codes in unicode table, or possibly endian issues (why don't you print values in hex?)

    Also, TNTEdit might have translated character into UTF-32, while in TEdit you may be receiving UTF-16 characters.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Comodo SSL