ryancheung / ImeSharp

C# wrapper for Windows IME APIs
MIT License
71 stars 12 forks source link

Word VSTO - OnTextInput and OnTextComposition callbacks don't fire #19

Open Robertocrotti98 opened 1 month ago

Robertocrotti98 commented 1 month ago

Hi, I am programming a VSTO add-in for Microsoft Word and I have problems with "OnTextInput" and "OnTextComposition" callbacks. I just need to intercept what the user is writing inside the body of the Word document, but I can't get the callbacks working. Maybe it could be a problem of initialization, related to the window handle. I've tried to obtain the HWND in many ways:

1) InputMethod.Initialize(Process.GetCurrentProcess().MainWindowHandle, true); 2) InputMethod.Initialize((IntPtr)Application.ActiveWindow.Hwnd, true); 3) InputMethod.Initialize((IntPtr)Application.Windows[0].Hwnd, true); 3) InputMethod.Initialize(GetFocus(), true);

None of these is working. What am I doing wrong?