How to change the freeze hotkey in Window Spy? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vkhu
Posts: 10
Joined: 04 Oct 2018, 00:40

How to change the freeze hotkey in Window Spy?

Post by vkhu » 18 Apr 2022, 03:33

I recently reinstalled ahk, only to find out the hotkey to freeze WindowSpy has changed from pressing Win+A to toggle to holding down Ctrl or Shift.

Is there a way to change it back to Win+A? The new hotkeys interfere with some of my scripts, and when I open up the WindowSpy.ahk file itself, I have no idea what I'm staring at :(.

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: How to change the freeze hotkey in Window Spy?

Post by boiler » 18 Apr 2022, 03:48

If you re-installed it without first un-installing it, depending on how old your initial installation was, you may still have the old version in your AutoHotkey installation folder (typically C:\Program Files\AutoHotkey). Look there and see if it contains the file AU3_Spy.exe.

vkhu
Posts: 10
Joined: 04 Oct 2018, 00:40

Re: How to change the freeze hotkey in Window Spy?

Post by vkhu » 18 Apr 2022, 04:07

Unfortunately, this is a new machine I'm having. There has never been any ahk installation on it, and I already sold off my old pc :(

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: How to change the freeze hotkey in Window Spy?

Post by boiler » 18 Apr 2022, 04:10

Here it is:
AU3_Spy.zip
(391.18 KiB) Downloaded 35 times

Just need to unzip it.

vkhu
Posts: 10
Joined: 04 Oct 2018, 00:40

Re: How to change the freeze hotkey in Window Spy?

Post by vkhu » 18 Apr 2022, 04:23

boiler wrote:
18 Apr 2022, 04:10
Here it is:
AU3_Spy.zip


Just need to unzip it.
TYSM!

So I just have to unzip and put this in the AHK installation folder, then delete the WindowSpy.ahk, right? Will AHK automatically use the new exe file every time I right click am active script and open window spy, or do I have to make some kind of adjustment for it to register the new file?

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: How to change the freeze hotkey in Window Spy?

Post by boiler » 18 Apr 2022, 04:29

You’re welcome. No, it won’t be invoked that way. I don’t know if that context menu can be easily changed to point at this.

You could probably download a very old version of AHK and get the .ahk version of this file, then replace the new one with it (rename it to the same name if different).

vkhu
Posts: 10
Joined: 04 Oct 2018, 00:40

Re: How to change the freeze hotkey in Window Spy?

Post by vkhu » 18 Apr 2022, 04:33

boiler wrote:
18 Apr 2022, 04:29
You could probably download a very old version of AHK and get the .ahk version of this file, then replace the new one with it (rename it to the same name if different).
Urgh, that sounds like a pain. Is there a way to open the compiled exe file and copy the code from there? I assume the exe would also be using ahk code, yes?

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: How to change the freeze hotkey in Window Spy?  Topic is solved

Post by boiler » 18 Apr 2022, 05:36

Yes, here you go:

Code: Select all

