Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

WinInfo Menu


  • Please log in to reply
12 replies to this topic
Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Hello, I have created the following script which will show the information about a window/control/Pixel in a menu form. It is designed to be an alternative for window spy. It should also make it quicker to get the information and then copy it into a script.

Hover your mouse over the window\control\pixel that you want information about and then hold down the Ctrl key and Left click.

When the menu appears, click on the information that you require and it will be copied to the clipboard.

It will display the following-

- window title, class, position (coordinates, height, width), ID (Handle)
The window text is trimmed to fit in the menu but the full text will be copied to the clipboard
- Mouse Position (On screen and in Window)
- Control Name, position (coordinates, height, width), Text
- Pixel Colour in HEX and Decimal

Added 13/03/06:
- Status Bar Text + minor changes


Posted Image

Posted Image

Menu, Tray, add, About, ShowAbout
Menu, Tray, Default, About
Menu, Tray, add, Exit, Exit
Menu, Tray, NoStandard


^LButton::

MouseGetPos, MousePosX, MousePosY, CurrentWinID
CoordMode, Mouse, Screen
MouseGetPos, MousePosScreenX, MousePosScreenY, CurrentWinID, ControlName

WinGetTitle, CurrentWin, ahk_ID %CurrentWinID%

SetTitleMatchMode, Slow
WinGetTitle, CurrentWinSlow, ahk_ID %CurrentWinID%
SetTitleMatchMode, Fast

WinGetClass, CurrentWinClass, ahk_ID %CurrentWinID%

;------------------------------------------------------

Menu, Title, add, %CurrentWin%, WinSub_Title
;Menu, Title, add, %CurrentWinSlow% (match=slow), WinSub_TitleSlow
Menu, Title, add, ahk_Class %CurrentWinClass%, WinSub_Class
Menu, Title, add, ahk_id %CurrentWinID%, WinSub_ID
Menu, Main, add, Window Title, :Title

;------------------------------------------------------

WinGetPos, CurrentWinX, CurrentWinY, CurrentWinW, CurrentWinH, %CurrentWin%

Menu, WinPos, add, X: %CurrentWinX% %a_tab% Y: %CurrentWinY%, WinSub_XY
Menu, WinPos, add, W: %CurrentWinW% %a_tab% H: %CurrentWinH% , WinSub_WH
Menu, Main, add, Window Position, :WinPos

;------------------------------------------------------

WinGetText, WinText, %CurrentWin%

if WinText=
Menu, Text, add, No Text Found, WinSub_Text

StringSplit, WinTextShort, WinText, `n

Loop, %WinTextShort0%
{
  StringTrimLeft, NewLine, WinTextShort%a_index%, 0

  if NewLine=
    continue

  if (strlen(NewLine) > 100)
  {
    StringLeft, NewLine, NewLine, 100
    NewLine=%NewLine% ---8<---
  }

  Menu, Text, add, %NewLine%, WinSub_Text

  if a_index>15
  {
    Menu, Text, add, -------------8<-------------, WinSub_Text
    break
  }
}

Menu, Main, add, Window Text, :Text
Menu, Main, add

;------------------------------------------------------

loop, 5
{
  StatusBarGetText, Part, %a_index%, %CurrentWin%
  if Part <> 
  { 
    x=1
    Menu, Status, add, %a_index%) %Part%, StatusSub
  }
}

if x <> 1
Menu, Status, add, No Text Found, Status

Menu, Main, add, Status Bar, :Status

;------------------------------------------------------

Menu, MousePos, add, Screen, MouseSub_ScreenXY
Menu, MousePos, add, X: %MousePosScreenX% %a_tab% Y: %MousePosScreenY%, MouseSub_ScreenXY
Menu, MousePos, add
Menu, MousePos, add, Window, MouseSub_WindowXY
Menu, MousePos, add, X: %MousePosX% %a_tab% Y: %MousePosY%, MouseSub_WindowXY
Menu, Main, add, Mouse Position, :MousePos

;------------------------------------------------------

ControlGetPos, ControlPosX, ControlPosY, ControlPosW, ControlPosH, %ControlName%, %CurrentWin%
ControlGetText, ControlText, %ControlName%, %CurrentWin%

if ControlText=
Menu, ControlText, add, No Text Found, ControlSub_Text

StringSplit, ControlTextShort, ControlText, `n
Loop, %ControlTextShort0%
{
  StringTrimLeft, NewLine, ControlTextShort%a_index%, 0

  if NewLine=
    continue

  if (strlen(NewLine) > 100)
  {
    StringLeft, NewLine, NewLine, 100
    NewLine=%NewLine% ---8<---
  }
  Menu, ControlText, add, %NewLine%, ControlSub_Text

  if a_index=10
  {
    Menu, ControlText, add, -------------8<-------------, ControlSub_Text
    break
  }
}

Menu, Control, add, %ControlName%, ControlSub_Name
Menu, Control, add
Menu, Control, add, X: %ControlPosX% %a_tab% Y: %ControlPosY%, ControlSub_XY
Menu, Control, add, W: %ControlPosW% %a_tab% H: %ControlPosH%, ControlSub_WH
Menu, Control, add
Menu, Control, add, Text, :ControlText
Menu, Main, add, Control, :Control

