 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Sun Mar 12, 2006 4:52 pm Post subject: WinInfo Menu |
|
|
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
| Code: | 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 
Last edited by Jon on Mon Mar 13, 2006 10:31 pm; edited 4 times in total |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Sun Mar 12, 2006 10:55 pm Post subject: |
|
|
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  _________________
 |
|
| Back to top |
|
 |
robiandi Guest
|
Posted: Mon Mar 13, 2006 4:33 am Post subject: |
|
|
| As Titan writes "This is a must-have script". Thanks. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6264
|
Posted: Mon Mar 13, 2006 6:10 am Post subject: |
|
|
Nice & Very Useful Script !
Thanks for sharing it - Regards,
Comment:^LButton (Control LeftClick) is not supported in Win9x, I assigned a different hotkey. _________________
 |
|
| Back to top |
|
 |
AHKnow* Guest
|
Posted: Mon Mar 13, 2006 7:32 am Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Mon Mar 13, 2006 1:03 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Mon Mar 13, 2006 1:17 pm Post subject: |
|
|
I guess you could combine all the "put to clipboard" subroutines to a single one with using A_ThisMenuItem. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1239
|
Posted: Mon Mar 13, 2006 1:25 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Mon Mar 13, 2006 2:07 pm Post subject: |
|
|
| Good points. |
|
| Back to top |
|
 |
AHKnow* Guest
|
Posted: Mon Mar 13, 2006 2:44 pm Post subject: |
|
|
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.autohotkey.com/forum/viewtopic.php?t=4679 ) could make great replacement for AU3_Spy or least could be included too. |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Mon Mar 13, 2006 2:52 pm Post subject: |
|
|
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.
| Quote: | | 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.
| Quote: | | It would need to support status bar text |
I forgot about that. I will add it in tonight.
| Quote: | | normal and slow titlematch modes |
I'll add that as well.
| Quote: | | 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.
| Quote: | | 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:
| AHKnow* wrote: | 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.autohotkey.com/forum/viewtopic.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 
Last edited by Jon on Mon Mar 13, 2006 5:31 pm; edited 1 time in total |
|
| Back to top |
|
 |
Jon as Guest Guest
|
Posted: Mon Mar 13, 2006 2:59 pm Post subject: |
|
|
| Quote: | 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 |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Mon Mar 13, 2006 3:46 pm Post subject: |
|
|
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:
| Code: | ;----------------------------------------------------------------
;--- 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. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|