Advertisement
Guest User

Untitled

a guest
Aug 20th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. ;
  2. ; Window Spy
  3. ;
  4.  
  5. #NoEnv
  6. #NoTrayIcon
  7. #SingleInstance Ignore
  8. SetWorkingDir, %A_ScriptDir%
  9. SetBatchLines, -1
  10. CoordMode, Pixel, Screen
  11.  
  12. txtNotFrozen := "(Hold Ctrl or Shift to suspend updates)"
  13. txtFrozen := "(Updates suspended)"
  14. txtMouseCtrl := "Control Under Mouse Position"
  15. txtFocusCtrl := "Focused Control"
  16.  
  17. Gui, New, hwndhGui AlwaysOnTop Resize MinSize
  18. Gui, Add, Text,, Window Title, Class and Process:
  19. Gui, Add, Checkbox, yp xp+200 w120 Right vCtrl_FollowMouse, Follow Mouse
  20. Gui, Add, Edit, xm w320 r4 ReadOnly -Wrap vCtrl_Title
  21. Gui, Add, Text,, Mouse Position:
  22. Gui, Add, Edit, w320 r4 ReadOnly vCtrl_MousePos
  23. Gui, Add, Text, w320 vCtrl_CtrlLabel, % txtFocusCtrl ":"
  24. Gui, Add, Edit, w320 r4 ReadOnly vCtrl_Ctrl
  25. Gui, Add, Text,, Active Window Position:
  26. Gui, Add, Edit, w320 r2 ReadOnly vCtrl_Pos
  27. Gui, Add, Text,, Status Bar Text:
  28. Gui, Add, Edit, w320 r2 ReadOnly vCtrl_SBText
  29. Gui, Add, Checkbox, vCtrl_IsSlow, Slow TitleMatchMode
  30. Gui, Add, Text,, Visible Text:
  31. Gui, Add, Edit, w320 r2 ReadOnly vCtrl_VisText
  32. Gui, Add, Text,, All Text:
  33. Gui, Add, Edit, w320 r2 ReadOnly vCtrl_AllText
  34. Gui, Add, Text, w320 r1 vCtrl_Freeze, % txtNotFrozen
  35. Gui, Show, NoActivate, Window Spy
  36. GetClientSize(hGui, temp)
  37. horzMargin := temp*96//A_ScreenDPI - 320
  38. SetTimer, Update, 250
  39. return
  40.  
  41. GuiSize:
  42. Gui %hGui%:Default
  43. if !horzMargin
  44. return
  45. SetTimer, Update, % A_EventInfo=1 ? "Off" : "On" ; Suspend on minimize
  46. ctrlW := A_GuiWidth - horzMargin
  47. list = Title,MousePos,Ctrl,Pos,SBText,VisText,AllText,Freeze
  48. Loop, Parse, list, `,
  49. GuiControl, Move, Ctrl_%A_LoopField%, w%ctrlW%
  50. return
  51.  
  52. Update:
  53. Gui %hGui%:Default
  54. GuiControlGet, Ctrl_FollowMouse
  55. CoordMode, Mouse, Screen
  56. MouseGetPos, msX, msY, msWin, msCtrl
  57. actWin := WinExist("A")
  58. if Ctrl_FollowMouse
  59. {
  60. curWin := msWin
  61. curCtrl := msCtrl
  62. WinExist("ahk_id " curWin)
  63. }
  64. else
  65. {
  66. curWin := actWin
  67. ControlGetFocus, curCtrl
  68. }
  69. WinGetTitle, t1
  70. WinGetClass, t2
  71. if (curWin = hGui || t2 = "MultitaskingViewFrame") ; Our Gui || Alt-tab
  72. {
  73. UpdateText("Ctrl_Freeze", txtFrozen)
  74. return
  75. }
  76. UpdateText("Ctrl_Freeze", txtNotFrozen)
  77. WinGet, t3, ProcessName
  78. WinGet, t4, PID
  79. UpdateText("Ctrl_Title", t1 "`nahk_class " t2 "`nahk_exe " t3 "`nahk_pid " t4)
  80. CoordMode, Mouse, Relative
  81. MouseGetPos, mrX, mrY
  82. CoordMode, Mouse, Client
  83. MouseGetPos, mcX, mcY
  84. PixelGetColor, mClr, %msX%, %msY%, RGB
  85. mClr := SubStr(mClr, 3)
  86. UpdateText("Ctrl_MousePos", "Screen:`t" msX ", " msY " (less often used)`nWindow:`t" mrX ", " mrY " (default)`nClient:`t" mcX ", " mcY " (recommended)"
  87. . "`nColor:`t" mClr " (Red=" SubStr(mClr, 1, 2) " Green=" SubStr(mClr, 3, 2) " Blue=" SubStr(mClr, 5) ")")
  88. UpdateText("Ctrl_CtrlLabel", (Ctrl_FollowMouse ? txtMouseCtrl : txtFocusCtrl) ":")
  89. if (curCtrl)
  90. {
  91. ControlGetText, ctrlTxt, %curCtrl%
  92. cText := "ClassNN:`t" curCtrl "`nText:`t" textMangle(ctrlTxt)
  93. ControlGetPos cX, cY, cW, cH, %curCtrl%
  94. cText .= "`n`tx: " cX "`ty: " cY "`tw: " cW "`th: " cH
  95. WinToClient(curWin, cX, cY)
  96. ControlGet, curCtrlHwnd, Hwnd,, % curCtrl
  97. GetClientSize(curCtrlHwnd, cW, cH)
  98. cText .= "`nClient:`tx: " cX "`ty: " cY "`tw: " cW "`th: " cH
  99. }
  100. else
  101. cText := ""
  102. UpdateText("Ctrl_Ctrl", cText)
  103. WinGetPos, wX, wY, wW, wH
  104. GetClientSize(curWin, wcW, wcH)
  105. UpdateText("Ctrl_Pos", "`tx: " wX "`ty: " wY "`tw: " wW "`th: " wH "`nClient:`tx: 0`ty: 0`tw: " wcW "`th: " wcH)
  106. sbTxt := ""
  107. Loop
  108. {
  109. StatusBarGetText, ovi, %A_Index%
  110. if ovi =
  111. break
  112. sbTxt .= "(" A_Index "):`t" textMangle(ovi) "`n"
  113. }
  114. StringTrimRight, sbTxt, sbTxt, 1
  115. UpdateText("Ctrl_SBText", sbTxt)
  116. GuiControlGet, bSlow,, Ctrl_IsSlow
  117. if bSlow
  118. {
  119. DetectHiddenText, Off
  120. WinGetText, ovVisText
  121. DetectHiddenText, On
  122. WinGetText, ovAllText
  123. }
  124. else
  125. {
  126. ovVisText := WinGetTextFast(false)
  127. ovAllText := WinGetTextFast(true)
  128. }
  129. UpdateText("Ctrl_VisText", ovVisText)
  130. UpdateText("Ctrl_AllText", ovAllText)
  131. return
  132.  
  133. GuiClose:
  134. ExitApp
  135.  
  136. WinGetTextFast(detect_hidden)
  137. {
  138. ; WinGetText ALWAYS uses the "fast" mode - TitleMatchMode only affects
  139. ; WinText/ExcludeText parameters. In Slow mode, GetWindowText() is used
  140. ; to retrieve the text of each control.
  141. WinGet controls, ControlListHwnd
  142. static WINDOW_TEXT_SIZE := 32767 ; Defined in AutoHotkey source.
  143. VarSetCapacity(buf, WINDOW_TEXT_SIZE * (A_IsUnicode ? 2 : 1))
  144. text := ""
  145. Loop Parse, controls, `n
  146. {
  147. if !detect_hidden && !DllCall("IsWindowVisible", "ptr", A_LoopField)
  148. continue
  149. if !DllCall("GetWindowText", "ptr", A_LoopField, "str", buf, "int", WINDOW_TEXT_SIZE)
  150. continue
  151. text .= buf "`r`n"
  152. }
  153. return text
  154. }
  155.  
  156. UpdateText(ControlID, NewText)
  157. {
  158. ; Unlike using a pure GuiControl, this function causes the text of the
  159. ; controls to be updated only when the text has changed, preventing periodic
  160. ; flickering (especially on older systems).
  161. static OldText := {}
  162. global hGui
  163. if (OldText[ControlID] != NewText)
  164. {
  165. GuiControl, %hGui%:, % ControlID, % NewText
  166. OldText[ControlID] := NewText
  167. }
  168. }
  169.  
  170. GetClientSize(hWnd, ByRef w := "", ByRef h := "")
  171. {
  172. VarSetCapacity(rect, 16)
  173. DllCall("GetClientRect", "ptr", hWnd, "ptr", &rect)
  174. w := NumGet(rect, 8, "int")
  175. h := NumGet(rect, 12, "int")
  176. }
  177.  
  178. WinToClient(hWnd, ByRef x, ByRef y)
  179. {
  180. WinGetPos wX, wY,,, ahk_id %hWnd%
  181. x += wX, y += wY
  182. VarSetCapacity(pt, 8), NumPut(y, NumPut(x, pt, "int"), "int")
  183. if !DllCall("ScreenToClient", "ptr", hWnd, "ptr", &pt)
  184. return false
  185. x := NumGet(pt, 0, "int"), y := NumGet(pt, 4, "int")
  186. return true
  187. }
  188.  
  189. textMangle(x)
  190. {
  191. if pos := InStr(x, "`n")
  192. x := SubStr(x, 1, pos-1), elli := true
  193. if StrLen(x) > 40
  194. {
  195. StringLeft, x, x, 40
  196. elli := true
  197. }
  198. if elli
  199. x .= " (...)"
  200. return x
  201. }
  202.  
  203. ~*Ctrl::
  204. ~*Shift::
  205. SetTimer, Update, Off
  206. UpdateText("Ctrl_Freeze", txtFrozen)
  207. return
  208.  
  209. ~*Ctrl up::
  210. ~*Shift up::
  211. SetTimer, Update, On
  212. return
  213.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement