Get extended attributes of window under mouse cursor

Post your working scripts, libraries and tools
aph
Posts: 7
Joined: 29 Jan 2018, 21:53

Get extended attributes of window under mouse cursor

29 Jan 2018, 22:09

This script shows the following attributes for the window under the mouse cursor:
  • Title
  • ahk_id
  • ahk_class
  • ahk_exe
  • Full path
  • Process ID
  • hWnd
  • Control ClassNN
  • Window Text
  • Control Text
The text can be copied and won't change until you press the hotkey again.

Code: Select all

; Description: Get extended attributes of window under mouse cursor
; Permalink: https://autohotkey.com/boards/viewtopic.php?f=6&t=43544
; Author: aph
; Version: 0.6
; Hotkey: Win+w
#w::
    MouseGetPos, CursorX, CursorY, Window, ClassNN
    WinGetTitle, Title, ahk_id %Window%
    WinGetClass, ahk_class, ahk_id %Window%
    DetectHiddenText, On
    WinGetText, WindowText, ahk_id %Window%
    WinGet, WindowPID, PID, ahk_id %Window%
    WinGet, ControlText, ControlList, ahk_id %Window%
    CursorHwnd := DllCall("WindowFromPoint", "int64", CursorX | (CursorY << 32), "Ptr")
    WinGet, ControlText, ControlList, ahk_id %Window%
    StringReplace, ControlText, ControlText, `n, %A_SPACE%, All
    StringReplace, WindowText, WindowText, `n,  , All
    StringReplace, WindowText, WindowText, %A_SPACE%%A_SPACE%, , All
    If not (WindowText = "")
        WindowText = `n%WindowText%
    WinGetText, Text, ahk_id %Window%
    WinGet, ahk_exe, ProcessName, ahk_id %Window%
    WinGet, Path, ProcessPath, ahk_id %Window%
    UnderCursor = 
(
Title: %Title%
ahk_id = %Window%
ahk_exe = %ahk_exe%
ahk_class = %ahk_class%
Path: %Path%
Process ID: %WindowPID%
Control ClassNN: %ClassNN%
hWnd: %CursorHwnd%

Window Text:%WindowText%

Control Text:
%ControlText%
)
    Gui, Destroy
    SysGet, Workspace, MonitorWorkArea
    Gui, Add, Text, , Ctrl+C to copy to clipboard. Repeat %A_ThisHotkey% to update.
    Gui, Add, Edit, vInfo +Wrap w380, %UnderCursor%
    DetectHiddenWindows, On
    Gui, +LastFound +AlwaysOnTop +Owner
    Gui, Show, NoActivate h255 Hide
    GuiControl, Move, Info, h220
    AspectRatio := WorkspaceRight/WorkSpaceBottom
    GUI_ID := WinExist()
    WinGetPos, GUIX, GUIY, GUIWidth, GUIHeight, ahk_id %GUI_ID%
    Offset = 30 ; Change 30 to a lower to move GUI farther from bottom right
    Gui, Show, % "NoActivate x"WorkspaceRight-GUIWidth-WorkspaceRight/Offset/AspectRatio " y"WorkspaceBottom-GUIHeight-WorkSpaceBottom/Offset, Window under cursor
    Return
Return
I used this to make Explorer scroll like other windows when the middle mouse button is pressed: https://autohotkey.com/boards/viewtopic.php?t=43715

Based on:
Last edited by aph on 06 Feb 2018, 18:30, edited 8 times in total.
aph
Posts: 7
Joined: 29 Jan 2018, 21:53

Re: Get extended attributes of window under mouse cursor

03 Feb 2018, 00:25

Updates:
  • 0.6:
    • Add window's ahk_id, hWnd, control text, and currently hovered control's ClassNN
    • Wrap Window Text and Control Text into a single line with spaces
    • Limit height of GUI and make the edit control scrollable
    • Prevent GUI from focusing on activation
  • 0.5:
    • Add configurable offset from bottom right
    • Add current hotkey to window instructions
  • 0.4:
    • Position window to bottom right of screen size
  • 0.3:
    • Change MsgBox to GUI, making it easier to copy attributes
  • 0.2:
    • Add process path and process ID.
Known issues:
  • Sometimes hWnd comes up as 0 or doesn't update.
    • Workaround until fixed is to activate the window and then hit the hotkey.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: aseiot, Google [Bot], jp94189, SupposedToBeWorking and 50 guests