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#?

    Wednesday, June 12, 2019 5:46 PM

Answers

  • Hello,

    I would suggest looking into Selenium. Do the following Google search.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by singer-neu Monday, June 17, 2019 5:25 PM
    Thursday, June 13, 2019 9:36 PM
    Moderator

All replies

  • Hi singer-neu,

    Than you for posting here.

    Based on my search, I could not find a way to meet your requirements.

    I suggest that you could post in the third-party forum to look for if third-party product could solve it.

    https://csharpforums.net/

    Note:This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Jack


    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.

    Thursday, June 13, 2019 9:57 AM
    Moderator
  • Hi thank you for the reply. Can we locate the bounding box of the field user is working on? For example the name field in a form.
    Thursday, June 13, 2019 8:55 PM
  • Hello,

    I would suggest looking into Selenium. Do the following Google search.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by singer-neu Monday, June 17, 2019 5:25 PM
    Thursday, June 13, 2019 9:36 PM
    Moderator