 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
whynot
Joined: 06 Aug 2004 Posts: 10
|
Posted: Fri Aug 06, 2004 3:03 pm Post subject: (Probably Dumb) Newbie question re: Multi-line scripts |
|
|
I just discovered AutoHotKey, and would like to thank you for an amazing piece of software! I recently purchased a Mac, and am able to do things like global auto-completes and such, and was sorely missing this when I was working on Windows boxes. Your program was the solution!
My question is regarding multi-line, or more specifically mult-function scripts. Perhaps I'm making them more complex than they are, but I'm running into problems performing multiple commands in a script. Or more specifically, I'm seemingly unable to create multi-line scripts that recognize and process each line of code. Instead, the first command will process, and the rest are seemingly ignored.
From looking at the samples and such, it appears that multi-line scripts are possible, but where I'm getting confused is how to structure these so that each line is picked up/handled.
Here's an example:
^+SPACE:: clipboard = ;
Send, ^c/* ^v */
The above script 'should' empty the clipboard, then copy the currently selected text (if any is selected), and insert it between the beginning and ending comment brackets. Instead, it simply empties the clipboard, and the script ends.
If I remove the semi-colon, and/or put the commands all on one line (with appropriate spacing, of course), then it sets the clipboard contents equal to "Send, ^c/* ^v */" instead of processing the commands. The programmer in me wants to put a semicolon at the end of each line, or use bracketing to tell it what and how to process the lines, but this obviously isn't how AutoHotKey works.
So what is the solution? I have other examples of similar problems, but am unable to determine how to handle such items. Help! |
|
| Back to top |
|
 |
Bobo Guest
|
Posted: Fri Aug 06, 2004 8:20 pm Post subject: |
|
|
Have you checked this directives (in the help): #EscapeChar; #CommentFlag ?
As I know /* this is used to comment multipe lines aka blocks of code in AHK */
Guess that's another issue with your code.  |
|
| Back to top |
|
 |
