Debugging AutoHotKey scripts for SciTE users

Helpful script writing tricks and HowTo's
User avatar
Joe Glines
Posts: 397
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Debugging AutoHotKey scripts for SciTE users

02 Jan 2014, 21:21

I read a few posts on the forum about SciTE's built in debugging features however it wasn't straight-forward to me so I made a short video that helps show how to use it. Fincs has an awesome customized version for AutoHotKey which you can get here: http://fincs.ahk4.net/scite4ahk/

You can watch the ~6 minute video here and my script (which was built merely to show some of the tools) is below.

[youtube]https://www.youtube.com/watch?v=M2mMfpEt8ok[/youtube]

I should have prefaced my post with the warning that I am NOT a programmer. I might use incorrect terms here and there and I'm sure there are more elegant ways to demonstrate this but it should suffice for the basics.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by Joe Glines on 18 Jul 2016, 07:11, edited 1 time in total.
vasili111
Posts: 696
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: Debugging AutoHotKey scripts for SciTE users

29 Jan 2014, 04:43

Very nice video. Thank you!
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
User avatar
Grendahl
Posts: 158
Joined: 30 Sep 2013, 08:21

Re: Debugging AutoHotKey scripts for SciTE users

31 Jan 2014, 09:29

Thanks for doing the video, the variable list means no more needing to use ListVars use for me!!!
User avatar
fincs
Posts: 500
Joined: 30 Sep 2013, 14:17
GitHub: fincs
Location: Seville, Spain
Contact:

Re: Debugging AutoHotKey scripts for SciTE users

14 Feb 2014, 15:25

Really nice tutorial :)
fincs
Windows 10 x64 Build 14393 / AutoHotkey v1.1.24.04
Get SciTE4AutoHotkey v3.0.06.01 - [My project list]
User avatar
Joe Glines
Posts: 397
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Debugging AutoHotKey scripts for SciTE users

16 Dec 2015, 22:07

I learned a few more things about using SciTE to debug and thought I'd document it in the below video. I also give short review of using the dmp function for displaying what text is in an object/array. (Newbies that are not used to playing with objects or arrays will find this very helpful)
[youtube]https://www.youtube.com/watch?v=9s_awT4n8AM[/youtube]

I also realized that the SciTE output pane can be used as a command prompt. I'm sure there are more uses for it, but I didn't realize I could easily submit commands from it. :)
Last edited by Joe Glines on 18 Jul 2016, 07:38, edited 1 time in total.
User avatar
evilC
Posts: 3144
Joined: 27 Feb 2014, 12:30

Re: Debugging AutoHotKey scripts for SciTE users

17 Dec 2015, 14:58

Joe, there is an even better (imho) way of doing this.
Download DebugView from the microsoft site.
This is an app that traps debug messages from other apps - anything you output with OutputDebug will appear in debugview.
If you want to clear the debug view window, do OutputDebug DBGVIEWCLEAR (case for the debug message is important).
Then in scite, do Options->Open User properties, and add ahk.debugger.capture.streams=0 at the end to turn off the stream viewer (it gets annoying once you have debugview).
With debugview, you may see messages from other apps, which might get annoying . so in this case you can write a logging func to prefix a string to each message:

Code: [Select all] [Download] GeSHi © Codebox Plus

Log(str){
OutputDebug % "MyAppName: " str
}

Then in debugview, add a filter: MyFunc: * and you only see debug info from your app.
Usually it isnt an issue tho, you dont have to bother.
User avatar
Joe Glines
Posts: 397
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Debugging AutoHotKey scripts for SciTE users

17 Dec 2015, 19:41

Sounds both cool and a bit complex. I like my current method as it is simple and easy but I'm looking forward to trying your suggestion (especially when I have complicated debug issues) Thanks evilC for taking the time to write it out!
User avatar
evilC
Posts: 3144
Joined: 27 Feb 2014, 12:30

Re: Debugging AutoHotKey scripts for SciTE users

18 Dec 2015, 03:57

It's not complex, at it's simplest level, just run debugview and close the stream viewer. I find the stream viewer really annoying as it pops up in front of your code and you invariably have to move it around.
With debugview, you just arrange your scite window and debugview window how you want and then forget about it. Personally, I normally put use Gui, Show, x0 y0 in my gui scripts when writing them, so the gui always appears top left, with the scite window to the right of that and the debugview window at the bottom.
User avatar
Joe Glines
Posts: 397
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Debugging AutoHotKey scripts for SciTE users

