AutoHotkey Community

It is currently May 27th, 2012, 10:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next

What do you think about this wsh
Cmon Chris, add this FFS !
No Chris, don't listen to them !
You may select 1 option

View results
Author Message
 Post subject: ListVars
PostPosted: September 1st, 2007, 10:32 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Last edited by majkinetor on December 19th, 2007, 9:39 pm, edited 6 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2007, 4:12 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I seem to remember someone (Laszlo?) made a function that silently captures the contents of ListVars, perhaps without having to show the window.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2007, 7:11 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2007, 7:32 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
It is possible to do without displaying the window but not an ideal solution compared to built-in. Here's a link to the topic that you might have been thinking of: http://www.autohotkey.com/forum/viewtopic.php?t=10182


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2007, 8:08 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2007, 10:37 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2007, 1:02 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
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. :D (HWND_MESSAGE requires Windows 2000 or later.)

It does still cause the active window to flicker, though...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2007, 7:25 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
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%
       
        astr := A_IsUnicode ? "astr":"str"
        ptr := A_PtrSize=8 ? "ptr":"uint"
        hmod := DllCall("GetModuleHandle", "str", "user32.dll")
        pSFW := DllCall("GetProcAddress", ptr, hmod, astr, "SetForegroundWindow")
        pSW := DllCall("GetProcAddress", ptr, hmod, astr, "ShowWindow")
        DllCall("VirtualProtect", ptr, pSFW, ptr, 8, "uint", 0x40, "uint*", 0)
        DllCall("VirtualProtect", ptr, pSW, ptr, 8, "uint", 0x40, "uint*", 0)
        bkpSFW := NumGet(pSFW+0, 0, "int64")
        bkpSW := NumGet(pSW+0, 0, "int64")
    }

    if (A_PtrSize=8) {
        NumPut(0x0000C300000001B8, pSFW+0, 0, "int64")  ; return TRUE
        NumPut(0x0000C300000001B8, pSW+0, 0, "int64")   ; return TRUE
    } else {
        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.

---
Edit @ 2010-10-21 - Unicode builds of AutoHotkey_L require the additions shown in green (optional for the ANSI build):
Code:
        pSFW := DllCall("GetProcAddress", "uint", hmod, "astr", "SetForegroundWindow")
        pSW := DllCall("GetProcAddress", "uint", hmod, "astr", "ShowWindow")

Edit @ 2010-11-12 - Updated code and tested with AutoHotkey v1.0.48.05, AutoHotkey_L ANSI, Unicode and Unicode x64.


Last edited by Lexikos on November 12th, 2010, 9:10 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2007, 2:40 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2007, 12:02 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
@Lexikos, RE: ListGlobalVars()

Many thanks for the fantastic code! :D. I am able to save/restore global variables.

Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2007, 1:29 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
Yes, its very impressive! and far away from my possibilities. :D

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
  }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 1:17 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
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.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 2:49 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
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.
:D
Ah I forgot to ask. Are there more of such interresting switches?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 4:38 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 8:56 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear majkinetor, :)

I voted yes, but, er.. was the poll here before or was just introduced ? :roll:

Quote:
ListGlobalVars function reliable up to the point where number of variables is very big.


How big ?

:)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group