;------------------------------------------------------

PixelGetColor, PixelRGB, MousePosX, MousePosY, RGB 
PixelGetColor, PixelBGR, MousePosX, MousePosY

x=3
loop, 3
{
  StringMid, HEX%a_index%, PixelRGB, %x%, 2
  x+=2
}

Menu, Colour, add, %PixelRGB%, PixelSub_HEX
Menu, Colour, add, % "R: " HEXtoDEC(HEX1) "   G: " HEXtoDEC(HEX2)"   B: " HEXtoDEC(HEX3), PixelSub_DEC
Menu, Main, add, Pixel Colour (RGB), :Colour

;------------------------------------------------------

Menu, Main, Show

;Clears Menus

Menu, Main, DeleteAll
Menu, Control, DeleteAll
Menu, ControlText, DeleteAll
Menu, MousePos, DeleteAll
Menu, WinPos, DeleteAll
Menu, Text, DeleteAll
Menu, Title, DeleteAll
Menu, Colour, DeleteAll
Menu, Status, DeleteAll

return

;------------------------------------------------------


WinSub_Title:
Clipboard=%CurrentWin%
return

WinSub_TitleSlow:
Clipboard=%CurrentWinSlow%
return

WinSub_Class:
Clipboard=AHK_class %CurrentWinClass%
return

WinSub_ID:
Clipboard=AHK_ID %CurrentWinID%
return

WinSub_XY:
Clipboard=%CurrentWinX% `, %CurrentWinY%
return

WinSub_WH:
Clipboard=%CurrentWinW% `, %CurrentWinH%
return

WinSub_Text:
Clipboard=%WinText%
return

MouseSub_ScreenXY:
Clipboard=%MousePosScreenX% `, %MousePosScreenY%
return

MouseSub_WindowXY:
Clipboard=%MousePosX% `, %MousePosY%
return

ControlSub_Name:
Clipboard=%ControlName%
return

ControlSub_XY:
Clipboard=%ControlPosX% `, %ControlPosY%
return

ControlSub_WH:
Clipboard=%ControlPosW% `, %ControlPosH%
return

ControlSub_Text:
Clipboard=%ControlText%
return

PixelSub_HEX:
Clipboard=%PixelRGB%
return

PixelSub_DEC:
Clipboard:=HEXtoDEC(HEX1) " " HEXtoDEC(HEX2) " " HEXtoDEC(HEX3)
return

StatusSub:
StringTrimLeft, StatusText, A_ThisMenuItem, 3
clipboard=%StatusText%
Status:
return

;------------------------------------------------------

ShowAbout:

detecthiddenwindows, on

Gui, Add, Text, x6 y40 w180 h70, To view the menu hold down Ctrl and Left Click`n`nClick on the required menu item and it will be copied to the clipboard.
Gui, Add, Button, x50 y120 w100 h30 gGuiClose,OK  
Gui, Add, Text, x6 y10 w180 h20,WinInfo Menu by Jon 
Gui, Show, h160 w200 hide, WinInfo Menu
WinGet, hwnd, ID, WinInfo Menu
error:=DLLCall("AnimateWindow", "Uint", hwnd, "int", 2000, "int", 0x00000010) ;AW_Center
gui, show
Return

GuiClose:
error:=DLLCall("AnimateWindow", "Uint", hwnd, "int", 2000, "int", 0x00090000) ;AW_Blend
sleep, 2000
gui, Destroy
detecthiddenwindows, off
return

Exit:
Exitapp
return

;------------------------------------------------------


;My Function to converts HEX to DEC

HEXtoDEC(HEX)
{
  StringUpper, HEX, HEX
  loop, % StrLen(HEX)
  {
    StringMid, Col, HEX, % (StrLen(HEX)+1)-a_index, 1
    if Col is integer
      DEC1:=Col*16**(a_index-1)
    Else
      DEC1:=(Asc(Col)-55)*16**(a_index-1)
  DEC+=%DEC1%
  }
  return DEC
}

Comments/Suggestions/Improvements welcome

Jon :)

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
I really like the way the options are organised in a discreet menu and how information can be directly copied to the clipboard. This is a must-have script, very useful. Thanks :)

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


robiandi
  • Guests
  • Last active:
  • Joined: --
As Titan writes "This is a must-have script". Thanks.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Nice & Very Useful Script !

Thanks for sharing it - Regards, :)

Comment:^LButton (Control LeftClick) is not supported in Win9x, I assigned a different hotkey.
kWo4Lk1.png

AHKnow*
  • Guests
  • Last active:
  • Joined: --