whynot
Joined: 06 Aug 2004 Posts: 10
|
Posted: Fri Aug 06, 2004 8:33 pm Post subject: |
|
|
Have you checked this directives (in the help): #EscapeChar; #CommentFlag ?
I have - It still hasn't helped me to understand my problem though. I can do multi line scripts without a problem if I'm working within a logic loop (ie, if(){DOTHIS}).
As I know /* this is used to comment multipe lines aka blocks of code in AHK */
Guess that's another issue with your code. Rolling Eyes
Actually, the commenting piece works fine when it's bracketed. I'm just trying to understand how to do it outside a bracketed branch.
As an example, the below does exactly what I want it to do (so far... Haven't done a ton of testing yet):
^+SPACE::
SetTitleMatchMode, 2
IfWinActive, Microsoft
{
Send, ^+{SPACE}
}
else
{
clipboard =
Send, ^c/* ^v */
}
return
What this does is to copy whatever's selected, (after emptying the current clipboard contents), if anything is, and then wrap it in "bulk comments", unless it's a Microsoft App (Word, Excel, Outlook, etc) |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Fri Aug 06, 2004 9:26 pm Post subject: |
|
|
Here are few things that should help:
| Quote: | | ^+SPACE:: clipboard = ; |
Semicolons that have at least one space or tab to their left mark the start of a comment. Semicolons are never used to terminate a line (lines are terminated automatically by the linefeed (`n) character at the end of each).
Also, you can't put the first line of a multi-line subroutine on the same line as its hotkey definition. You can only do that if the subroutine consists of exactly one line. This is because there is an implicit "return" immediately after a single-line hotkey.
/* and */ can only be used to comment out a section if those symbols appear at the beginning of a line as in this example:
/*
MsgBox, This line is commented out (disabled).
MsgBox, This one too.
*/
I've clarified the documentation to reflect this. Thanks for asking since I'm sure it was a point of confusion for others too. |
|
| Back to top |
|
 |
WhyKnot Guest
|
Posted: Sat Aug 07, 2004 7:03 am Post subject: Thank you! |
|
|
Chris, that is exactly the kind of information I was looking for! Thank you very much.
BTW, I believe in supporting good software development, and so far I am very impressed with both the program, and how quickly you respond to user questions and commentary. Do you use Paypal or is there some other method of payment for people to contribute towards you as a reward, and/or incentive towards further development?
I admitedly can't afford much, but I'd like to give you something. I actually have been able to turn off Unisys's Automate 5 for most of my tasks since discovering AHK. Automate's nice, but AHK seems to be much more responsive and it has that "light-weight" feel to it, at least when compared to the aforementioned Automate 5. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
|
| Back to top |
|
 |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Sat Aug 07, 2004 9:05 pm Post subject: |
|
|
Chris, you are now $40 richer
Thanks for the program. _________________ AHK = Hella fun |
|
| Back to top |
|
 |
whynot
Joined: 06 Aug 2004 Posts: 10
|
Posted: Sat Aug 07, 2004 11:40 pm Post subject: "ChingChing" |
|
|
Make that $60.00 richer. Thanks again!  |
|
| Back to top |
|
 |
ealerner
Joined: 13 Jul 2004 Posts: 10
|
Posted: Tue Aug 17, 2004 9:03 am Post subject: Re: (Probably Dumb) Newbie question re: Multi-line scripts |
|
|
Hi whynot,
One thing I didn't see in the replies so far (though I may have missed it) is the fact that I learned about using the shortcuts for modifiers like ^ for Control, ! for Alt, etc.
These shortcuts only seem to work in the labels of hotkeys, and not within commands, such as "Send." For those, I believe that you need to specify the key name as shown in the AutoHotkey Help File documentation for the Send key, in this case:
Instead of:
Send, ^c
You would use:
Send, {CONTROLDOWN}c{CONTROLUP}
Chris, am I right on this one?
Kindest Regards.
| whynot wrote: | I just discovered AutoHotKey, and would like to thank you for an amazing piece of software! I recently purchased a Mac, and am able to do things like global auto-completes and such, and was sorely missing this when I was working on Windows boxes. Your program was the solution!
My question is regarding multi-line, or more specifically mult-function scripts. Perhaps I'm making them more complex than they are, but I'm running into problems performing multiple commands in a script. Or more specifically, I'm seemingly unable to create multi-line scripts that recognize and process each line of code. Instead, the first command will process, and the rest are seemingly ignored.
From looking at the samples and such, it appears that multi-line scripts are possible, but where I'm getting confused is how to structure these so that each line is picked up/handled.
Here's an example:
^+SPACE:: clipboard = ;
Send, ^c/* ^v */
The above script 'should' empty the clipboard, then copy the currently selected text (if any is selected), and insert it between the beginning and ending comment brackets. Instead, it simply empties the clipboard, and the script ends.
If I remove the semi-colon, and/or put the commands all on one line (with appropriate spacing, of course), then it sets the clipboard contents equal to "Send, ^c/* ^v */" instead of processing the commands. The programmer in me wants to put a semicolon at the end of each line, or use bracketing to tell it what and how to process the lines, but this obviously isn't how AutoHotKey works.
So what is the solution? I have other examples of similar problems, but am unable to determine how to handle such items. Help! |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Tue Aug 17, 2004 11:26 am Post subject: |
|
|
The reason you see things like "Send, {CONTROLDOWN}c{CONTROLUP}" so often is that I think that's the way AutoScriptWriter records modified keystrokes. However, you can use those other symbols as shorthand for the Send command. For example, these are valid:
Send, ^c
Send, +{PgUp 5}^{Right 3} ; Send 5 Shift-PgUps and 3 Ctrl-Rights
However, the below will actually send Shift-Control-C since an uppercase C is specified. Thus, modified uppercase letters should usually be avoided to cut down on confusion:
Send, ^C
Send, +^c ; equivalent, but probably clearer
The documentation for the Send command -- though fairly complete -- is a little disorganized so probably adds to the confusion. |
|
| 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
|