AutoHotkey Community

It is currently May 26th, 2012, 8:43 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: March 1st, 2009, 5:11 am 
Offline

Joined: March 8th, 2008, 11:36 am
Posts: 64
Location: Santa Barbara
AutoHotkey Expression Examples: "" %% () and all that.

because I can never get them right, so I made this.
Originally this was just going to be about IF statements (see sections H: , I: ), then it just started growing...

CONTENTS:

A: RETRIEVING COMMAND LINE PARAMETERS
B: COMMON THINGS AT THE BEGINNING OF AUTOHOTKEY SCRIPTS
C: WHEN TO USE %% AROUND VARIABLES x,%x%,(%x%)
D: ERASE A VARIABLE
E: SET A VARIABLE (:=) [store numbers, quoted strings]
F: SET A VARIABLE (=) [assign unquoted literal strings]
G: COPY A VARIABLE
H: IF STATEMENTS with ()
I: IF STATEMENTS without () [Translate the 1st, take the 2nd literally]
J: CHECK FOR A BLANK VARIABLE
K: STRING MANIPULATION
L: NUMBERS
M: FILE NAMES
N: REGULAR EXPRESSIONS
O: MISC AUTOHOTKEY NOTES, DEBUGGING TIPS
P: MISC AUTOHOTKEY SCRIPTS
Q: NAVIGATING WEB SITES
R: NEWBIE RECOMMENDED LEARNING SEQUENCE
S: Press ESC to cancel this scipt
T: THE AUTOHOTKEY RUN COMMAND
U: PASSING PARAMETERS TO AUTOHOTKEY SCRIPTS
V: PASSING PARAMETERS TO ANY PROGRAM


NOTE: ALL VARIABLES ARE STORED AS CHARACTER STRINGS !!!
Strings containing numbers are converted to numbers when needed, and the result is converted back to a string.

NOTE: Closing */ must be first thing on line. Otherwise you'll be asking yourself, "Why does my script stop running at this point, as if the whole rest of the script was commented out?"


Version 1.21 (08/24/2009)
Web page:
http://www.autohotkey.net/~deleyd/xprxm ... amples.htm
or download the older obsolete .ahk version from:
http://www.autohotkey.net/~deleyd/xprxm ... amples.ahk
Example of Navigating a Website:
http://www.autohotkey.net/~deleyd/xprxmp/WebsiteNav.ahk


(It's now too long to post all of it here.)

My title: "" %% (), And All That, is taken from the wonderful book, Div, Grad, Curl, And All That: An Informal Text on Vector Calculus by H. M. Schey (1973)

History:
Version 1.00 02/28/2009
Version 1.04 03/08/2009
Version 1.05 03/09/2009
Version 1.09 03/26/2009
Version 1.10 04/30/2009
Version 1.12 05/15/2009
Version 1.14 05/24/2009
Version 1.19 06/01/2009
Version 1.21 08/24/2009


Last edited by deleyd on August 25th, 2009, 6:27 am, edited 16 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 5:53 am 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Helpful!

Thanks for this.

You should consider doing some kind of clickable index version.

Perhaps if I have some time I will try ;).

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2009, 1:00 pm 
Offline

Joined: March 8th, 2008, 11:36 am
Posts: 64
Location: Santa Barbara
Version 1.04 03/08/2008
Added part A: WHEN TO USE %% AROUND VARIABLES
Code:
/*
WHEN TO USE %% AROUND VARIABLES
LESSON #1 on %%:
The only place to use %x% is where a literal string NOT enclosed in
double-quotes is expected. Otherwise, don't use %% around a variable name.
*/
;Notice in the following examples that unquoted literal strings are expected.
; = assigns unquoted literal strings
n = Ishmael
x = Call me %n%
MsgBox Call me %n%

;Example
x = 500
y = 500
z = 10
MouseMove, 500, 500, 10           ;works
MouseMove, 500 - 1, 500 + 1, 10   ;works
MouseMove,  x, y, z               ;works
MouseMove,  x - 1, y + 1, z + 2   ;works

;However, this doesn't work, because MouseMove
;doesn't expect an unquoted literal string
MouseMove, %x% - 1, %y% + 1, 10   ;doesn't work


;CONFUSION IS CAUSED BECAUSE THE FOLLOWING HAPPENS TO ALSO WORK
MouseMove, %x%, %y%, %c%          ;works

;The above works because "for backward compatibility, command parameters
;    that are documented as "can be an expression" treat an isolated name
;    in percent signs (e.g. %Var%, but not Array%i%) as though the percent
;    signs are absent."
;        --AutoHotkey Documentation: Variables and Expressions


/*
LESSON #2 on %%:
Use (%x%) when x contains the name of a 2nd variable which in
turn contains the contents you want.
*/
a = 500    ;a = "500"
b = 200    ;b = "200"
x := "a"
y := "b"
MouseMove, (%x%), (%y%)            ;x = a, a = 500.  y = b, b = 200
MouseGetPos, xpos, ypos
MsgBox xpos=%xpos%  ypos=%ypos%    ;xpos=500  ypos=200


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2009, 1:02 pm 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
wooow thanks


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 12th, 2009, 6:16 pm 
Offline

Joined: August 25th, 2005, 9:40 pm
Posts: 129
A handy interface for this might be the Scriptlet library tool

Scriptlet Library v4
http://www.autohotkey.com/forum/viewtopic.php?t=2510

should also move this thread to "scripts & functions" forum
________
IMPREZA WRX


Last edited by webber on March 11th, 2011, 12:30 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2009, 7:40 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
It's AutoHotkey, (that 'k' is lowercase) :)
Anyway, nice tutorial for newbies :D

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2009, 1:29 am 
Offline

Joined: March 8th, 2008, 11:36 am
Posts: 64
Location: Santa Barbara
Added sections H2: & I2:
COMPARING NUMERIC VALUES VS. COMPARING STRINGS

It's also available as a web page now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 3:00 am 
Offline

Joined: March 8th, 2008, 11:36 am
Posts: 64
Location: Santa Barbara
added these new sections:

T: THE AUTOHOTKEY RUN COMMAND
U: PASSING PARAMETERS TO AUTOHOTKEY SCRIPTS
V: PASSING PARAMETERS TO ANY PROGRAM

also added a new essay,

How Command Line Parameters Are Parsed
How to escape the special characters in your parameters
with numerous examples.

_________________
http://www.autohotkey.net/~deleyd/xprxm ... amples.htm


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: joetazz, Leef_me, Mickers, tidbit, tomoe_uehara and 61 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