Perhaps this should be considered for being included with AutoHotkey and replace AU3_SPY. An AutoHotkey solution, especially as a script that its users can learn from and tweak, seems so much better. Nice work Jon. :D

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Great interface design. I'm not sure if this can be a complete replacement for Window Spy, so more comments on that subject would be welcome (and I've made a note to review it more thoroughly). Thanks.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I guess you could combine all the "put to clipboard" subroutines to a single one with using A_ThisMenuItem.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
It would need to support status bar text and to have additional entries for visible and hidden text and normal and slow titlematch modes to be a complete replacement for Window Spy. It certainly has its advantages over window spy, but I'm not quite sure if it could be a complete replacement because sometimes I watch window spy while moving the mouse around a program to see what it picks up - that's not really possible with a menu-driven interface.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Good points.

AHKnow*
  • Guests
  • Last active:
  • Joined: --
I didn't say it was perfect. I think it could do better to recognize controls/classNN.

The script can use some tweaks, but the great thing is the Jon allowed the source to be available and he made it in AutoHotkey so everybody could make those tweaks too.

I think, after a while and some tweaks, WinInfo Menu and AHK Window Spy ( http://www.autohotke...opic.php?t=4679 ) could make great replacement for AU3_Spy or least could be included too.

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Thank you for all your comments and feedback :)

I think that it is more something to use alongside WindowsSpy at the moment than a replacement.

I guess you could combine all the "put to clipboard" subroutines to a single one with using A_ThisMenuItem.


I thought of doing that but I wanted to copy quite a few of them to the clipboard in a different layout than they were displayed in the menu. For example, I had to trim down the window text so that it wasn't too large for the menu and the X/Y/Height/Width values I thought would be better seperated by a comma so that they could be copied straight into a script.


Thanks for your suggestions evl.

It would need to support status bar text


I forgot about that. I will add it in tonight.

normal and slow titlematch modes


I'll add that as well.

have additional entries for visible and hidden text


I'm not sure how you would go about detecting hidden window text though. I couldn't see anything in the help files that would allow me to do it.

I watch window spy while moving the mouse around a program to see what it picks up


The only way to do that would be to have a seperate window or tooltip displaying the information changing as you move the mouse around (something like this).

I will think about adding something like that. And maybe give the option to hide or display it.


Thanks, Jon :)

edit:

I didn't say it was perfect. I think it could do better to recognize controls/classNN.

The script can use some tweaks, but the great thing is the Jon allowed the source to be available and he made it in AutoHotkey so everybody could make those tweaks too.

I think, after a while and some tweaks, WinInfo Menu and AHK Window Spy ( http://www.autohotke...opic.php?t=4679 ) could make great replacement for AU3_Spy or least could be included too.


I could have sworn that post wasn't there before :?

Jon as Guest
  • Guests
  • Last active:
  • Joined: --

I'm not sure how you would go about detecting hidden window text though. I couldn't see anything in the help files that would allow me to do it.


I hadn't noticed this command before :)

DetectHiddenText, On|Off

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
I am not a big fan of the interface with nested menus...
Of course, it is just personal preference.
I had a little WinSpy derivated from the example given in the MouseGetPos manual page.
Your script gives me the idea of beefing it up a little.
I probably won't add much more information as there are already a lot...
I don't give the pixel level information, I already have various utilities giving it (like Zoom+ and DotColor) with screen loupe effect, and I see it as a distinct information.
Here is my current version:
;----------------------------------------------------------------
;--- Shift+Win+S: run a mini-WinSpy
#+s::
	If bMiniWinSpy
	{
		SetTimer WatchCursor, Off
		ToolTip
		Hotkey ^c, Off
	}
	Else
	{
		SetTimer WatchCursor, 200
		Hotkey ^c, MWS_Snapshot
	}
	bMiniWinSpy := not bMiniWinSpy
Return

WatchCursor:
	; Get relative coordinates, and additional data
	MouseGetPos xr, yr, id, control
	; Get absolute coordinates
	CoordMode Mouse, Screen
	MouseGetPos xs, ys
	; Restore default
	CoordMode Mouse, Relative
	; Get other information: window level
	WinGetTitle title, ahk_id %id%
	WinGetClass class, ahk_id %id%
	WinGetText windowText, ahk_id %id%
	ShortenAndCleanUp(windowText)
	WinGetPos xw, yw, ww, hw, ahk_id %id%
	; Get other information: current control level
	ControlGetText controlText, %control%, ahk_id %id%
	ShortenAndCleanUp(controlText)
	ControlGetPos xc, yc, wc, hc, %control%, ahk_id %id%
	MWS_Info =
(
Window: %title%
(%windowText%)
ahk_id: %id% - ahk_class: %class%
%ww%x%hw% at %xw%, %yw%
Control: %control% (%controlText%)
%wc%x%hc% at %xc%, %yc%
Cursor: (relative) %xr%, %yr% (screen) %xs%, %ys%
)
	ToolTip %MWS_Info%
Return

MWS_Snapshot:
	Clipboard = %MWS_Info%
Return

ShortenAndCleanUp(ByRef text, length=64)
{
	StringReplace text, text, `r, ``r, All
	StringReplace text, text, `n, ``n, All
	StringReplace text, text, `r, ``t, All
	StringLeft text, text, length
}
Thanks for the additional ideas.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")