none
How input methods get the keyboard caret/cursor position? And how to do that in C#? RRS feed

  • Question

  • I am working on a C# project, which need to get the keyboard caret/ cursor position.

    The method I am using is by calling Win32 Apis. By using this blog: https://www.codeproject.com/Articles/34520/Getting-Caret-Position-Inside-Any-Application

    https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getguithreadinfo

    https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-guithreadinfo

    NativeMethods.GUITHREADINFO gUITHREADINFO = new NativeMethods.GUITHREADINFO();
    gUITHREADINFO.cbSize = (uint)Marshal.SizeOf(gUITHREADINFO);

    if (!NativeMethods.GetGUIThreadInfo(0, out gUITHREADINFO))
    {
       return new int[] { 0, 0 };
    }
    [DllImport("user32.dll")]
    public static extern bool GetGUIThreadInfo(uint tId, out GUITHREADINFO threadInfo);

    But such method has limitations. It won't work in Chrome and Chrome based applications, nor it works in Java based applications.

    I noticed that some Non-English input method has a feature to keep track of keyboard input cursor/caret. How they do the job? Or how I can get the keyboard caret in Chrome in C#?

    Monday, June 10, 2019 9:51 PM

Answers

  • Hello singer-neu,

    This forum is for "Discuss general issues about developing applications for Windows."

    Since this issue is C# related I'll move it to C# forum for more professional support.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by singer-neu Tuesday, June 11, 2019 9:18 PM
    Tuesday, June 11, 2019 3:09 AM