A C# wrapper for Windows IME APIs. Its goal is to support both IMM32 and TSF.
TSF Implementation is based on WPF core.
dotnet add package ImeSharp
Note ImeSharp.NetStandard package is deprecated, use ImeSharp instead.
Call InputMethod.Initialize
to initialize the input method with a window handle, e.g. InputMethod.Initialize(someWindowHandle)
.
If you don't want the OS Candidate Window, do InputMethod.Initialize(someWindowHandle, false)
.
If we don't enable custom windows message pumping. Use TSF in WinForms would have a issue: Frame will randomly stuck when composing with IME. This is because TSF disables Application.Idle event when it's busy. Enables custom message pumping fix this.
In WinForms, we add message pumping at the end line in Application.Idle
handler, e.g.:
private void Application_Idle(object sender, EventArgs e)
{
Game.Tick();
// Enables custom message pumping
InputMethod.PumpMessage();
}
InputMethod.TextInputCallback = OnTextInput;
InputMethod.TextCompositionCallback = OnTextComposition;
Retrieve other composition info from InputMethod.CandidateList
and other fields for CJK IMEs.
InputMethod.SetTextInputRect(location.X, location.Y, 0, textBoxHeight);
IMM32 would be only enabled if TSF service is not available.
You can return false
manually in TextServicesLoader.ServicesInstalled
to mimic TSF unavailable case.
- Make it work in Unity3d