Window Spy for AHKv2 - 2021/07/09 - beta.1

Post your working scripts, libraries and tools.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Window Spy for AHKv2 - 2021/07/09 - beta.1

Post by TheArkive » 07 Feb 2020, 11:13

Haven't seen this posted anywhere yet, or anything like it. Hope this helps someone.

Of course I didn't write this, I just updated it. Here is the original script for comparison.

User @Steely Wing also has a version of Window Spy for AHK v2 recently updated with new features.

==================================================
Updates
==================================================


:arrow: Download on GitHub

Latest commit on GitHub pull request for official Window Spy.
Last edited by TheArkive on 02 Aug 2021, 05:39, edited 38 times in total.

burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Window Spy for AHKv2

Post by burque505 » 24 Feb 2020, 14:40

@TheArkive, thanks a lot, working great on Win7 Pro 64-bit, SP1, AHK2 v2.0-a107, at 125% scaling.
Nice!
Regards,
burque505

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2

Post by TheArkive » 26 Feb 2020, 10:32

@burque505 glad to know it's helping someone :-) ... I've been wanting to mess around with AHKv2 for a while, but only a few months ago did I have time to really dig in to the installation, syntax, and everything else. I found this tool to be vital for me to find window information to figure out how to compose certain scripts.

User avatar
vvhitevvizard
Posts: 454
Joined: 25 Nov 2018, 10:15
Location: Russia

Re: Window Spy for AHKv2

Post by vvhitevvizard » 30 Apr 2020, 20:45

@TheArkive Thank u for preserving all the original calculations and stuff. This code, when compared to the original v1 code side by side, can be a good example for ones struggling to convert v1 GUI code for v2-108!

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2

Post by TheArkive » 01 May 2020, 00:56

@vvhitevvizard
That was part of the idea for sure, and it makes life easier when really digging in to AHK v2 and setting up your system to really start AHK v2 coding.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2 - 2020/06/11

Post by TheArkive » 11 Jun 2020, 12:28

Update 2020/06/11 - works with AHK v2 a110
  • a few stability fixes when quickly moving the mouse over several windows
  • converted VarSetCapacity() to BufferAlloc()
  • Added Try to a few lines to bypass errors

User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Window Spy for AHKv2 - 2020/06/18

Post by Tigerlily » 19 Jun 2020, 19:50

Looks nearly identical, not sure if this because of DPI scaling but with Win 10 at 125% DPI I get the text boxes pushed too far to the left. Here is a comparison of me running a AHK .exe file of Window Spy for v1 next to your v2 version.

Image

Nice work! I was just actually about to make this myself the other day but got distracted and did something else :p
-TL

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2 - 2020/07/01 - a113

Post by TheArkive » 01 Jul 2020, 07:21

@Tigerlily
Sorry for the late reply, the misalignment with scaling should now be fixed.

Steely Wing
Posts: 9
Joined: 12 Dec 2019, 06:26

Re: Window Spy for AHKv2 - 2020/07/31 - a121

Post by Steely Wing » 07 Sep 2020, 02:04

I have rewrite part of the script, is should more easy to read, and update for AHK version a122, please have a check if you interest.

https://github.com/steelywing/AutoHotkey-Release/blob/master/installer/source/WindowSpy.v2.ahk

And I want to change some function, may be update a few days later.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2 - 2020/07/31 - a122

Post by TheArkive » 07 Sep 2020, 08:06

Thanks @Steely Wing, I updated the OP and included your link.

My rewrite is currently working in a122 so I'm not updating mine yet. I'll take a closer look at yours at some point too.

I haven't bothered to do a true "rewrite" yet... I was just wanted to maintain a functional version for AHK v2 alpha, and I wanted to make minimal changes to preserve the original code (as mush as possible) for people looking for some potential examples of AHK v1 / v2 equivalent code.

Steely Wing
Posts: 9
Joined: 12 Dec 2019, 06:26

Re: Window Spy for AHKv2 - 2020/07/31 - a122

Post by Steely Wing » 09 Sep 2020, 09:39

Just because I have some time these days :P I added some option, it would be useful.

User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Window Spy for AHKv2 - 2020/07/31 - a122

Post by Tigerlily » 09 Sep 2020, 14:36

@TheArkive

Just tried this out again and still getting some odd control sizing again. Seems like nothing works as good as a compiled v1 version XD.

Also, you need to take out the #INCLUDE TheArkive_Debug.ahk from the top of the script since I don't think you intended to leave that in there :D

On a side note, the #SingleInstance, Ignore is annoying lol but I understand that's probably leftovers from original author.


Example:
Image

I also tried
@Steely Wing's version which appeared to work a little better visually, however I did get a string warnings and errors when trying to take this screenshot using ShareX:

Image

Errors:
Image
-TL

Steely Wing
Posts: 9
Joined: 12 Dec 2019, 06:26

Re: Window Spy for AHKv2 - 2020/07/31 - a122

Post by Steely Wing » 10 Sep 2020, 05:59

@Tigerlily, I add a error handler, please try the updated version.

User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Window Spy for AHKv2 - 2020/07/31 - a122

Post by Tigerlily » 10 Sep 2020, 11:29

