Skip to content

ryancheung/ImeSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IME Sharp

Nuget

A C# wrapper for Windows IME APIs. Its goal is to support both IMM32 and TSF.

TSF Implementation is based on WPF core.

Packages

dotnet add package ImeSharp

Note ImeSharp.NetStandard package is deprecated, use ImeSharp instead.

Usage

Initialization

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).

Custom message pumping

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();
}

Hook events

InputMethod.TextInputCallback = OnTextInput;
InputMethod.TextCompositionCallback = OnTextComposition;

Retrieve other composition info from InputMethod.CandidateList and other fields for CJK IMEs.

Set position of OS rendered IME Candidate Window

InputMethod.SetTextInputRect(location.X, location.Y, 0, textBoxHeight);

Test IMM32 implementation only

IMM32 would be only enabled if TSF service is not available. You can return false manually in TextServicesLoader.ServicesInstalled to mimic TSF unavailable case.

TODO

  • Make it work in Unity3d

MS Docs

Other samples / implementations

Credits