Im working with a c# application which captures the system events using the global c# mouse and keyboard hooks, But I couldn't get the current keyboard cursor position values while im typing.
Following is my code and it always returns GetCaretPos output as (0,0)
PointDetail curPoint = new PointDetail();
Point position = new Point();
IntPtr hwndFoc;
IntPtr hwndFG = WinApiDelegate.GetForegroundWindow();
uint processID = 0;
uint mainWindowProcessId = 0;
IntPtr activeWindowThreadProcess = WinApiDelegate.GetWindowThreadProcessId(hwndFG, IntPtr.Zero);
IntPtr currWindowThread = IntPtr.Zero;
int thisWindowThread = 0;
this.Invoke(new MethodInvoker(delegate
{
currWindowThread = WinApiDelegate.GetWindowThreadProcessId(this.Handle, IntPtr.Zero);
thisWindowThread = WinApiDelegate.GetWindowThreadProcessId(this.Handle, out mainWindowProcessId);
}));
int activeWindowThread = WinApiDelegate.GetWindowThreadProcessId(hwndFG, out processID);
if (activeWindowThread != Thread.CurrentThread.ManagedThreadId)
{
WinApiDelegate.AttachThreadInput(activeWindowThreadProcess, currWindowThread, true);
hwndFoc = WinApiDelegate.GetActiveWindow();
bool CaretPos = WinApiDelegate.GetCaretPos(ref position);
}