 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| What do you think about this wsh |
| Cmon Chris, add this FFS ! |
|
80% |
[ 12 ] |
| No Chris, don't listen to them ! |
|
20% |
[ 3 ] |
|
| Total Votes : 15 |
|
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 3589 Location: Belgrade
|
Posted: Sat Sep 01, 2007 10:32 am Post subject: ListVars |
|
|
Is it possible to change this command so it returns the string that we can see in Edit, without opening GUI.
In absence of debuging in AHK it can at least help me about some things.
I imagine:
| Code: | | ListVars,result ,local|global, filter] |
We can for instance use this to findout about and iterate trough all variables user created with some prefix or to create custom interface for ListVars (for instance to hide global variables used by modules)
I guess this is trivial code change.
EDIT:
This can be replaced somwhat with minor wish
Alternative is presented here
Why is alternative bad, is presented here. _________________

Last edited by majkinetor on Wed Dec 19, 2007 9:39 pm; edited 6 times in total |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10463
|
Posted: Sat Sep 01, 2007 4:12 pm Post subject: |
|
|
| I seem to remember someone (Laszlo?) made a function that silently captures the contents of ListVars, perhaps without having to show the window. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3589 Location: Belgrade
|
Posted: Sat Sep 01, 2007 7:11 pm Post subject: |
|
|
I think its not possible to do it correctly, without showing a window for a short amount of time.
I tried even to use WinEvent hooks to intercept window creation in early phase, but window is always flashing.
Perhaps there is something I didn't do. I also searchd for Laszlo's thing and found out some examples, but those were also showing window for short amount of time.
Anyway, its trivial code detail. Why not adding it internaly in absence of more serious debug functions. It can be also very well used for loging of internal variables in case script encounters some unusualy scenario. _________________
 |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2381
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2381
|
Posted: Sat Sep 01, 2007 8:08 pm Post subject: |
|
|
| Code: | MsgBox,,Lines, % GetAhkStats("lines")
MsgBox,,Variables, % GetAhkStats("variables")
MsgBox,,Hotkeys, % GetAhkStats("hotkeys")
MsgBox,,KeyHistory,% GetAhkStats("Key history")
Return
a::a
GetAhkStats(Section="") {
DetectHiddenWindows, On
IfEqual Section,, SetEnv Section, Key
HidWin := WinExist(A_ScriptFullPath " - AutoHotkey v")
OldPar := DllCall("GetParent", UInt,HidWin)
GUI +LastFound
DllCall("SetParent", UInt,HidWin, UInt,WinExist("ahk_class Shell_TrayWnd"))
WinMenuSelectItem ahk_id %HidWin%,,View, %Section%
Sleep 0
ControlGetText Out1, Edit1, ahk_id %HidWin%
WinHide ahk_id %HidWin%
DllCall("SetParent", UInt,HidWin, UInt,OldPar)
Return Out1
} |
|
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3589 Location: Belgrade
|
Posted: Sun Sep 02, 2007 10:37 am Post subject: |
|
|
Amazing workaround !!!
This is definitely good enough replacement, but internal support would be much better, especialy as SetParent may produce unwanted effects one day, and generaly shouldn't be used in such manner. _________________
 |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2472 Location: Australia, Qld
|
Posted: Mon Sep 03, 2007 1:02 pm Post subject: |
|
|
Excellent trick!
If you set the parent to "int", -3 (HWND_MESSAGE) instead of UInt,WinExist("ahk_class Shell_TrayWnd"), AutoHotkey becomes a message-only window. This prevents it from stealing the focus, so getting variables,etc. doesn't interrupt the user. (HWND_MESSAGE requires Windows 2000 or later.)
It does still cause the active window to flicker, though... |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2472 Location: Australia, Qld
|
Posted: Wed Dec 12, 2007 7:25 am Post subject: |
|
|
Contrary to my previous post, it seems HWND_MESSAGE only allows it to "recover quicker" - the function still interferes with the active window.
That being the case, I thought I'd make another attempt at preventing it from stealing focus. My attempts at catching window messages, using LockSetForegroundWindow, etc. all failed, so I went all out, and temporarily replaced ShowWindow/SetForegroundWindow:
| Code: | Loop {
tick := A_TickCount
ToolTip % ListGlobalVars()
}
ListGlobalVars()
{
static hwndEdit, pSFW, pSW, bkpSFW, bkpSW
if !hwndEdit
{
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
Process, Exist
ControlGet, hwndEdit, Hwnd,, Edit1, ahk_class AutoHotkey ahk_pid %ErrorLevel%
DetectHiddenWindows, %dhw%
hmod := DllCall("GetModuleHandle", "str", "user32.dll")
pSFW := DllCall("GetProcAddress", "uint", hmod, "str", "SetForegroundWindow")
pSW := DllCall("GetProcAddress", "uint", hmod, "str", "ShowWindow")
DllCall("VirtualProtect", "uint", pSFW, "uint", 8, "uint", 0x40, "uint*", 0)
DllCall("VirtualProtect", "uint", pSW, "uint", 8, "uint", 0x40, "uint*", 0)
bkpSFW := NumGet(pSFW+0, 0, "int64")
bkpSW := NumGet(pSW+0, 0, "int64")
}
NumPut(0x0004C200000001B8, pSFW+0, 0, "int64") ; return TRUE
NumPut(0x0008C200000001B8, pSW+0, 0, "int64") ; return TRUE
ListVars
NumPut(bkpSFW, pSFW+0, 0, "int64")
NumPut(bkpSW, pSW+0, 0, "int64")
ControlGetText, text,, ahk_id %hwndEdit%
RegExMatch(text, "sm)(?<=^Global Variables \(alphabetical\)`r`n-{50}`r`n).*", text)
return text
} |
ListGlobalVars() neither shows nor activates the AutoHotkey main window. It is also considerably faster: on my system, 2ms vs 128ms (40ms with SetWinDelay, -1.)
It also doesn't hide the main window if it was already visible, though it does of course overwrite its contents. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1240
|
Posted: Wed Dec 12, 2007 2:40 pm Post subject: |
|
|
| lexikos wrote: | | and temporarily replaced ShowWindow/SetForegroundWindow: |
What's next? ApiHook? Well, this is what I don't want to see in the forum, but I guess it's unstoppable. Anyway, nice trick. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5574
|
Posted: Mon Dec 17, 2007 12:02 am Post subject: |
|
|
@Lexikos, RE: ListGlobalVars()
Many thanks for the fantastic code! . I am able to save/restore global variables.
 |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 99 Location: Osnabrück, Germany