#NoEnv
#NoTrayIcon
#SingleInstance Ignore
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1
CoordMode, Pixel, Screen
IfExist, ..\toolicon.icl
Menu, Tray, Icon, ..\toolicon.icl, 9
try
Hotkey #a, FreezeDisplay
catch
Hotkey #vk41, FreezeDisplay
isUpd := true
txtNotFrozen := "(Win+A to freeze display)"
txtFrozen := "(Win+A to unfreeze display)"
Gui, New, hwndhGui AlwaysOnTop Resize MinSize
Gui, Add, Text,, Window Title, Class and Process:
Gui, Add, Edit, w320 r3 ReadOnly -Wrap vCtrl_Title
Gui, Add, Text,, Mouse Position:
Gui, Add, Edit, w320 r3 ReadOnly vCtrl_MousePos
Gui, Add, Text,, Control Under Mouse Position:
Gui, Add, Edit, w320 r5 ReadOnly vCtrl_MouseCur
Gui, Add, Text,, Active Window Position:
Gui, Add, Edit, w320 r2 ReadOnly vCtrl_Pos
Gui, Add, Text,, Status Bar Text:
Gui, Add, Edit, w320 r2 ReadOnly vCtrl_SBText
Gui, Add, Checkbox, vCtrl_IsSlow, Slow TitleMatchMode
Gui, Add, Text,, Visible Text:
Gui, Add, Edit, w320 r2 ReadOnly vCtrl_VisText
Gui, Add, Text,, All Text:
Gui, Add, Edit, w320 r2 ReadOnly vCtrl_AllText
Gui, Add, Text, w320 r1 vCtrl_Freeze, % txtNotFrozen
Gui, Show,, Active Window Info
GetClientSize(hGui, temp)
horzMargin := temp*96//A_ScreenDPI - 320
SetTimer, Update, 250
return
GuiSize:
Gui %hGui%:Default
if !horzMargin
return
ctrlW := A_GuiWidth - horzMargin
list = Title,MousePos,MouseCur,Pos,SBText,VisText,AllText,Freeze
Loop, Parse, list, `,
GuiControl, Move, Ctrl_%A_LoopField%, w%ctrlW%
return
Update:
Gui %hGui%:Default
curWin := WinExist("A")
if (curWin = hGui)
return
WinGetTitle, t1
WinGetClass, t2
WinGet, t3, ProcessName
GuiControl,, Ctrl_Title, % t1 "`nahk_class " t2 "`nahk_exe " t3
CoordMode, Mouse, Screen
MouseGetPos, msX, msY, msWin, msCtrlHwnd, 2
CoordMode, Mouse, Relative
MouseGetPos, mrX, mrY,, msCtrl
CoordMode, Mouse, Client
MouseGetPos, mcX, mcY
GuiControl,, Ctrl_MousePos, % "Absolute:`t" msX ", " msY " (less often used)`nRelative:`t" mrX ", " mrY " (default)`nClient:`t" mcX ", " mcY " (recommended)"
PixelGetColor, mClr, %msX%, %msY%, RGB
mClr := SubStr(mClr, 3)
mText := "`nColor:`t" mClr " (Red=" SubStr(mClr, 1, 2) " Green=" SubStr(mClr, 3, 2) " Blue=" SubStr(mClr, 5) ")"
if (curWin = msWin)
{
ControlGetText, ctrlTxt, %msCtrl%
mText := "ClassNN:`t" msCtrl "`nText:`t" textMangle(ctrlTxt) mText
ControlGetPos cX, cY, cW, cH, %msCtrl%
mText .= "`n`tx: " cX "`ty: " cY "`tw: " cW "`th: " cH
WinToClient(msWin, cX, cY)
GetClientSize(msCtrlHwnd, cW, cH)
mText .= "`nClient:`tx: " cX "`ty: " cY "`tw: " cW "`th: " cH
} else mText := "`n" mText
GuiControl,, Ctrl_MouseCur, % mText
WinGetPos, wX, wY, wW, wH
GetClientSize(curWin, wcW, wcH)
GuiControl,, Ctrl_Pos, % "`tx: " wX "`ty: " wY "`tw: " wW "`th: " wH "`nClient:`t`t`tw: " wcW "`th: " wcH
sbTxt := ""
Loop
{
StatusBarGetText, ovi, %A_Index%
if ovi =
break
sbTxt .= "(" A_Index "):`t" textMangle(ovi) "`n"
}
StringTrimRight, sbTxt, sbTxt, 1
GuiControl,, Ctrl_SBText, % sbTxt
GuiControlGet, bSlow,, Ctrl_IsSlow
if bSlow
{
DetectHiddenText, Off
WinGetText, ovVisText
DetectHiddenText, On
WinGetText, ovAllText
}
else
{
ovVisText := WinGetTextFast(false)
ovAllText := WinGetTextFast(true)
}
GuiControl,, Ctrl_VisText, % ovVisText
GuiControl,, Ctrl_AllText, % ovAllText
return
GuiClose:
ExitApp
WinGetTextFast(detect_hidden)
{
WinGet controls, ControlListHwnd
static WINDOW_TEXT_SIZE := 32767
VarSetCapacity(buf, WINDOW_TEXT_SIZE * (A_IsUnicode ? 2 : 1))
text := ""
Loop Parse, controls, `n
{
if !detect_hidden && !DllCall("IsWindowVisible", "ptr", A_LoopField)
continue
if !DllCall("GetWindowText", "ptr", A_LoopField, "str", buf, "int", WINDOW_TEXT_SIZE)
continue
text .= buf "`r`n"
}
return text
}
GetClientSize(hWnd, ByRef w := "", ByRef h := "")
{
VarSetCapacity(rect, 16)
DllCall("GetClientRect", "ptr", hWnd, "ptr", &rect)
w := NumGet(rect, 8, "int")
h := NumGet(rect, 12, "int")
}
WinToClient(hWnd, ByRef x, ByRef y)
{
WinGetPos wX, wY,,, ahk_id %hWnd%
x += wX, y += wY
VarSetCapacity(pt, 8), NumPut(y, NumPut(x, pt, "int"), "int")
if !DllCall("ScreenToClient", "ptr", hWnd, "ptr", &pt)
return false
x := NumGet(pt, 0, "int"), y := NumGet(pt, 4, "int")
return true
}
textMangle(x)
{
if pos := InStr(x, "`n")
x := SubStr(x, 1, pos-1), elli := true
if StrLen(x) > 40
{
StringLeft, x, x, 40
elli := true
}
if elli
x .= " (...)"
return x
}
FreezeDisplay:
Gui %hGui%:Default
isUpd := !isUpd
SetTimer, Update, % isUpd ? "On" : "Off"
GuiControl,, Ctrl_Freeze, % isUpd ? txtNotFrozen : txtFrozen
return

