Coder Social home page Coder Social logo

imesharp's Introduction

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

imesharp's People

Contributors

nikitabuyevich avatar ryancheung avatar sradnickdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

imesharp's Issues

[Usecase] [Help] How to start textcomposition ?

Thanks for this great wrapper.

I am totally new to IME and all TSF related APIs. I was able to start the Demo Project successfully. On textinput InputMethod.TextInputCallback is fired. Now I want to start my custom text composition based on my input and want to show candidates in window like below.
image

Can you tell me how to start text composition and show window ?

Regards,
Sagar

[BUG] Access violation on ImeSharp.Demo

OS: Win10
Language: Chinese
IME: MicrosoftPinyin
When I submit a candidate word it exit without any popups. Just see a access violation log on VS output window.

无法在Monogame上正常工作

项目模板:MonoGame Windows Desktop Application(短名称:mgwindowsdx)

更改Game1.cs的两个方法:

protected override void LoadContent()
    {
        // 使用 Procecss.GetCurrentProcess().MainWindowHandle 也不行
        var form = (Form)Window.GetType().GetField("Form", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(Window)!;
        InputMethod.Initialize(form.Handle);
    }

    protected override void Update(GameTime gameTime)
    {
        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
        {
            Exit();
        }

        if (Keyboard.GetState().IsKeyDown(Keys.Enter))
        {
            InputMethod.Enabled = true;
        }

        base.Update(gameTime);
    }

复现步骤:运行之后切换按下回车键
异常:
Unhandled exception. SharpGen.Runtime.SharpGenException: HRESULT: [0x80004002], Module: [Unknown], ApiCode: [Unknown/Unknown], Message: 不支持此接口

at SharpGen.Runtime.Result.ThrowFailureException()
at SharpGen.Runtime.ComObject.QueryInterfaceT
at ImeSharp.TextServicesContext.get_ThreadManager()
at ImeSharp.TextServicesContext.RegisterTextStore(TextStore defaultTextStore)
at ImeSharp.TextStore.get_Current()
at ImeSharp.TextServicesContext.SetFocusOnDefaultTextStore()
at ImeSharp.InputMethod.EnableOrDisableInputMethod(Boolean bEnabled)
at ImeSharpOnMonogame.Game1.Update(GameTime gameTime) in D:\Notran\ImeSharpOnMonogame\ImeSharpOnMonogame\Game1.cs:line 57
at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime)
at Microsoft.Xna.Framework.Game.Tick()
at MonoGame.Framework.WinFormsGameWindow.TickOnIdle(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.Interop.Mso.IMsoComponent.FDoIdle(msoidlef grfidlef)
at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MonoGame.Framework.WinFormsGameWindow.RunLoop()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at Program.

$(String[] args) in D:\Notran\ImeSharpOnMonogame\ImeSharpOnMonogame\Program.cs:line 6

我试过把 WindowsDX 换成 DesktopGL, 但是仍会抛出此异常

How should I paste the word to third-party program?

I am trying to code an input method by this.

I tried the demo program and it runs well.

However, the demo program only works in itself.

Now I am about to paste the word to third-party programs (such as windows notepad).

How can I achieve this? Thank you.

Korean doesn't work with TSF

When TSF is installed/enabled, Korean stops working (The behavior is unexpected and the composition string stops being rendered)

Find a way to hide OS rendered ImeWindow

The default TextStore of WPF have implemented ITfTransitoryExtensionSink(doc) to easily support text composition events. But in this way, if we want to hide the OS rendered ImeWindow, we have to use ITfTransitoryExtensionUIElement(doc) to hide the ImeWindow. But I'm not sure how to make it work.

If this way cannot work. We may switch to ITextStoreACP and use ITfUIElementSink to hide the OS ImeWindow.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.