|
Posted: Mon Dec 17, 2007 1:29 pm Post subject: |
|
|
Yes, its very impressive! and far away from my possibilities.
I would like to see also a ListAllIncludedFuncs() for listing the called library functions. This may be a useful debugging feature.
I've done the following two functions to start outputdebug with the script,
but to show the included functions DbgHelper_func(A_ThisFunc) must be inserted in all functions.
I put my functions in the Libfolder and with one line of code I can start debugview with my script
| Code: | DbgHelper_RunDebugView()
;or DbgHelper_RunDebugView(0) for not showing included functions
|
| Code: |
DbgHelper_func(func){
static AllFuncs:=""
global dbg91938514, ListAllUsedFunctions
IfNotInString, AllFuncs, %func%
{
If (allfuncs<>"")
AllFuncs := Func . ", " . AllFuncs
else
AllFuncs := Func
If (dbg91938514)
ListAllUsedFunctions := AllFuncs
OutputDebug, included Function= %AllFuncs% ; %Func%
}
}
DbgHelper_RunDebugView(funcOn="TRUE"){
global dbg91938514
dbg91938514 := funcOn ? 1:0
debuggerpath .= "c:\programme\autoHotkey\DebugView\Dbgview.exe"
debuggerTitel := "DebugView on \\" . A_ComputerName . " (local)"
IfExist, %debuggerpath%
IfWinNotExist, %debuggerTitel%
Run, %debuggerpath%
WinWait, %debuggerTitel%, ,3
FileGetTime, Created, %A_ScriptFullPath%, C
FormatTime, Created, Created, dd.MM.yyyy HH:mm
OutputDebug, Script= ---- %A_ScriptName% ----
OutputDebug, Created= --- %Created% ---`n`n
}
|
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2472 Location: Australia, Qld
|
Posted: Wed Dec 19, 2007 1:17 pm Post subject: |
|
|
| haichen wrote: | I would like to see also a ListAllIncludedFuncs() for listing the called library functions. This may be a useful debugging feature.
| If you mean what I think you mean, that can be done fairly easily:
| Code: | | RunWait, "%A_AhkPath%" /iLib "temp-file.ahk" "my-script-file.ahk" |
temp-file.ahk would then either be empty (no library functions) or contain a list of #includes in the form:
| Quote: | #Include library-folder
#IncludeAgain full-path-of-first-library-script.ahk
#Include library-folder
#IncludeAgain full-path-of-second-library-script.ahk
etc. |
I believe this feature is used by Ahk2Exe.
I've posted a method of avoid the temporary file on page 2 of this thread (keyword: iLib.) |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 99 Location: Osnabrück, Germany
|
Posted: Wed Dec 19, 2007 2:49 pm Post subject: |
|
|
Wow!
One Line to get all included files and three to show them in debugview.
| Code: | RunWait, "%A_AhkPath%" /iLib "%A_AppData%/temp-file.txt" "%a_scriptname%"
Fileread, includedFiles, %A_AppData%/temp-file.txt
outputdebug, Included Files:`n%includedFiles%
|
I also like your pipe-version!
And as third I (re)found fdeps from corrupt.
Ah I forgot to ask. Are there more of such interresting switches? |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3589 Location: Belgrade
|
Posted: Wed Dec 19, 2007 4:38 pm Post subject: |
|
|
Unfortunately, ListGlobalVars can not be used with certanity for now, and probably never will be, until there are some changes in AHK itself. See this.
So we need to restate the wish, if Chris decides not to add this the way it is originaly told:
Variables in ListVars window should never exceed one line, i.e. \r\n & \n have to be replaced. Its probably the best to escape them regulary, i.e. replace \n with `n and \r\n with `r`n.
This can't break scripts, and will make ListGlobalVars function reliable up to the point where number of variables is very big.
Ofcourse, update to ListVars itself would be much much cleaner option.
Honestly, I don't know why so much talk about this ? We have 0 debuging options in AHK and ListVars can't be worse. Why so much talk when requested thing is even more simple to implement then current solution, i.e. it just has to return the data before showing the window. I am sure this is one of those "10 minutes" updates... _________________
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5574
|
Posted: Wed Dec 19, 2007 8:56 pm Post subject: |
|
|
Dear majkinetor,
I voted yes, but, er.. was the poll here before or was just introduced ?
| Quote: | | ListGlobalVars function reliable up to the point where number of variables is very big. |
How big ?
 |
|
| 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
|