vkhu
Posts: 10
Joined: 04 Oct 2018, 00:40

Re: How to change the freeze hotkey in Window Spy?

Post by vkhu » 18 Apr 2022, 07:28

Incredible, thank you!

b0dhimind
Posts: 18
Joined: 20 May 2015, 11:41

Re: How to change the freeze hotkey in Window Spy?

Post by b0dhimind » 11 Aug 2022, 19:04

Any way to modify v2 WinSpy to have a hotkey for freezing instead?

I tried adding this to WinSpy.ahk and it didn't work.

Code: Select all

#a::
{
	if (frozen := !frozen)
	{
		SetTimer, Update, Off
		GuiControl, %hGui%:, Ctrl_Freeze, % txtFrozen
	}
	else
	{
		SetTimer, Update, On
	}
return
}

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: How to change the freeze hotkey in Window Spy?

Post by lexikos » 12 Aug 2022, 20:16

Note: Modifications to WindowSpy.ahk in the installation directory may be overwritten by the AutoHotkey v1 installer, or by the v2 installer if the previous installation was v1.

However, the v2 installer creates a WindowSpy.ahk which runs either A_MyDocuments\AutoHotkey\WindowSpy.ahk or InstallDir\UX\WindowSpy.ahk. This redirection also works for the "Window Spy" menu option in v1 scripts. So if you have AutoHotkey v2 installed, save your customizations to the former path.


@b0dhimind What is "v2 WinSpy"?

AutoHotkey v2.0-beta.7 includes a version of WindowSpy.ahk, which is obviously written for AutoHotkey v2.0-beta. The code you have posted is apparently for AutoHotkey v1, so of course it wouldn't work. The syntax of commands and structure of the GUI system are different.

The current version of WindowSpy.ahk included with v1 has

Code: Select all

~*Ctrl::
~*Shift::
SetTimer, Update, Off
UpdateText("Ctrl_Freeze", txtFrozen)
return

