Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
/ ImeSharp Public archive
forked from ryancheung/ImeSharp

C# wrapper for Windows IME APIs

License

Notifications You must be signed in to change notification settings

FNA-NET/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.TextComposition += (o, e) =>
{
    // get composition or candidate infos
};
InputMethod.TextInput += (o, e) =>
{
    // get composition result.
};

Or you prefer callbacks

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

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

About

C# wrapper for Windows IME APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%