I have a few questions about this code to Get Caret Position that I have put together from various sources.
Why are some Carets not detected? Eg. Caret in Notepad is detected. Caret in various web browsers is not.
Why is it that when this code is running, it is not possible to double click a desktop icon to launch an app?
How might this code be improved?
All advice greatly appreciated.
Code: Select all
Define StringCaretPos.Point
OpenWindow(0, 0, 0, 200, 160, "GetCaretPos", #PB_Window_SystemMenu)
EditorGadget(0, 0, 0, 200, 50, #PB_Editor_WordWrap)
SetGadgetText(0, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
TextGadget(1, 20,  80, 160, 25, "")
TextGadget(2, 20, 110, 160, 25, "")
Repeat
  
  Event = WaitWindowEvent(100) 
  
  Select Event
      
    Case #PB_Event_CloseWindow
 
      End
      
    Default
             
      ThisID = GetCurrentThreadId_() 
      ForeID = GetWindowThreadProcessId_(GetForegroundWindow_(), 0) 
      
      If ThisID <> ForeID
        AttachThreadInput_(ThisID, ForeID, #True)
      EndIf     
      
      GetCaretPos_(@StringCaretPos)
      
      If (StringCaretPos\x <> 0) Or (StringCaretPos\y <> 0)
        focusedHandle = GetFocus_()      
        ClientToScreen_(focusedHandle, @StringCaretPos)
      EndIf      
      
      If ThisID <> ForeID
        AttachThreadInput_(ThisID, ForeID, #False)
      EndIf
      
      SetGadgetText(1, "Caret X:" + Str(StringCaretPos\x) + ", Y:" + Str(StringCaretPos\y)) 
      
      iters = iters + 1
      SetGadgetText(2, "Iteration " + Str(iters))
      
  EndSelect
  
ForEver