~*Ctrl up::
~*Shift up::
SetTimer, Update, On
return
which can be replaced with

Code: Select all

#a::
	if frozen := !frozen
	{
		SetTimer, Update, Off
		UpdateText("Ctrl_Freeze", txtFrozen)
	}
	else
		SetTimer, Update, On
return
You may also wish to change the values of txtFrozen and txtNotFrozen at the top of the script.

For AutoHotkey v2, the current version of WindowSpy.ahk has

Code: Select all

~*Shift::
~*Ctrl::suspend_timer()

~*Ctrl up::
~*Shift up::SetTimer Update, 250
which can be replaced with

Code: Select all

#a::
{
    static frozen := false
    if frozen := !frozen
        suspend_timer
    else
        SetTimer Update, 250
}
The display text can be changed in WinSpyGui() near the top of the file.

b0dhimind
Posts: 18
Joined: 20 May 2015, 11:41

Re: How to change the freeze hotkey in Window Spy?

Post by b0dhimind » 07 Sep 2022, 22:57

Sorry I was actually referring to a second version of WinSpy that I found on Reddit here:
https://www.reddit.com/r/AutoHotkey/comments/aled4x/comment/efdftue

I modified the hotkeys for sure and added the process directory info and widened some boxes and added a reload button.
I wonder how others have modified WinSpy to make it more friendly. Definitely added to my toolbox along with UIA.

Code: Select all

