views:

71

answers:

2

I have several keyboards and they type in different TMemos. In english, everything works fine, but in Korean the keystrokes get sent to the IME before it sends it to my onKeypress (which handles/identifies the different keyboards), so I can't exactly tell which keyboard it came from before that.

I don't exactly know how to use WinApi, but I need to learn to use the part that deals with the IME. There is a lot of information HERE, but I need to know how to apply it in delphi. I need to store each users keystrokes and send them to the IME.

Perhaps someone can help me learn to use IMM.PAS

A: 

I doubt that Windows supports what you want to do, and I doubt that you can make Windows work differently. It sounds like you are trying to use two physical keyboards on a single computer.

IMM.PAS is a wrapper for the Windows IME API, and does not appear to have been written to help you do exactly what you want to do.

Why aren't you using two computers, with two keyboards?

Warren P
It's part of the specifications my company gave me. I've succeeded in separating the keystrokes/characters that I've received from the IME but I now I can't get the characters that need multiple keystrokes. I was wondering if possibly the other functions I haven't tried out can solve this like the one with the RECONVERTSTRING, but there is not that much delphi sample codes which help me figure out how to use the functions.
Dian
+2  A: 

Got it to work. Using ImmGetContext, ImmSetCompositon, ImmGetComposition and NormalizeString.

procedure TForm1.IMEFUNCTION(var msg: TMsg);
var
  buf: array [0..20] of char;
  hHimc: HIMC;
  i, j: integer;
  str: string;
  temporary: PWideChar;
begin

   hHimc:= ImmGetContext (msg.hwnd);
   if hHimc = 0 then
    Exit;
   fillchar (buf, 20, 0);
   ImmSetCompositionStringW (hHimc, SCS_SETSTR, PChar (''), Length(''), nil, 0);
   ImmGetCompositionString (hHimc, GCS_COMPSTR, @buf, 20);

  temporary:= PWideChar(Edit1.Text+buf[0]);
  NormalizeString(5 , temporary, -1, buf, 20);
  Edit1.Text:=buf;

    end;//end if
  end;//end for
  ImmReleaseContext (handle, hHimc);

end;

Side note: I didn't really use TEdit, I used a StringGrid and a for-loop. (but the general idea is there)

Dian