18 Dec 2015, 07:13

@evilC- I made the changes and tested it. Yes, I definitely prefer the DebugView window over the StreamViewer. I too would get annoyed with where StremViewer would end up. Having this on it's own (besides being able to track alll debug commands) is pretty awesome! Thanks for sharing!
haichen
Posts: 135
Joined: 09 Feb 2014, 08:24

Re: Debugging AutoHotKey scripts for SciTE users

21 Dec 2015, 09:03

I am using Lexikos ListGlobalVars() with Outputdebug (if i don't have too much vars in a script).
https://autohotkey.com/board/topic/2092 ... ntry156570
User avatar
Joe Glines
Posts: 397
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Debugging AutoHotKey scripts for SciTE users

21 Dec 2015, 10:00

@haichen , this sounds interesting however, in my example, I keep having to step through Lexicos' function during debug (which I don't think makes sense). Can you provide a working example how you use it?

Here is what I did

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
evilC
Posts: 3144
Joined: 27 Feb 2014, 12:30

Re: Debugging AutoHotKey scripts for SciTE users

21 Dec 2015, 10:07

Joe, when you are debugging, you have a number of options:

1) "Step In" (The Right arrow or F10)
This steps "into" functions etc. If you "step in" on a line that is a call to another func (eg lex's ListGlobalVars), you will debug that func.
Also, if you have SetTimers psuedo-threads running, step in can jump to those as well.

2) "Step Over" (The down arrow or F11)
This steps "over" functions etc. It will run until the next line.

3) "Step Out" (Up and left arrow, or Shift+F11)
Runs until you exit from the current function.
Useful if you accidentally "Step In" - will keep going until that function call ends.

4) Run (Play icon or F5)
Play until next breakpoint.

So TL;DR - Use Step Over (F11) to avoid debugging stuff you do not want to, and use Step Out if you Step In by mistake.
haichen
Posts: 135
Joined: 09 Feb 2014, 08:24

Re: Debugging AutoHotKey scripts for SciTE users

21 Dec 2015, 11:15

Hi Joe, if you put OutputDebug DBGVIEWCLEAR into the loop you can see it a little better. Lexikos function does the same as the listvars command. So maybe a big loop is not the best example, but if you want to have a look at all vars at a special codeline this may be an easy solution. Its like a better Msgbox, % var1 var2 var3 .. (without stopping the script and changing the active window)
User avatar
Joe Glines
Posts: 397
Joined: 30 Sep 2013, 20:49
Facebook: https://www.facebook.com/theAutomatorGuru/
Google: https://plus.google.com/105328929654286634910
GitHub: joetazz
Location: Dallas
Contact:

Re: Debugging AutoHotKey scripts for SciTE users

21 Dec 2015, 15:41

@EvilC- thanks for point out the 3rd option. I new it did behaved this way on labels but I didn't realize it would behave this way on functions too.

@haichen- I thought you meant you were using the function in the same line as Outputdebug. Thank you for the clarification.
tbolto00

Re: Debugging AutoHotKey scripts for SciTE users

26 Jan 2016, 11:53

When debugging this script using F11 (step by step); it activates notepad, but then it makes Scite the active window. Thus, when I debug the next line, it sends a 1 in Scite rather than Notepad. Is there a way to prevent Scite from constantly making itself the active window?

WinActivate, ahk_class Notepad
Send 1
Send 2
Send 3
Send 4
Send 5
User avatar
evilC
Posts: 3144
Joined: 27 Feb 2014, 12:30

Re: Debugging AutoHotKey scripts for SciTE users

26 Jan 2016, 14:31

Yeah, that's annoying. FWIW it's no better in C with Visual Studio in my experience, so I don't think it's inherently an AHK / SciTe problem.
However, it may well be fixable in SciTe4AHK as a lot of the code is actually AHK code, so if the part that focuses SciTe is AHK code, and is not fundamentally required, it could be deactivated.
Another solution would be to run an AHK script that redirects F11 to the SciTe window (eg by using ControlSend). Potentially what you could have the script do when you hit F11 would be to store the active window, send F11 to SciTe (Which would grab focus), then re-focus the window you had focused.
lexikos
Posts: 5325
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Debugging AutoHotKey scripts for SciTE users

27 Jan 2016, 01:17

You could just remove the IfWinNotActive/WinActivate lines from SciTE_RedrawLine and SciTE_EnsureFileIsOpen in SciTEDebug.ahk...

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 5 guests