#NoEnv
; #NoTrayIcon
{ ;LOAD ICON
	RegExMatch(A_ScriptName, "\w+$", A_ScriptName_Extension)
	; Script_icon := SubStr(A_ScriptDir, 1, InStr(SubStr(A_ScriptDir,1,-1), "\", 0, 0, 2)-1) . "\ico\computer-desktop.png" ;FOR !OTHERSCRIPTS
	; MsgBox, % Script_icon
	; If (A_ScriptName_Extension = "ahk") and FileExist(Script_icon)
		Menu, Tray, Icon, Shell32.dll, 56
		; Menu, Tray, Icon, Script_icon, 56
		; Menu, Tray, Icon, Script_icon, 1
}
#SingleInstance
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1
CoordMode, Pixel, Screen

txtNotFrozen := "Hold Ctrl or Shift to suspend updates`n!F1 toggles freeze status"
txtFrozen := "Updates suspended`n!F1 toggles freeze status"
txtMouseCtrl := "Control Under Mouse Position"
txtFocusCtrl := "Focused Control"

Gui, New, hwndhGui AlwaysOnTop Resize MinSize
Gui, Add, Text, , `nWindow Title, Class and Process:
Gui, Add, Button, gReloadWinSpy vReloadWinSpy Centeryp yp xp+260 w40, RELOAD
Gui, Add, Edit, xm w320 r6 ReadOnly -Wrap vCtrl_Title
Gui, Add, Text,, Mouse Position:
Gui, Add, Edit, w320 r4 ReadOnly vCtrl_MousePos
Gui, Add, Text, w320 vCtrl_CtrlLabel, % txtFocusCtrl ":"
Gui, Add, Edit, w320 r4 ReadOnly vCtrl_Ctrl
Gui, Add, Text,, Active Window Position:
Gui, Add, Edit, w320 r2 ReadOnly vCtrl_Pos
Gui, Add, Text,, Status Bar Text:
Gui, Add, Edit, w320 r2 ReadOnly vCtrl_SBText
Gui, Add, Checkbox, vCtrl_IsSlow, Slow TitleMatchMode
Gui, Add, Text,, Visible Text:
Gui, Add, Edit, w320 r4 ReadOnly vCtrl_VisText
Gui, Add, Text,, All Text:
Gui, Add, Edit, w320 r4 ReadOnly vCtrl_AllText
Gui, Add, Text, w200 r2 vCtrl_Freeze, % txtNotFrozen
Gui, Add, Checkbox, Checked1 yp xp+220 w100 Right vCtrl_FollowMouse, Follow Mouse
; Gui, Show, NoActivate yCenter x0, Window Spy
Gui, Show, % "x" A_ScreenWidth - 350 " yCenter NoActivate", Window Spy
; MsgBox, % GuiWidth " " GuiHeight " " A_ScreenWidth
GetClientSize(hGui, temp)
horzMargin := temp*96//A_ScreenDPI - 320
SetTimer, Update, 250
return

ReloadWinSpy(CtrlHwnd:=0, GuiEvent:="", EventInfo:="", ErrLvl:=""){
	Reload
	Return
}

GuiSize:
Gui %hGui%:Default
if !horzMargin
	return
SetTimer, Update, % A_EventInfo=1 ? "Off" : "On" ; Suspend on minimize
ctrlW := A_GuiWidth - horzMargin
list = Title,MousePos,Ctrl,Pos,SBText,VisText,AllText,Freeze
Loop, Parse, list, `,
	GuiControl, Move, Ctrl_%A_LoopField%, w%ctrlW%
GuiWidth := A_GuiWidth
GuiHeight := A_GuiHeight
return

Update:
Gui %hGui%:Default
GuiControlGet, Ctrl_FollowMouse
CoordMode, Mouse, Screen
MouseGetPos, msX, msY, msWin, msCtrl
actWin := WinExist("A")
if Ctrl_FollowMouse
{
	curWin := msWin
	curCtrl := msCtrl
	WinExist("ahk_id " curWin)
}
else
{
	curWin := actWin
	ControlGetFocus, curCtrl
}
WinGetTitle, t1
WinGetClass, t2
if (curWin = hGui || t2 = "MultitaskingViewFrame") ; Our Gui || Alt-tab
{
	UpdateText("Ctrl_Freeze", txtFrozen)
	return
}
UpdateText("Ctrl_Freeze", txtNotFrozen)
WinGet, t3, ProcessName
WinGet, t4, PID
WinGet, t5, ID
WinGet, t6, ProcessPath
UpdateText("Ctrl_Title", t1 "`nahk_class " t2 "`nahk_exe " t3 "`nahk_pid " t4 "`nahk_id " t5 "`n" t6)
CoordMode, Mouse, Relative
MouseGetPos, mrX, mrY
CoordMode, Mouse, Client
MouseGetPos, mcX, mcY
PixelGetColor, mClr, %msX%, %msY%, RGB
mClr := SubStr(mClr, 3)
UpdateText("Ctrl_MousePos", "Screen:`t" msX ", " msY " (less often used)`nWindow:`t" mrX ", " mrY " (default)`nClient:`t" mcX ", " mcY " (recommended)"
	. "`nColor:`t" mClr " (Red=" SubStr(mClr, 1, 2) " Green=" SubStr(mClr, 3, 2) " Blue=" SubStr(mClr, 5) ")")
UpdateText("Ctrl_CtrlLabel", (Ctrl_FollowMouse ? txtMouseCtrl : txtFocusCtrl) ":")
if (curCtrl)
{
	ControlGetText, ctrlTxt, %curCtrl%
	cText := "ClassNN:`t" curCtrl "`nText:`t" textMangle(ctrlTxt)
	ControlGetPos cX, cY, cW, cH, %curCtrl%
	cText .= "`n`tx: " cX "`ty: " cY "`tw: " cW "`th: " cH
	WinToClient(curWin, cX, cY)
	ControlGet, curCtrlHwnd, Hwnd,, % curCtrl
	GetClientSize(curCtrlHwnd, cW, cH)
	cText .= "`nClient:`tx: " cX "`ty: " cY "`tw: " cW "`th: " cH
}
else
	cText := ""
UpdateText("Ctrl_Ctrl", cText)
WinGetPos, wX, wY, wW, wH
GetClientSize(curWin, wcW, wcH)
UpdateText("Ctrl_Pos", "`tx: " wX "`ty: " wY "`tw: " wW "`th: " wH "`nClient:`tx: 0`ty: 0`tw: " wcW "`th: " wcH)
sbTxt := ""
Loop
{
	StatusBarGetText, ovi, %A_Index%
	if ovi =
		break
	sbTxt .= "(" A_Index "):`t" textMangle(ovi) "`n"
}
StringTrimRight, sbTxt, sbTxt, 1
UpdateText("Ctrl_SBText", sbTxt)
GuiControlGet, bSlow,, Ctrl_IsSlow
if bSlow
{
	DetectHiddenText, Off
	WinGetText, ovVisText
	DetectHiddenText, On
	WinGetText, ovAllText
}
else
{
	ovVisText := WinGetTextFast(false)
	ovAllText := WinGetTextFast(true)
}
UpdateText("Ctrl_VisText", ovVisText)
UpdateText("Ctrl_AllText", ovAllText)
return

GuiClose:
ExitApp

WinGetTextFast(detect_hidden)
{
	; WinGetText ALWAYS uses the "Slow" mode - TitleMatchMode only affects the
	; WinText/ExcludeText parameters.  In "Fast" mode, GetWindowText() is used
	; to retrieve the text of each control.
	WinGet controls, ControlListHwnd
	static WINDOW_TEXT_SIZE := 32767 ; Defined in AutoHotkey source.
	VarSetCapacity(buf, WINDOW_TEXT_SIZE * (A_IsUnicode ? 2 : 1))
	text := ""
	Loop Parse, controls, `n
	{
		if !detect_hidden && !DllCall("IsWindowVisible", "ptr", A_LoopField)
			continue
		if !DllCall("GetWindowText", "ptr", A_LoopField, "str", buf, "int", WINDOW_TEXT_SIZE)
			continue
		text .= buf "`r`n"
	}
	return text
}

UpdateText(ControlID, NewText)
{
	; Unlike using a pure GuiControl, this function causes the text of the
	; controls to be updated only when the text has changed, preventing periodic
	; flickering (especially on older systems).
	static OldText := {}
	global hGui
	if (OldText[ControlID] != NewText)
	{
		GuiControl, %hGui%:, % ControlID, % NewText
		OldText[ControlID] := NewText
	}
}

GetClientSize(hWnd, ByRef w := "", ByRef h := "")
{
	VarSetCapacity(rect, 16)
	DllCall("GetClientRect", "ptr", hWnd, "ptr", &rect)
	w := NumGet(rect, 8, "int")
	h := NumGet(rect, 12, "int")
}

WinToClient(hWnd, ByRef x, ByRef y)
{
	WinGetPos wX, wY,,, ahk_id %hWnd%
	x += wX, y += wY
	VarSetCapacity(pt, 8), NumPut(y, NumPut(x, pt, "int"), "int")
	if !DllCall("ScreenToClient", "ptr", hWnd, "ptr", &pt)
		return false
	x := NumGet(pt, 0, "int"), y := NumGet(pt, 4, "int")
	return true
}

textMangle(x)
{
	if pos := InStr(x, "`n")
		x := SubStr(x, 1, pos-1), elli := true
	if StrLen(x) > 40
	{
		StringLeft, x, x, 40
		elli := true
	}
	if elli
		x .= " (...)"
	return x
}

; F8::
!F1::
	win_a_toggle := !win_a_toggle
	If win_a_toggle
		UpdateText("Ctrl_Freeze", txtFrozen)
	SetTimer, Update, % (win_a_toggle ? "Off" : "On")
Return


~*Ctrl::
~*Shift::
If !win_a_toggle
{
	SetTimer, Update, Off
	UpdateText("Ctrl_Freeze", txtFrozen)
}
return

~*Ctrl up::
~*Shift up::
If !win_a_toggle
{
	SetTimer, Update, On
}
return

Post Reply

Return to “Ask for Help (v1)”