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

  • Thread starter Thread starter singer-neu
  • Start date Start date
S

singer-neu

Guest
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: Getting Caret Position Inside Any Application

GetGUIThreadInfo function (winuser.h)

GUITHREADINFO (winuser.h)

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

Continue reading...
 
Back
Top