Hi
I am writing a program that displays keyboard shortcuts (hotkeys) in C# and WPF for use when making video tutorials.
Everything I have done so far, works pretty good. The problem is, sometimes I don't want to process keyboard shortcuts, ie: don't display them.
That would be if the user is typing something into any kind of editable textbox or element where a caret is blinking.
I found a solution here that kind of works:
Getting Caret Position Inside Any Application[
^]
I don't need to know position or anything other than a cursor is active and blinking somewhere on screen. Then I would ignore showing the keys being pressed and not show them on screen. The problem with the above code is, it works in some apps but not others. In 3dsmax all works correctly, in Maya, I have to click the input box a 2nd time and it will work, in other 3d programs like cinema 4d it doesn't work at all.
Is there anyway to to detect a blinking caret / active caret in an external program using C# and WPF ?
Thanks
Rob
Update 3/31/23
I saw someone posted a solution, but must have deleted it - I did try it cause the solution remained visible on my phone but not on my desktop - regardless the solution didn't work.
2nd: As stated above, my version works mostly, but even my version doesn't detect the bright blinking caret in visual studio. I am assuming if I can detect the caret in visual studio, it might detect for all (if this helps people come up with a solution)
3rd: I have a feeling its a window depth problem, ie: the code area of visual studio isn't detected as the foreground window, only the surrounding frame is the foreground window (if you get my drift). Maybe the problem is detecting the caret in a child window of the foreground window ?!
What I have tried:
I have tried:
public void GetCaretPosition()
{
guiInfo = new GUITHREADINFO();
guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);
GetGUIThreadInfo(0, out guiInfo);
}
private void EvaluateCaretPosition()
{
caretPosition = new Point();
GetCaretPosition();
caretPosition.X = (int)guiInfo.rcCaret.Left + 25;
caretPosition.Y = (int)guiInfo.rcCaret.Bottom + 25;
if ((int)caretPosition.X != 25 || (int)caretPosition.Y != 25)
{
Globals.bCaretActive = true;
}
else
{
Globals.bCaretActive = false;
}
txtCaret.Text = ((int)caretPosition.X).ToString() + " / " + ((int)caretPosition.Y).ToString();
}