Help with my Control Finder script.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

Help with my Control Finder script.

Post by LAPIII » 26 Jan 2022, 21:17

I found this awesome script I've named Control Finder.ahk:

Code: Select all

CommandLine := DllCall("GetCommandLine", "Str")
If !(A_IsAdmin || RegExMatch(CommandLine, " /restart(?!\S)")) {
    Try {
        If (A_IsCompiled) {
            Run *RunAs "%A_ScriptFullPath%" /restart
        } Else {
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
        }
    }
    ExitApp
}


Menu Tray, Icon, pifmgr.DLL, 38

GetWindows()

GetWindows(){
    WinGet, WinList, List
    Loop % WinList
    {   
        ID := "ahk_id " WinList%A_Index%

        WinGet, ProcessName, ProcessName, % ID
        
        If ItemInList(ProcessName, ["chrome.exe", "explorer.exe", "AutoHotkey.exe", "scite.exe"])
            Continue
        
        WinGet, ControlList, ControlList, % ID

        ;Ignore windows without form controls
        ;If !ControlList
        ;    Continue

        WinGetTitle, WinTitle, % ID
        WinTitles .= WinTitle ? WinTitle "|" : ""
    }
    Return WinTitles
}

Gui, +AlwaysOnTop +HWNDGuiHWND
Gui, Add, DDL, Section w240 vWindowTitle Choose1, % GetWindows()
Gui, Add, Button, ys-1 gRun w80, Run
Gui, Add, Button, ys-1 gReload w80, Reload
Gui, Add, Checkbox, ys+5 vShowHidden, Show Hidden
Gui, Add, Checkbox, ys+5 vEnable, Enable All
Gui, Add, Progress, ys+4 vProgress BackgroundNavy HWNDProgress
Gui, Add, ListView, xm w800 h400, Control|Text

Gui, Show, ,Control Spy

Return

Run:
    Gui, Submit, Nohide

    WinActivate, % WindowTitle

    WinGet, ControlList, ControlList, % WindowTitle
    ControlCount := 0

    LV_Delete()
    GuiControl,, % Progress, 0

    Loop, Parse, ControlList, `n
        ControlCount++

    Loop, Parse, ControlList, `n
    {
        If ShowHidden
            Control, Show,, % A_LoopField, % WindowTitle

        If Enable
            Control, Enable,, % A_LoopField, % WindowTitle  

        ControlGetText, ControlText, % A_LoopField, % WindowTitle
        If !ControlText
            ControlText := "NULL"

        LV_Add( , A_LoopField, ControlText)
        GuiControl,, % Progress, % (A_Index / ControlCount) * 100
    }
    Loop 2
        LV_ModifyCol(A_Index, "AutoHdr")    
Return

Reload:
    ToolTip Reloading...
    LV_Delete()
    GuiControl,, WindowTitle, % "|" GetWindows()
    GuiControl, Choose, WindowTitle, 1
    ToolTip
Return

ItemInList(Item, List){    
    For Index, ListItem in List
        If (ListItem = Item)
            Return True
}

GuiClose:
GuiEscape:
    ExitApp
Return
Before it runs, I get 2 of each of these:

Image Image

gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: Help with my Control Finder script.

Post by gregster » 26 Jan 2022, 22:21

Obviously you use #warn in your own script - did you follow the suggestion from the msgboxes above to read the #Warn docs?

This would be the first step to understand warnings - if you have questions afterwards, feel free to ask.

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

Re: Help with my Control Finder script.

Post by boiler » 26 Jan 2022, 22:27

And as with the script in your other thread, you are showing a particular script, and then you are asking about why it behaves a certain way when that's not the script you ran (as gregster pointed out regarding #Warn, and there are apparently other lines you added according to the mismatch in line numbers). Show exactly what you ran because that's important in order to troubleshoot and/or give feedback.

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

Re: Help with my Control Finder script.

Post by LAPIII » 26 Jan 2022, 23:15

Sorry about my mistake. This script had this stuff above it:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines -1
#SingleInstance,Force
I just took out the #Warn directive. Can you help me correct that this GUI is always on top, can't be Snapped with # and an arrow key, and won't allow copying results.

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

Re: Help with my Control Finder script.

Post by boiler » 26 Jan 2022, 23:32

To remove the always-on-top attribute, remove +AlwaysOnTop from the line in which it appears. I don’t know how to address the window snapping issue. If you want to copy from the ListView control to the clipboard, you’ll have to modify the script so it grabs the highlighted row’s data and puts in the clipboard after you press a hotkey or click a GUI button.

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

Re: Help with my Control Finder script.

Post by LAPIII » 28 Jan 2022, 12:20

Think you boiler, can you make a script to get a single control from under the mouse, post message box, and a copy to clipboard?

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

Re: Help with my Control Finder script.

Post by boiler » 28 Jan 2022, 13:36

If you mean from the ListView control, there is an example to follow from the ListView documentation:

Code: Select all

; Create the ListView with two columns, Name and Size:
Gui, Add, ListView, r20 w700 gMyListView, Name|Size (KB)

; Gather a list of file names from a folder and put them into the ListView:
Loop, %A_MyDocuments%\*.*
    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)

LV_ModifyCol()  ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")  ; For sorting purposes, indicate that column 2 is an integer.

; Display the window and return. The script will be notified whenever the user double clicks a row.
Gui, Show
return

MyListView:
if (A_GuiEvent = "DoubleClick")
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
    ToolTip You double-clicked row number %A_EventInfo%. Text: "%RowText%"
}
return
That's how you would get the info even if you don't make it conditional on a double-click event. You can put that variable RowText in a MsgBox instead of a ToolTip or assign it to Clipboard.

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

Re: Help with my Control Finder script.

Post by LAPIII » 28 Jan 2022, 15:07

I got this:

Image

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

Re: Help with my Control Finder script.

Post by boiler » 28 Jan 2022, 15:27

That line isn't in anything I posted, and it's obviously not correct. It also looks totally unrelated to anything you posted in this thread. Is this about a totally different script having nothing to do with this thread and you just decided to post it here? It's hard to understand the context for your post.

It looks like you put what is meant to be a hotkey on the line after the Return line, and even then, that line would be incorrect because it would need two colons, not one.

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

Re: Help with my Control Finder script.

Post by LAPIII » 06 Feb 2022, 14:28

Why can't I set a hotkey to this:

Code: Select all

WinGet, cList, ControlList, A
Tooltip, The following controls are found...`n%cList%
Sleep 10000
Tooltip,
return
Esc::ExitApp

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

Re: Help with my Control Finder script.

Post by boiler » 06 Feb 2022, 16:19

Why can't you? Did you try? You just put a hotkey label in front of it:

Code: Select all

Tab::
WinGet, cList, ControlList, A
Tooltip, The following controls are found...`n%cList%
Sleep 10000
Tooltip,
return

Esc::ExitApp

By the way, it would be much better like the following so you don't have to wait 10 seconds before you can get the control list for another window:

Code: Select all

Tab::
WinGet, cList, ControlList, A
ToolTip, The following controls are found...`n%cList%
SetTimer, ToolTipOff, -10000
return

Esc::ExitApp

ToolTipOff:
ToolTip
return

Post Reply

Return to “Ask for Help (v1)”