@Steely Wing

Works like a charm - thank you!
-TL

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2 - 2020/09/10 - a122

Post by TheArkive » 10 Sep 2020, 13:35

@Tigerlily, thanks for the heads up. Somehow i got my wires crossed and the posted script was out of sync with what i actually have.

Also, changed -DPIScale to +DPIScale, that seems to have fixed it on my end. Let me know if not.

@Steely Wing thanks for the updates :) ... let me know if your link ever changes so i can update the OP.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2 - 2021/03/08 - a128

Post by TheArkive » 08 Mar 2021, 06:06

2021/03/08
  • updated for a128
  • added &VarRef entries where needed
  • declared Global oGui where needed within functions
  • changed function references from strings to the function name (unquoted)
  • ~*Ctrl:: and ~*Shift:: have been changed to ~Ctrl:: and ~Shift (the * seemed to break both the key up and key down events when present on the keydown event)

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

Re: Window Spy for AHKv2 - 2021/05/08 - a134

Post by lexikos » 21 May 2021, 23:38

Would you like to submit a pull request to AutoHotkey-Release, adding this under installer/source/WindowSpy.v2.ahk? (Ideally after fixing the following issues.)

Your indentation style looked a bit strange, until I realized that some lines used spaces and the rest used tabs (like the original script). GitHub shows the tabs as 8 spaces, so it really stands out.

The script often shows an error message when I close a window, or (strangely enough) open a window. It also shows an error message if I activate a hidden window, which happens when any script displays a popup menu with Menu Name, Show or MenuObj.Show(). It is impossible to predict when the target window will be closed, so I suppose it would be appropriate to abort the update when an error occurs. At first I thought it could empty the GUI or show that there was an error, but a subsequent update would overwrite it, and if there's no subsequent update (because a hidden window is still active), it's better to retain whatever was already in the GUI. This appears to be sufficient:

Code: Select all

Update() { ; timer, no params
	try TryUpdate()
}

TryUpdate() {
	...
Steely Wing's version uses OnError to suppress all error messages. I would not use OnError this way in an "official" script, even if the end result is actually the same.

There are (at least?) two errors in WinGetTextFast:
  1. The buffer size is half what it should be (also, I would remove the comment; Buffer and A_IsUnicode never existed in the same version).
  2. The lack of "`r`n" causes all of the text to be lumped together, like SourceSourceRunAHKToolbar4SciTETab.

Code: Select all

		buf := Buffer(WINDOW_TEXT_SIZE * 1,0) ; Buffer(WINDOW_TEXT_SIZE * (A_IsUnicode ? 2 : 1),0)
		...
			; text .= buf "`r`n"
			text .= StrGet(buf)
The error handling in WinGetTextFast makes it closer to its counterpart in Window Spy v1, but inconsistent with WinGetText. I think it would be better to instead let exceptions propagate to the caller, so they are handled (or unhandled) the same way as for WinGetText. In other words, remove Try, If and Else and let the caller handle the error.

Code: Select all

	controls := ""
    Try controls := WinGetControlsHwnd() ; "ahk_id " curWin

    If (Type(controls) = "Array") {
        ...
    } Else
        return ""
Alternatives (not preferred)
; WinGetText ALWAYS uses the "fast" mode - TitleMatchMode only affects to retrieve the text
; of each control. WinText/ExcludeText parameters. In Slow mode, GetWindowText() is used.
The part in red appears to be a copy-paste error, or maybe a failed attempt to fix the "slow" and "fast" being around the wrong way, which is an error in the original script. The fixed version of the original comment is:
; WinGetText ALWAYS uses the "slow" mode - TitleMatchMode only affects
; WinText/ExcludeText parameters. In "fast" mode, GetWindowText() is used
; to retrieve the text of each control.
This code, when compared to the original v1 code side by side, can be a good example for ones struggling to convert v1 GUI code for v2
:thumbup:

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2 - 2021/05/08 - a134

Post by TheArkive » 22 May 2021, 02:11

Ok sounds good! I'll work on those errors then submit a pull request.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Window Spy for AHKv2 - 2021/05/08 - a134

Post by TheArkive » 22 May 2021, 03:10

@lexikos

Do you want me to remove all the instances of Try in the TryUpdate func? Your solution of wrapping it in its own func and using one Try statement is of course cleaner.

EDIT: All those Try instances were me trying to do what you just suggested :P

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

Re: Window Spy for AHKv2 - 2021/05/08 - a134

Post by lexikos » 22 May 2021, 05:51

No. The overall try should cover cases where the target window disappears mid-update or wasn't detected to begin with, but there are other possible errors.

For instance, curCtrlClassNN := ControlGetClassNN(curCtrl) will fail if there is no control, so now the info won't update if "Follow Mouse" is on and you mouse over the window itself and not a control; or if the window has no controls. It's actually not even used until after if (curCtrl) is checked, so it should just be moved there (no try needed for that one).

I would suggest replacing GetClientSize with WinGetClientPos. Aside from eliminating redundant code, it might be useful to show the position of the client area (which is in screen coordinates) rather than x: 0 y: 0.

Post Reply

Return to “Scripts and Functions (v2)”