-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariables.htm
1032 lines (1025 loc) · 82.2 KB
/
Variables.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html lang="nl">
<head>
<title>Variables and Expressions - Definition & Usage | AutoHotkey</title>
<meta name="description" content="Learn details about variables, expressions, operators, built-in variables and capacity and memory of variables." />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="static/theme.css" rel="stylesheet" type="text/css" />
<script src="static/content.js" type="text/javascript"></script>
</head>
<body>
<h1>Variables and Expressions</h1>
<h2 id="toc">Table of Contents</h2>
<ul>
<li><a href="#Intro">Variables</a></li>
<li><a href="#Expressions">Expressions</a></li>
<li><a href="#Operators">Operators in Expressions</a></li>
<li><a href="#BuiltIn">Built-in Variables</a></li>
<li><a href="#cap">Variable Capacity and Memory</a></li>
</ul>
<span id="Variables"></span><h2 id="Intro">Variables</h2>
<p>See <a href="Concepts.htm#variables">Variables</a> for general explanation and details about how variables work.</p>
<p id="assigning"><strong>Storing values in variables</strong>: To store a string or number in a variable, there are two methods: <a href="Language.htm#legacy-syntax">legacy</a> and <a href="Language.htm#expressions">expression</a>. The legacy method uses the <a href="commands/SetEnv.htm">equal sign operator (=)</a> to assign <a href="Language.htm#unquoted-text"><strong>unquoted</strong> literal strings</a> or variables enclosed in percent signs. For example:</p>
<pre>MyNumber = 123
MyString = This is a literal string.
CopyOfVar = %Var% <em>; With the = operator, percent signs are required to retrieve a variable's contents.</em></pre>
<p>By contrast, the expression method uses the <a href="commands/SetExpression.htm">colon-equal operator (:=)</a> to store numbers, <a href="Language.htm#strings"><strong>quoted</strong> strings</a>, and other types of <a href="Language.htm#expressions">expressions</a>. The following examples are functionally identical to the previous ones:</p>
<pre>MyNumber := 123
MyString := "This is a literal string."
CopyOfVar := Var <em>; Unlike its counterpart in the previous section, percent signs are not used with the := operator.</em></pre>
<p>The latter method is preferred by many due to its greater clarity, and because it supports an <a href="Language.htm#expressions">expression syntax</a> nearly identical to that in many other languages.</p>
<p>You may have guessed from the above that there are two methods to erase the contents of a variable (that is, to make it blank):</p>
<pre>MyVar =
MyVar := ""</pre>
<p>The empty pair of quotes above should be used only with the := operator because if it were used with the = operator, it would store two literal quote-characters inside the variable.</p>
<p id="retrieving"><strong>Retrieving the contents of variables</strong>: Like the two methods of storing values, there are also two methods for retrieving them: <a href="Language.htm#legacy-syntax">legacy</a> and <a href="Language.htm#variables">expression</a>. The legacy method requires that each variable name be enclosed in percent signs to retrieve its contents. For example:</p>
<pre><a href="commands/MsgBox.htm">MsgBox</a> The value in the variable named Var is %Var%.
CopyOfVar = %Var%</pre>
<p>By contrast, the expression method omits the percent signs around variable names, but encloses <a href="Language.htm#strings">literal strings</a> in quotes. Thus, the following are the expression equivalents of the previous examples:</p>
<pre>MsgBox % "The value in the variable named Var is " . Var . "." <em>; A period is used to concatenate (join) two strings.</em>
CopyOfVar := Var</pre>
<p>In the MsgBox line above, <a href="Language.htm#-expression">a percent sign and a space</a> is used to change the parameter from legacy to expression mode. This is necessary because the legacy method is used by default by all commands, except where otherwise documented.</p>
<p><strong>Comparing variables</strong>: Please read the expressions section below for important notes about the different kinds of comparisons, especially about when to use parentheses.</p>
<h2 id="Expressions">Expressions</h2>
<p class="note">See <a href="Language.htm#expressions">Expressions</a> for a structured overview and further explanation.</p>
<p>Expressions are used to perform one or more operations upon a series of variables, literal strings, and/or literal numbers.</p>
<p>Variable names in an expression are not enclosed in percent signs (except for <a href="misc/Arrays.htm#pseudo">pseudo-arrays</a> and other <a href="#ref">double references</a>). Consequently, literal strings must be enclosed in double quotes to distinguish them from variables. For example:</p>
<pre>if (CurrentSetting > 100 or FoundColor != "Blue")
MsgBox The setting is too high or the wrong color is present.</pre>
<p>In the example above, "Blue" appears in quotes because it is a literal string. To include an <em>actual</em> quote-character inside a literal string, specify two consecutive quotes as shown twice in this example: <code>"She said, <span class="red">""</span>An apple a day.<span class="red">""</span>"</code>.</p>
<p class="warning"><strong>Note</strong>: There are several types of <a href="Language.htm#if-statement">If Statement</a> which look like expressions but are not.</p>
<p><strong>Empty strings</strong>: To specify an empty string in an expression, use an empty pair of quotes. For example, the statement <code>if (MyVar != "")</code> would be true if <em>MyVar</em> is not blank. However, in a <a href="commands/IfEqual.htm">traditional-if</a>, a pair of empty quotes is treated literally. For example, the statement <code>if MyVar = ""</code> is true only if <em>MyVar</em> contains an actual pair of quotes. Thus, to check if a variable is blank with a traditional-if, use = or != with nothing on the right side as in this example: <code>if Var =</code>.</p>
<p>On a related note, any invalid expression such as <code>(x +* 3)</code> yields an empty string.</p>
<p><strong>Storing the result of an expression</strong>: To assign a result to a variable, use the <a href="commands/SetExpression.htm">:= operator</a>. For example:</p>
<pre>NetPrice := Price * (1 - Discount/100)</pre>
<p id="Boolean"><strong>Boolean values</strong>: When an expression is required to evaluate to true or false (such as an IF-statement), a blank or zero result is considered false and all other results are considered true. For example, the statement <code>if ItemCount</code> would be false only if ItemCount is blank or 0. Similarly, the expression <code>if not ItemCount</code> would yield the opposite result.</p>
<p>Operators such as NOT/AND/OR/>/=/< automatically produce a true or false value: they yield 1 for true and 0 for false. For example, in the following expression, the variable <em>Done</em> is assigned 1 if either of the conditions is true:</p>
<pre>Done := A_Index > 5 or FoundIt</pre>
<p>As hinted above, a variable can be used to hold a false value simply by making it blank or assigning 0 to it. To take advantage of this, the shorthand statement <code>if Done</code> can be used to check whether the variable Done is true or false.</p>
<p><span id="True"></span><span id="False"></span>The words <em>true</em> and <em>false</em> are built-in variables containing 1 and 0. They can be used to make a script more readable as in these examples:</p>
<pre>CaseSensitive := false
ContinueSearch := true</pre>
<p><strong>Integers and floating point</strong>: Within an expression, numbers are considered to be floating point if they contain a decimal point; otherwise, they are integers. For most operators -- such as addition and multiplication -- if either of the inputs is a floating point number, the result will also be a floating point number.</p>
<p>Within expressions and non-expressions alike, integers may be written in either hexadecimal or decimal format. Hexadecimal numbers all start with the prefix 0x. For example, <code>Sleep 0xFF</code> is equivalent to <code>Sleep 255</code>. <span class="ver">[v1.0.46.11+]</span>: Floating point numbers written in scientific notation are recognized; but only if they contain a decimal point (e.g. <code>1<strong>.</strong>0e4</code> and <code>-2<strong>.</strong>1E-4</code>).</p>
<p id="percent-space"><strong>Force an expression</strong>: An expression can be used in a parameter that does not directly support it (except OutputVar parameters) by preceding the expression with a percent sign and a space or tab. In <span class="ver">[v1.1.21+]</span>, this prefix can be used in the InputVar parameters of all commands except the traditional IF commands (use <a href="commands/IfExpression.htm">If (expression)</a> instead). This technique is often used to access <a href="misc/Arrays.htm">arrays</a>. For example:</p>
<pre><a href="commands/FileAppend.htm">FileAppend</a>, % MyArray[i], My File.txt
<a href="commands/FileAppend.htm">FileAppend</a>, % MyPseudoArray%i%, My File.txt
<a href="commands/MsgBox.htm">MsgBox</a> % "The variable MyVar contains " . MyVar . "."
<a href="commands/Loop.htm">Loop</a> % Iterations + 1
<a href="commands/WinSet.htm">WinSet</a>, Transparent, % X + 100
<a href="commands/Control.htm">Control</a>, Choose, % CurrentSelection - 1</pre>
<h2 id="Operators">Operators in Expressions</h2>
<p class="note">See <a href="Language.htm#operators">Operators</a> for general information about operators.</p>
<p>Except where noted below, any blank value (empty string) or non-numeric value involved in a math operation is <strong>not</strong> assumed to be zero. Instead, it is treated as an error, which causes that part of the expression to evaluate to an empty string. For example, if the variable X is blank, the expression X+1 yields a blank value rather than 1.</p>
<p>For historical reasons, <em>quoted</em> numeric strings such as <code>"123"</code> are always considered non-numeric when used directly in an expression (but not when stored in a variable or returned by a function). This non-numeric attribute is propagated by <a href="#concat">concatenation</a>, so expressions like <code>"0x" n</code> also produce a non-numeric value (even when n contains valid hexadecimal digits). This problem can be avoided by assigning the value to a variable or passing it through a function like <a href="Functions.htm#Round">Round()</a>. Scripts should avoid using quote marks around literal numbers, as the behavior may change in a future version.</p>
<h3 id="operators">Expression Operators (in descending precedence order)</h3>
<table class="info">
<tr>
<th class="center">Operator</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="ref">
<td class="center bold">%Var%</td>
<td><p>If a variable is enclosed in percent signs within an expression (e.g. %Var%), whatever that variable <u>contains</u> is assumed to be the name or partial name of another variable (if there is no such variable, %Var% resolves to a blank string). This is most commonly used to reference <a href="misc/Arrays.htm#pseudo">pseudo-array</a> elements such as the following example:</p>
<pre>Var := MyArray%A_Index% + 100</pre>
<p>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. This can be avoided by enclosing the reference in parentheses; e.g. <code>Sleep (%Var%)</code>.</p>
<p><span class="ver">[AHK_L 52+]:</span> In addition to normal variables, %Var% may resolve to an <a href="Concepts.htm#environment-variables">environment variable</a>, the clipboard, or any <a href="#BuiltIn">reserved/read-only variable</a>. Prior to revision 52, %Var% yielded an empty string in these cases.</p></td>
</tr>
<tr>
<td class="center bold">x.y</td>
<td><span class="ver">[AHK_L 31+]:</span> <strong>Object access</strong>. Get or set a value or call a method of object <i>x</i>, where <i>y</i> is a literal value. See <a href="Objects.htm#Usage_Objects">object syntax</a>.</td>
</tr>
<tr id="new">
<td class="center bold">new</td>
<td><span class="ver">[v1.1.00+]:</span> Creates a new object derived from another object. For example, <code>x := new y</code> is often equivalent to <code>x := {base: y}</code>. <code>new</code> should be followed by a variable or simple class name of the form <code>GlobalClass.NestedClass</code>, and optionally parameters as in <code>x := new y(z)</code> (where <code>y</code> is a variable, not a function name). For details, see <a href="Objects.htm#Custom_Objects">Custom Objects</a>.</td>
</tr>
<tr id="IncDec">
<td class="center bold">++<br>
--</td>
<td><strong>Pre- and post-increment/decrement</strong>. Adds or subtracts 1 from a variable (but in versions prior to 1.0.46, these can be used only by themselves on a line; no other operators may be present). The operator may appear either before or after the variable's name. If it appears <em>before</em> the name, the operation is performed immediately and its result is used by the next operation. For example, <code>Var := ++X</code> increments X immediately and then assigns its value to <em>Var</em>. Conversely, if the operator appears <em>after</em> the variable's name, the operation is performed <em>after</em> the variable is used by the next operation. For example, <code>Var := X++</code> increments X only after assigning the current value of X to <em>Var</em>. Due to backward compatibility, the operators ++ and -- treat blank variables as zero, but only when they are alone on a line; for example, <code>y:=1, ++x</code> and <code>MsgBox % ++x</code> both produce a blank result when x is blank.</td>
</tr>
<tr id="pow">
<td class="center bold">**</td>
<td>
<p><strong>Power</strong>. Both the base and the exponent may contain a decimal point. If the exponent is negative, the result will be formatted as a floating point number even if the base and exponent are both integers. Since ** is of higher precedence than unary minus, <code>-2**2</code> is evaluated like <code>-(2**2)</code> and so yields -4. Thus, to raise a literal negative number to a power, enclose it in parentheses such as <code>(-2)**2</code>.</p>
<p class="note"><strong>Note</strong>: A negative base combined with a fractional exponent such as <code>(-2)**0.5</code> is not supported; it will yield an empty string. But both <code>(-2)**2</code> and <code>(-2)**2.0</code> are supported.</p>
<p class="warning"><strong>Note</strong>: Unlike its mathematical counterpart, ** is left-associative in AutoHotkey v1. For example, <code>x ** y ** z</code> is evaluated as <code>(x ** y) ** z</code>.</p>
</td>
</tr>
<tr id="unary">
<td class="center bold">-<br>
!<br>
~<br>
& *</td>
<td><p><strong>Unary minus (-)</strong>: Although it uses the same symbol as the subtract operator, unary minus applies to only a single item or sub-expression as shown twice in this example: <code><strong>-</strong>(3 / <strong>-</strong>x)</code>. On a related note, any unary plus signs (+) within an expression are ignored.</p>
<p><strong>Logical-not (!)</strong>: If the operand is blank or 0, the result of applying logical-not is 1, which means "true". Otherwise, the result is 0 (false). For example: <code>!x or !(y and z)</code>. Note: The word NOT is synonymous with <strong>!</strong> except that <strong>!</strong> has a higher precedence. <span class="ver">[v1.0.46+]</span>: Consecutive unary operators such as <code><strong>!!</strong>Var</code> are allowed because they are evaluated in right-to-left order.</p>
<p><strong>Bitwise-not (~)</strong>: This inverts each bit of its operand. If the operand is a floating point value, it is truncated to an integer prior to the calculation. If the operand is between 0 and 4294967295 (0xffffffff), it will be treated as an <u>unsigned</u> 32-bit value. Otherwise, it is treated as a <u>signed</u> 64-bit value. For example, <code>~0xf0f</code> evaluates to 0xfffff0f0 (4294963440).</p>
<p id="amp"><strong>Address (&)</strong>: <code>&MyVar</code> retrieves the address of <em>MyVar</em>'s contents in memory, which is typically used with <a href="commands/DllCall.htm#struct">DllCall structures</a>. <code>&MyVar</code> also disables the caching of binary numbers in that variable, which can slow down its performance if it is ever used for math or numeric comparisons. Caching is re-enabled for a variable whenever its address changes (e.g. via <a href="commands/VarSetCapacity.htm">VarSetCapacity()</a>).</p>
<p><strong>Dereference (*)</strong>: <code>*Expression</code> assumes that <code>Expression</code> resolves to a numeric memory address; it retrieves the byte at that address as a number between 0 and 255 (0 is always retrieved if the address is 0; but any other invalid address must be avoided because it might crash the script). However, <a href="commands/NumGet.htm">NumGet()</a> generally performs much better when retrieving binary numbers.</p></td>
</tr>
<tr id="MulDiv">
<td class="center bold">*<br>
/<br>
//
</td>
<td><p><strong>Multiply (*)</strong>: The result is an integer if both inputs are integers; otherwise, it is a floating point number.</p>
<p id="divide"><strong>True divide (/)</strong>: Unlike <a href="commands/EnvDiv.htm">EnvDiv</a>, true division yields a floating point result even when both inputs are integers. For example, <code>3/2</code> yields 1.5 rather than 1, and <code>4/2</code> yields 2.0 rather than 2.</p>
<p id="FloorDivide"><strong>Floor divide (//)</strong>: The double-slash operator uses high-performance integer division if the two inputs are integers. For example, <code>5//3</code> is 1 and <code>5//-3</code> is -1. If either of the inputs is in floating point format, floating point division is performed and the result is truncated to the nearest integer to the left. For example, <code>5//3.0</code> is 1.0 and <code>5.0//-3</code> is -2.0. Although the result of this floating point division is an integer, it is stored in floating point format so that anything else that uses it will see it as such. For modulo, see <a href="commands/Math.htm#Mod">mod()</a>.</p>
<p>The <a href="#AssignOp">*= and /= operators</a> are a shorthand way to multiply or divide the value in a variable by another value. For example, <code>Var*=2</code> produces the same result as <code>Var:=Var*2</code> (though the former performs better).</p>
<p>Division by zero yields a blank result (empty string).</p></td>
</tr>
<tr id="AddSub">
<td class="center bold">+<br>
-</td>
<td><p><strong>Add (+)</strong> and <strong>subtract (-)</strong>. On a related note, the <a href="#AssignOp">+= and -= operators</a> are a shorthand way to increment or decrement a variable. For example, <code>Var+=2</code> produces the same result as <code>Var:=Var+2</code> (though the former performs better). Similarly, a variable can be increased or decreased by 1 by using <a href="#IncDec">Var++, Var--, ++Var, or --Var</a>.</p>
</td>
</tr>
<tr id="bitwise">
<td class="center bold"><<<br>
>><br>
>>></td>
<td>
<p><strong>Bit shift left (<<)</strong>. Example usage: <code>Value1 << Value2</code>. This is equivalent to multiplying <em>Value1</em> by "2 to the <em>Value2</em>th power".</p>
<p><strong>Arithmetic bit shift right (>>)</strong>. Example usage: <code>Value1 >> Value2</code>. This is equivalent to dividing <em>Value1</em> by "2 to the <em>Value2</em>th power" and rounding the result to the nearest integer leftward on the number line; for example, <code>-3>>1</code> is -2.</p>
<p><strong>Logical bit shift right (>>>)</strong> <span class="ver">[v1.1.35+]</span>. Example usage: <code>Value1 >>> Value2</code>. Unlike arithmetic bit shift right, this does not preserve the sign of the number. For example, -1 has the same bit representation as the unsigned 64-bit integer 0xffffffffffffffff, therefore <code>-1 >>> 1</code> is 0x7fffffffffffffff.</p>
<p>For all three operators, any floating point input is truncated to an integer prior to the calculation. The results are undefined if <em>Value2</em> is less than 0 or greater than 63.</p>
</td>
</tr>
<tr>
<td class="center bold">&<br>
^<br>
|
</td>
<td><strong>Bitwise-and (&)</strong>, <strong>bitwise-exclusive-or (^)</strong>, and <strong>bitwise-or (|)</strong>. Of the three, <strong>&</strong> has the highest precedence and <strong>|</strong> has the lowest. Any floating point input is truncated to an integer prior to the calculation.</td>
</tr>
<tr id="concat">
<td class="center bold">.</td>
<td><p><strong>Concatenate</strong>. The period (dot) operator is used to combine two items into a single string (there must be at least one space on each side of the period). You may also omit the period to achieve the same result (except where ambiguous such as <code>x <strong>-</strong>y</code>, or when the item on the right side has a leading ++ or --). When the dot is omitted, there should be at least one space between the items to be merged.<br>
Example (expression method): <code>Var := "The color is " <strong>.</strong> FoundColor</code><br>
Example (traditional method): <code>Var = The color is %FoundColor%</code></p>
<p>Sub-expressions can also be concatenated. For example: <code>Var := "The net price is " <strong>.</strong> Price * (1 - Discount/100)</code>.</p>
<p>A line that begins with a period (or any other operator) is automatically <a href="Scripts.htm#continuation">appended to</a> the line above it.</p></td>
</tr>
<tr id="regex">
<td class="center bold">~=</td>
<td><span class="ver">[AHK_L 31+]:</span> Shorthand for <a href="commands/RegExMatch.htm">RegExMatch()</a>. For example, <code>"abc123" ~= "\d"</code> sets ErrorLevel to 0 and yields 4 (the position of the first numeric character). Prior to <span class="ver">[v1.1.03]</span>, this operator had the same precedence as the <em>equal</em> (=) operator and was not fully documented.</td>
</tr>
<tr id="compare">
<td class="center bold">> <<br>
>= <=</td>
<td>
<p><strong>Greater (>)</strong>, <strong>less (<)</strong>, <strong>greater-or-equal (>=)</strong>, and <strong>less-or-equal (<=)</strong>. If both inputs are <a href="Concepts.htm#numbers">numbers</a> or <a href="Concepts.htm#numeric-strings">numeric strings</a>, they are compared numerically; otherwise they are compared alphabetically. The comparison is case sensitive only if <a href="commands/StringCaseSense.htm">StringCaseSense</a> has been turned on. See also: <a href="commands/Sort.htm">Sort</a></p>
<p class="note"><strong>Note</strong>: In AutoHotkey v1, a quoted string (or the result of concatenating with a quoted string) is never considered numeric when used directly in an expression.</p>
</td>
</tr>
<tr id="equal">
<td class="center bold">=<br>
==<br>
<> !=<br>
!==</td>
<td>
<p><strong>Case-insensitive equal (=)</strong>, <strong>case-sensitive equal (==)</strong>, and <strong>not-equal (<> or !=)</strong>. If both inputs are <a href="Concepts.htm#numbers">numbers</a> or <a href="Concepts.htm#numeric-strings">numeric strings</a>, they are compared numerically; otherwise they are compared alphabetically. The operators <strong>!=</strong> and <strong><></strong> are identical in function. The <strong>==</strong> operator behaves identically to <strong>=</strong> except when either of the inputs is not numeric, in which case <strong>==</strong> is always case sensitive and <strong>=</strong> is always case insensitive (the method of insensitivity depends on <a href="commands/StringCaseSense.htm">StringCaseSense</a>). By contrast, <strong><></strong> and <strong>!=</strong> obey <a href="commands/StringCaseSense.htm">StringCaseSense</a>.</p>
<p><strong>Case-sensitive not-equal (!==)</strong> <span class="ver">[v1.1.35+]</span>. Behaves identically to <strong>==</strong>, except that the result is inverted.</p>
<p class="note"><strong>Note</strong>: In AutoHotkey v1, a quoted string (or the result of concatenating with a quoted string) is never considered numeric when used directly in an expression.</p>
<p class="warning"><strong>Deprecated:</strong> The <> operator is not recommended for use in new scripts. Use the != operator instead.</p>
</td>
</tr>
<tr id="not">
<td class="center bold">NOT</td>
<td><strong>Logical-NOT</strong>. Except for its lower precedence, this is the same as the <strong>!</strong> operator. For example, <code>not (x = 3 or y = 3)</code> is the same as <code><strong>!</strong>(x = 3 or y = 3)</code>.</td>
</tr>
<tr id="and">
<td class="center bold">AND<br>
&&</td>
<td>Both of these are <strong>logical-AND</strong>. For example: <code>x > 3 and x < 10</code>. To enhance performance, <a href="Functions.htm#ShortCircuit">short-circuit evaluation</a> is applied. Also, a line that begins with AND/OR/&&/|| (or any other operator) is automatically <a href="Scripts.htm#continuation">appended to</a> the line above it.</td>
</tr>
<tr id="or">
<td class="center bold">OR<br>
||</td>
<td>Both of these are <strong>logical-OR</strong>. For example: <code>x <= 3 or x >= 10</code>. To enhance performance, <a href="Functions.htm#ShortCircuit">short-circuit evaluation</a> is applied.</td>
</tr>
<tr id="ternary">
<td class="center bold">?:</td>
<td><strong>Ternary operator</strong> <span class="ver">[v1.0.46+]</span>. This operator is a shorthand replacement for the <a href="commands/IfExpression.htm">if-else statement</a>. It evaluates the condition on its left side to determine which of its two branches should become its final result. For example, <code>var := x>y ? 2 : 3</code> stores 2 in <em>Var</em> if x is greater than y; otherwise it stores 3. To enhance performance, only the winning branch is evaluated (see <a href="Functions.htm#ShortCircuit">short-circuit evaluation</a>).</td>
</tr>
<tr id="AssignOp">
<td class="center bold">:=<br>
+=<br>
-=<br>
*=<br>
/=<br>
//=<br>
.=<br>
|=<br>
&=<br>
^=<br>
>>=<br>
<<=<br>
>>>=
</td>
<td><p><strong>Assign</strong>. Performs an operation on the contents of a variable and stores the result back in the same variable (but in versions prior to 1.0.46, these could only be used as the leftmost operator on a line, and only the first five operators were supported). The simplest assignment operator is <a href="commands/SetExpression.htm">colon-equals (:=)</a>, which stores the result of an expression in a variable. For a description of what the other operators do, see their related entries in this table. For example, <code>Var //= 2</code> performs <a href="#FloorDivide">floor division</a> to divide <em>Var</em> by 2, then stores the result back in <em>Var</em>. Similarly, <code>Var <strong>.=</strong> "abc"</code> is a shorthand way of writing <code>Var := Var <strong>.</strong> "abc"</code>.</p>
<p>Unlike most other operators, assignments are evaluated from right to left. Consequently, a line such as <code>Var1 := Var2 := 0</code> first assigns 0 to <em>Var2</em> then assigns <em>Var2</em> to <em>Var1</em>.</p>
<p>If an assignment is used as the input for some other operator, its value is the variable itself. For example, the expression <code>(Var+=2) > 50</code> is true if the newly-increased value in <em>Var</em> is greater than 50. This also allows an assignment to be passed <a href="Functions.htm#ByRef">ByRef</a>, or its <a href="#amp">address</a> taken; for example: <code>&(x:="abc")</code>.</p>
<p>The precedence of the assignment operators is automatically raised when it would avoid a syntax error or provide more intuitive behavior. For example: <code>not x:=y</code> is evaluated as <code>not (x:=y)</code>. Similarly, <code>++Var := X</code> is evaluated as <code>++(Var := X)</code>; and <code>Z>0 ? X:=2 : Y:=2</code> is evaluated as <code>Z>0 ? (X:=2) : (Y:=2)</code>.</p>
<p><strong>>>>=</strong> requires <span class="ver">[v1.1.35+]</span>.</p>
<p>Known limitations caused by backward compatibility (these may be resolved in a future release): 1) When <strong>/=</strong> is the leftmost operator in an expression and it is not part of a <a href="#comma">multi-statement expression</a>, it performs <a href="#FloorDivide">floor division</a> unless one of the inputs is floating point (in all other cases, <strong>/=</strong> performs <a href="#divide">true division</a>); 2) <a href="commands/EnvAdd.htm">Date/time math</a> is supported by <strong>+=</strong> and <strong>-=</strong> only when that operator is the leftmost one on a line; 3) The operators <strong>+=</strong>, <strong>-=</strong>, and <strong>*=</strong> treat blank variables as zero, but only when they are alone on a line; for example, <code>y:=1, x+=1</code> and <code>MsgBox % x-=3</code> both produce a blank result when x is blank.</p></td>
</tr>
<tr id="comma">
<td class="center bold">,</td>
<td><p><strong>Comma (multi-statement)</strong> <span class="ver">[v1.0.46+]</span>. Commas may be used to write multiple sub-expressions on a single line. This is most commonly used to group together multiple assignments or function calls. For example: <code>x:=1<strong>,</strong> y+=2<strong>,</strong> ++index, MyFunc()</code>. Such statements are executed in order from left to right.</p>
<p class="note"><strong>Note</strong>: A line that begins with a comma (or any other operator) is automatically <a href="Scripts.htm#continuation">appended to</a> the line above it. See also: <a href="#CommaPerf">comma performance</a>.</p>
<p><span class="ver">[v1.0.46.01+]</span>: When a comma is followed immediately by a variable and an equal sign, that equal sign is automatically treated as an <a href="commands/SetExpression.htm">assignment (:=)</a>. For example, all of the following are assignments: <code>x:=1, y=2, a=b=c</code>. New scripts should not rely on this behavior as it may change. The rule applies only to plain variables and not <a href="#ref">double-derefs</a>, so the following contains only one assignment: <code>x:=1, %y%=2</code></p></td>
</tr>
</table>
<p>The following types of sub-expressions override precedence/order of evaluation:</p>
<table class="info">
<tr>
<th class="center">Expression</th>
<th abbr="Descr">Description</th>
</tr>
<tr>
<td class="center"><strong>(</strong><em>expression</em><strong>)</strong></td>
<td>
<p>Any sub-expression enclosed in parentheses. For example, <code>(3 + 2) * 2</code> forces <code>3 + 2</code> to be evaluated first.</p>
<p>For a multi-statement expression, the result of the <u>first</u> statement is returned. For example, <code>(a := 1, b := 2, c := 3)</code> returns 1.</p>
</td>
</tr>
<tr>
<td class="center"><p><strong>mod()<br>
round()<br>
abs()</strong></p></td>
<td><strong>Function call</strong>. The function name must be immediately followed by an open-parenthesis, without any spaces or tabs in between. For details, see <a href="Functions.htm">Functions</a>.</td>
</tr>
<tr>
<td class="center"><p><strong>%</strong><em>func</em><strong>%()</strong></p></td>
<td>See <a href="Functions.htm#DynCall">Dynamically Calling a Function</a>.</td>
</tr>
<tr>
<td class="center"><em>func</em><strong>.()</strong></td>
<td><p><strong>Deprecated:</strong> This syntax is not recommended for use. Use <code>%func%()</code> (for function names and objects) or <code>func.Call()</code> (for function objects) instead.</p>
<p><span class="ver">[AHK_L 48+]:</span> Attempts to call an empty-named method of the object <i>func</i>. By convention, this is the object's "default" method. If <i>func</i> does not contain an object, the <a href="Objects.htm#Default_Base_Object">default base object</a> is invoked instead.</p>
<p><span class="ver">[v1.0.95+]:</span> If <i>func</i> contains a function name, the named function is called.</p></td>
</tr>
<tr>
<td class="center">Fn(<strong><em>Params</em>*</strong>)</td>
<td><p><span class="ver">[AHK_L 60+]:</span> <a href="Functions.htm#VariadicCall">Variadic function call</a>. <em>Params</em> is an array (object) containing parameter values.</p></td>
</tr>
<tr>
<td class="center"><strong>x[y]<br>[a, b, c]</strong></td>
<td>
<p><span class="ver">[AHK_L 31+]:</span> <strong>Member access</strong>. Get or set a value or call a method of object <i>x</i>, where <i>y</i> is a parameter list (typically an array index or key) or an expression which returns a method name.</p>
<p><span class="ver">[v1.0.97+]:</span> <strong>Array literal</strong>. If the open-bracket is not preceded by a value (or a sub-expression which yields a value), it is interpreted as the beginning of an array literal. For example, <code>[a, b, c]</code> is equivalent to <code>Array(a, b, c)</code> (a, b and c are variables).</p>
<p>See <a href="Objects.htm#Usage_Simple_Arrays">array syntax</a> and <a href="Objects.htm#Usage_Objects">object syntax</a> for more details.</p>
</td>
</tr>
<tr>
<td class="center"><strong>{a: b, c: d}</strong></td>
<td><p><span class="ver">[v1.0.97+]:</span> <strong>Object literal</strong>. Create an object or associative array. For example, <code>x := {a: b}</code> is equivalent to <code>x := Object("a", b)</code> or <code>x := Object(), x.a := b</code>. See <a href="Objects.htm#Usage_Associative_Arrays">Associative Arrays</a> for details.</p></td>
</tr>
</table>
<br>
<p id="CommaPerf"><strong>Performance</strong>: <span class="ver">[v1.0.48+]</span>: The comma operator is usually faster than writing separate expressions, especially when assigning one variable to another (e.g. <code>x:=y, a:=b</code>). Performance continues to improve as more and more expressions are combined into a single expression; for example, it may be 35% faster to combine five or ten simple expressions into a single expression.</p>
<h2 id="BuiltIn">Built-in Variables</h2>
<p>The variables below are built into the program and can be referenced by any script.</p>
<p class="note">See <a href="Concepts.htm#built-in-variables">Built-in Variables</a> for general information.</p>
<h3 id="BuiltIn_TOC">Table of Contents</h3>
<ul>
<li>Special Characters: <a href="#Space">A_Space</a>, <a href="#Tab">A_Tab</a></li>
<li>Script Properties: <a href="#CommandLine">command line parameters</a>, <a href="#WorkingDir">A_WorkingDir</a>, <a href="#ScriptDir">A_ScriptDir</a>, <a href="#ScriptName">A_ScriptName</a>, <a href="#prop">(...more...)</a></li>
<li>Date and Time: <a href="#YYYY">A_YYYY</a>, <a href="#MM">A_MM</a>, <a href="#DD">A_DD</a>, <a href="#Hour">A_Hour</a>, <a href="#Min">A_Min</a>, <a href="#Sec">A_Sec</a>, <a href="#date">(...more...)</a></li>
<li>Script Settings: <a href="#IsSuspended">A_IsSuspended</a>, <a href="#BatchLines">A_BatchLines</a>, <a href="#ListLines">A_ListLines</a>, <a href="#TitleMatchMode">A_TitleMatchMode</a>, <a href="#settings">(...more...)</a></li>
<li>User Idle Time: <a href="#TimeIdle">A_TimeIdle</a>, <a href="#TimeIdlePhysical">A_TimeIdlePhysical</a>, <a href="#TimeIdleKeyboard">A_TimeIdleKeyboard</a>, <a href="#TimeIdleMouse">A_TimeIdleMouse</a></li>
<li>GUI Windows and Menu Bars: <a href="#Gui">A_Gui</a>, <a href="#GuiControl">A_GuiControl</a>, <a href="#GuiEvent">A_GuiEvent</a>, <a href="#EventInfo">A_EventInfo</a>, <a href="#gui">(...more...)</a></li>
<li>Hotkeys, Hotstrings, and Custom Menu Items: <a href="#ThisHotkey">A_ThisHotkey</a>, <a href="#EndChar">A_EndChar</a>, <a href="#ThisMenuItem">A_ThisMenuItem</a>, <a href="#h">(...more...)</a></li>
<li>Operating System and User Info: <a href="#OSVersion">A_OSVersion</a>, <a href="#Screen">A_ScreenWidth</a>, <a href="#Screen">A_ScreenHeight</a>, <a href="#os">(...more...)</a></li>
<li>Misc: <a href="#Cursor">A_Cursor</a>, <a href="#Caret">A_CaretX</a>, <a href="#Caret">A_CaretY</a>, <a href="#Clipboard">Clipboard</a>, <a href="#ClipboardAll">ClipboardAll</a>, <a href="#ErrorLevel">ErrorLevel</a>, <a href="#misc">(...more...)</a></li>
<li>Loop: <a href="#Index">A_Index</a>, <a href="#loop">(...more...)</a></li>
</ul>
<h3 id="Special_Characters">Special Characters</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="Space">
<td>A_Space</td>
<td>This variable contains a single space character. See <a href="commands/AutoTrim.htm">AutoTrim</a> for details.</td>
</tr>
<tr id="Tab">
<td>A_Tab</td>
<td>This variable contains a single tab character. See <a href="commands/AutoTrim.htm">AutoTrim</a> for details.</td>
</tr>
</table>
<h3 id="prop">Script Properties</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="CommandLine">
<td>1, 2, 3, etc.</td>
<td>These variables are automatically created whenever a script is launched with command line parameters. They can be changed and referenced just like normal variable names (for example: %1%), but cannot be referenced directly in an <a href="#Expressions">expression</a>. The variable %0% contains the number of parameters passed (0 if none). For details, see the <a href="Scripts.htm#cmd">command line parameters</a>.</td>
</tr>
<tr id="Args">
<td>A_Args<br><span class="ver">[v1.1.27+]</span></td>
<td>Contains an <a href="Objects.htm#Usage_Simple_Arrays">array</a> of command line parameters. For details, see <a href="Scripts.htm#cmd">Passing Command Line Parameters to a Script</a>.</td>
</tr>
<tr id="WorkingDir">
<td>A_WorkingDir</td>
<td>The script's current working directory, which is where files will be accessed by default. The final backslash is not included unless it is the root directory. Two examples: C:\ and C:\My Documents. Use <a href="commands/SetWorkingDir.htm">SetWorkingDir</a> to change the working directory.</td>
</tr>
<tr id="InitialWorkingDir">
<td>A_InitialWorkingDir<br><span class="ver">[v1.1.35+]</span></td>
<td>The script's initial working directory, which is determined by how it was launched. For example, if it was run via shortcut -- such as on the Start Menu -- its initial working directory is determined by the "Start in" field within the shortcut's properties.</td>
</tr>
<tr id="ScriptDir">
<td>A_ScriptDir</td>
<td>The full path of the directory where the current script is located. The final backslash is omitted (even for root directories).</td>
</tr>
<tr id="ScriptName">
<td>A_ScriptName</td>
<td>
<p>The file name of the current script, without its path, e.g. MyScript.ahk</p>
<p>If the script is <a href="Scripts.htm#ahk2exe">compiled</a> or <a href="Program.htm#embedded-scripts">embedded</a>, this is the name of the current executable file.</p>
</td>
</tr>
<tr id="ScriptFullPath">
<td>A_ScriptFullPath</td>
<td>
<p>The full path of the current script, e.g. C:\Scripts\My Script.ahk</p>
<p>If the script is <a href="Scripts.htm#ahk2exe">compiled</a> or <a href="Program.htm#embedded-scripts">embedded</a>, this is the full path of the current executable file.</p>
</td>
</tr>
<tr id="ScriptHwnd">
<td>A_ScriptHwnd<br><span class="ver">[v1.1.01+]</span></td>
<td>The unique ID (HWND/handle) of the script's hidden <a href="Program.htm#main-window">main window</a>.</td>
</tr>
<tr id="LineNumber">
<td>A_LineNumber</td>
<td><p>The number of the currently executing line within the script (or one of its <a href="commands/_Include.htm">#Include files</a>). This line number will match the one shown by <a href="commands/ListLines.htm">ListLines</a>; it can be useful for error reporting such as this example: <code>MsgBox Could not write to log file (line number %A_LineNumber%)</code>.</p>
<p>Since a <a href="Scripts.htm#ahk2exe">compiled script</a> has merged all its <a href="commands/_Include.htm">#Include files</a> into one big script, its line numbering may be different than when it is run in non-compiled mode.</p></td>
</tr>
<tr id="LineFile">
<td>A_LineFile</td>
<td>
<p>The full path and name of the file to which <a href="#LineNumber">A_LineNumber</a> belongs. If the script was loaded from an external file, this is the same as <a href="#ScriptFullPath">A_ScriptFullPath</a> unless the line belongs to one of the script's <a href="commands/_Include.htm">#Include files</a>.</p>
<p>If the script was <a href="Scripts.htm#ahk2exe">compiled</a> based on a <a href="Scripts.htm#ahk2exe-base">.bin file</a>, this is the full path and name of the current executable file, the same as <a href="#ScriptFullPath">A_ScriptFullPath</a>.</p>
<p><span class="ver">[v1.1.34+]:</span> If the script is <a href="Program.htm#embedded-scripts">embedded</a>, A_LineFile contains an asterisk (*) followed by the resource name; e.g. *#1</p>
</td>
</tr>
<tr id="ThisFunc">
<td>A_ThisFunc<br>
<span class="ver">[v1.0.46.16+]</span></td>
<td>The name of the <a href="Functions.htm">user-defined function</a> that is currently executing (blank if none); for example: MyFunction. See also: <a href="commands/IsFunc.htm">IsFunc()</a></td>
</tr>
<tr id="ThisLabel">
<td>A_ThisLabel<br>
<span class="ver">[v1.0.46.16+]</span></td>
<td>The name of the <a href="misc/Labels.htm">label</a> (subroutine) that is currently executing (blank if none); for example: MyLabel. It is updated whenever the script executes <a href="commands/Gosub.htm">Gosub</a>/<a href="commands/Return.htm">Return</a> or <a href="commands/Goto.htm">Goto</a>. It is also updated for automatically-called labels such as <a href="commands/SetTimer.htm">timers</a>, <a href="commands/Gui.htm#DefaultWin">GUI threads</a>, <a href="commands/Menu.htm">menu items</a>, <a href="Hotkeys.htm">hotkeys</a>, <a href="Hotstrings.htm">hotstrings</a>, <a href="commands/OnClipboardChange.htm#label">OnClipboardChange labels</a>, and <a href="commands/OnExit.htm#command">OnExit labels</a>. However, A_ThisLabel is not updated when execution "falls into" a label from above; when that happens, A_ThisLabel retains its previous value. See also: <a href="#ThisHotkey">A_ThisHotkey</a> and <a href="commands/IsLabel.htm">IsLabel()</a></td>
</tr>
<tr id="AhkVersion">
<td>A_AhkVersion</td>
<td>In versions prior to 1.0.22, this variable is blank. Otherwise, it contains the version of AutoHotkey that is running the script, such as 1.0.22. In the case of a <a href="Scripts.htm#ahk2exe">compiled script</a>, the version that was originally used to compile it is reported. The formatting of the version number allows a script to check whether A_AhkVersion is greater than some minimum version number with > or >= as in this example: <code>if A_AhkVersion >= 1.0.25.07</code>.</td>
</tr>
<tr id="AhkPath">
<td>A_AhkPath</td>
<td>
<p>For non-compiled or <a href="Program.htm#embedded-scripts">embedded</a> scripts: The full path and name of the EXE file that is actually running the current script. For example: C:\Program Files\AutoHotkey\AutoHotkey.exe</p>
<p>For <a href="Scripts.htm#ahk2exe">compiled scripts</a> based on a <a href="Scripts.htm#ahk2exe-base">.bin file</a>, the value is determined by reading the installation directory from the registry and appending "\AutoHotkey.exe". If AutoHotkey is not installed, the value is blank. The example below is equivalent:</p>
<pre>RegRead InstallDir, HKLM\SOFTWARE\AutoHotkey, InstallDir
AhkPath := ErrorLevel ? "" : InstallDir "\AutoHotkey.exe"</pre>
<p><span class="ver">[v1.1.34+]:</span> For compiled scripts based on an .exe file, A_AhkPath contains the full path of the compiled script. This can be used in combination with <a href="Scripts.htm#SlashScript">/script</a> to execute external scripts. To instead locate the installed copy of AutoHotkey, read the registry as shown above.</p>
</td>
</tr>
<tr id="IsUnicode">
<td>A_IsUnicode</td>
<td><p>Contains 1 if strings are Unicode (16-bit) and an empty string (which is considered <a href="#Boolean">false</a>) if strings are ANSI (8-bit). The format of strings depends on the version of AutoHotkey.exe which is used to run the script, or if it is compiled, which bin file was used to compile it.</p>
<p>For ANSI executables prior to <span class="ver">[v1.1.06]</span>, A_IsUnicode was left undefined; that is, the script could assign to it, and attempting to read it could trigger a <a href="commands/_Warn.htm">UseUnsetGlobal warning</a>. In later versions it is always defined and is read-only.</p></td>
</tr>
<tr id="IsCompiled">
<td>A_IsCompiled</td>
<td><p>Contains 1 if the script is running as a <a href="Scripts.htm#ahk2exe">compiled EXE</a> and an empty string (which is considered <a href="#Boolean">false</a>) if it is not.</p>
<p>For non-compiled scripts prior to <span class="ver">[v1.1.06]</span>, A_IsCompiled was left undefined; that is, the script could assign to it, and attempting to read it could trigger a <a href="commands/_Warn.htm">UseUnsetGlobal warning</a>. In later versions it is always defined and is read-only.</p></td>
</tr>
<tr id="ExitReason">
<td>A_ExitReason</td>
<td>The most recent reason the script was asked to terminate. This variable is blank unless the script has an <a href="commands/OnExit.htm#command">OnExit</a> subroutine and that subroutine is currently running or has been called at least once by an exit attempt. See <a href="commands/OnExit.htm#command">OnExit</a> for details.</td>
</tr>
</table>
<h3 id="date">Date and Time</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="YYYY">
<td>A_YYYY</td>
<td>
<p>Current 4-digit year (e.g. 2004). Synonymous with A_Year.</p>
<p class="note"><strong>Note</strong>: To retrieve a formatted time or date appropriate for your locale and language, use <code><a href="commands/FormatTime.htm">FormatTime</a>, OutputVar</code> (time and long date) or <code><a href="commands/FormatTime.htm">FormatTime</a>, OutputVar,, LongDate</code> (retrieves long-format date).</p>
</td>
</tr>
<tr id="MM">
<td>A_MM</td>
<td>Current 2-digit month (01-12). Synonymous with A_Mon.</td>
</tr>
<tr id="DD">
<td>A_DD</td>
<td>Current 2-digit day of the month (01-31). Synonymous with A_MDay.</td>
</tr>
<tr id="MMMM">
<td>A_MMMM</td>
<td>Current month's full name in the current user's language, e.g. July</td>
</tr>
<tr id="MMM">
<td>A_MMM</td>
<td>Current month's abbreviation in the current user's language, e.g. Jul</td>
</tr>
<tr id="DDDD">
<td>A_DDDD</td>
<td>Current day of the week's full name in the current user's language, e.g. Sunday</td>
</tr>
<tr id="DDD">
<td>A_DDD</td>
<td>Current day of the week's abbreviation in the current user's language, e.g. Sun</td>
</tr>
<tr id="WDay">
<td>A_WDay</td>
<td>Current 1-digit day of the week (1-7). 1 is Sunday in all locales.</td>
</tr>
<tr id="YDay">
<td>A_YDay</td>
<td>Current day of the year (1-366). The value is not zero-padded, e.g. 9 is retrieved, not 009. To retrieve a zero-padded value, use the following: <code><a href="commands/FormatTime.htm">FormatTime</a>, OutputVar,, YDay0</code>.</td>
</tr>
<tr id="YWeek">
<td>A_YWeek</td>
<td>Current year and week number (e.g. 200453) according to ISO 8601. To separate the year from the week, use <code>Year := <a href="commands/SubStr.htm">SubStr</a>(A_YWeek, 1, 4)</code> and <code>Week := <a href="commands/SubStr.htm">SubStr</a>(A_YWeek, -1)</code>. Precise definition of A_YWeek: If the week containing January 1st has four or more days in the new year, it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1.</td>
</tr>
<tr id="Hour">
<td>A_Hour</td>
<td>Current 2-digit hour (00-23) in 24-hour time (for example, 17 is 5pm). To retrieve 12-hour time as well as an AM/PM indicator, follow this example: <code><a href="commands/FormatTime.htm">FormatTime</a>, OutputVar, , h:mm:ss tt</code></td>
</tr>
<tr id="Min">
<td>A_Min</td>
<td><p>Current 2-digit minute (00-59).</p></td>
</tr>
<tr id="Sec">
<td>A_Sec</td>
<td>Current 2-digit second (00-59).</td>
</tr>
<tr id="MSec">
<td>A_MSec</td>
<td>Current 3-digit millisecond (000-999). To remove the leading zeros, follow this example: <code>Milliseconds := A_MSec + 0</code>.</td>
</tr>
<tr id="Now">
<td>A_Now</td>
<td>
<p>The current local time in <a href="commands/FileSetTime.htm#YYYYMMDD">YYYYMMDDHH24MISS</a> format.</p>
<p class="note"><strong>Note</strong>: Date and time math can be performed with <a href="commands/EnvAdd.htm">EnvAdd</a> and <a href="commands/EnvSub.htm">EnvSub</a>. Also, <a href="commands/FormatTime.htm">FormatTime</a> can format the date and/or time according to your locale or preferences.</p>
</td>
</tr>
<tr id="NowUTC">
<td>A_NowUTC</td>
<td>The current Coordinated Universal Time (UTC) in <a href="commands/FileSetTime.htm#YYYYMMDD">YYYYMMDDHH24MISS</a> format. UTC is essentially the same as Greenwich Mean Time (GMT).</td>
</tr>
<tr id="TickCount">
<td>A_TickCount</td>
<td><p>The number of milliseconds that have elapsed since the system was started, up to 49.7 days. By storing A_TickCount in a variable, elapsed time can later be measured by subtracting that variable from the latest A_TickCount value. For example:</p>
<pre>StartTime := A_TickCount
Sleep, 1000
ElapsedTime := A_TickCount - StartTime
MsgBox, %ElapsedTime% milliseconds have elapsed.</pre>
<p>If you need more precision than A_TickCount's 10ms, use <a href="commands/DllCall.htm#QPC">QueryPerformanceCounter()</a>.</p>
</td>
</tr>
</table>
<h3 id="settings">Script Settings</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="IsSuspended">
<td>A_IsSuspended</td>
<td>Contains 1 if the script is <a href="commands/Suspend.htm">suspended</a> and 0 otherwise.</td>
</tr>
<tr id="IsPaused">
<td>A_IsPaused<br>
<span class="ver">[v1.0.48+]</span></td>
<td>Contains 1 if the <a href="misc/Threads.htm">thread</a> immediately underneath the current thread is <a href="commands/Pause.htm">paused</a>. Otherwise it contains 0.</td>
</tr>
<tr id="IsCritical">
<td>A_IsCritical<br>
<span class="ver">[v1.0.48+]</span></td>
<td>Contains 0 if <a href="commands/Critical.htm">Critical</a> is off for the <a href="misc/Threads.htm">current thread</a>. Otherwise it contains an integer greater than zero, namely the <a href="commands/Critical.htm#Interval">message-check frequency</a> being used by Critical. Since <code>Critical 0</code> turns off critical, the current state of Critical can be saved and restored via <code>Old_IsCritical := A_IsCritical</code> followed later by <code>Critical %Old_IsCritical%</code>.</td>
</tr>
<tr id="BatchLines">
<td>A_BatchLines</td>
<td>(synonymous with A_NumBatchLines) The current value as set by <a href="commands/SetBatchLines.htm">SetBatchLines</a>. Examples: 200 or 10ms (depending on format).</td>
</tr>
<tr id="ListLines">
<td>A_ListLines<br><span class="ver">[v1.1.28+]</span></td>
<td>Contains 1 if <a href="commands/ListLines.htm">ListLines</a> is enabled. Otherwise it contains 0.</td>
</tr>
<tr id="TitleMatchMode">
<td>A_TitleMatchMode</td>
<td>The current mode set by <a href="commands/SetTitleMatchMode.htm">SetTitleMatchMode</a>: 1, 2, 3, or RegEx.</td>
</tr>
<tr id="TitleMatchModeSpeed">
<td>A_TitleMatchModeSpeed</td>
<td>The current match speed (fast or slow) set by <a href="commands/SetTitleMatchMode.htm">SetTitleMatchMode</a>.</td>
</tr>
<tr id="DetectHiddenWindows">
<td>A_DetectHiddenWindows</td>
<td>The current mode (On or Off) set by <a href="commands/DetectHiddenWindows.htm">DetectHiddenWindows</a>.</td>
</tr>
<tr id="DetectHiddenText">
<td>A_DetectHiddenText</td>
<td>The current mode (On or Off) set by <a href="commands/DetectHiddenText.htm">DetectHiddenText</a>.</td>
</tr>
<tr id="AutoTrim">
<td>A_AutoTrim</td>
<td>The current mode (On or Off) set by <a href="commands/AutoTrim.htm">AutoTrim</a>.</td>
</tr>
<tr id="StringCaseSense">
<td>A_StringCaseSense</td>
<td>The current mode (On, Off, or Locale) set by <a href="commands/StringCaseSense.htm">StringCaseSense</a>.</td>
</tr>
<tr id="FileEncoding">
<td>A_FileEncoding</td>
<td><span class="ver">[AHK_L 46+]</span>: Contains the default encoding for various commands; see <a href="commands/FileEncoding.htm">FileEncoding</a>.</td>
</tr>
<tr id="FormatInteger">
<td>A_FormatInteger</td>
<td>The current integer format (H or D) set by <a href="commands/SetFormat.htm">SetFormat</a>. <span class="ver">[AHK_L 42+]:</span> This may also contain lower-case h.</td>
</tr>
<tr id="FormatFloat">
<td>A_FormatFloat</td>
<td>The current floating point number format set by <a href="commands/SetFormat.htm">SetFormat</a>.</td>
</tr>
<tr id="SendMode">
<td>A_SendMode</td>
<td><span class="ver">[v1.1.23+]:</span> The current mode (Event, Input, Play or InputThenPlay) set by <a href="commands/SendMode.htm">SendMode</a>.</td>
</tr>
<tr id="SendLevel">
<td>A_SendLevel</td>
<td><span class="ver">[v1.1.23+]:</span> The current <a href="commands/SendLevel.htm">SendLevel</a> setting (an integer between 0 and 100, inclusive).</td>
</tr>
<tr id="StoreCapslockMode">
<td>A_StoreCapsLockMode</td>
<td><span class="ver">[v1.1.23+]:</span> The current mode (On or Off) set by <a href="commands/SetStoreCapslockMode.htm">SetStoreCapsLockMode</a>.</td>
</tr>
<tr id="KeyDelay">
<td>A_KeyDelay<br>
A_KeyDuration</td>
<td>The current delay or duration set by <a href="commands/SetKeyDelay.htm">SetKeyDelay</a> (always decimal, not hex). A_KeyDuration requires <span class="ver">[v1.1.23+]</span>.</td>
</tr>
<tr id="KeyDelayPlay">
<td>A_KeyDelayPlay<br>
A_KeyDurationPlay</td>
<td>The current delay or duration set by <a href="commands/SetKeyDelay.htm">SetKeyDelay</a> for the <a href="commands/Send.htm#SendPlayDetail">SendPlay</a> mode (always decimal, not hex). Requires <span class="ver">[v1.1.23+]</span>.</td>
</tr>
<tr id="WinDelay">
<td>A_WinDelay</td>
<td>The current delay set by <a href="commands/SetWinDelay.htm">SetWinDelay</a> (always decimal, not hex).</td>
</tr>
<tr id="ControlDelay">
<td>A_ControlDelay</td>
<td>The current delay set by <a href="commands/SetControlDelay.htm">SetControlDelay</a> (always decimal, not hex).</td>
</tr>
<tr id="MouseDelay">
<td>A_MouseDelay<br>
A_MouseDelayPlay</td>
<td>The current delay set by <a href="commands/SetMouseDelay.htm">SetMouseDelay</a> (always decimal, not hex). A_MouseDelay is for the traditional SendEvent mode, whereas A_MouseDelayPlay is for <a href="commands/Send.htm#SendPlayDetail">SendPlay</a>. A_MouseDelayPlay requires <span class="ver">[v1.1.23+]</span>.</td>
</tr>
<tr id="DefaultMouseSpeed">
<td>A_DefaultMouseSpeed</td>
<td>The current speed set by <a href="commands/SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> (always decimal, not hex).</td>
</tr>
<tr id="CoordMode">
<td>A_CoordModeToolTip<br>
A_CoordModePixel<br>
A_CoordModeMouse<br>
A_CoordModeCaret<br>
A_CoordModeMenu</td>
<td><span class="ver">[v1.1.23+]:</span> The current mode (Window, Client or Screen) set by <a href="commands/CoordMode.htm">CoordMode</a>.</td>
</tr>
<tr id="RegView">
<td>A_RegView</td>
<td><span class="ver">[v1.1.08+]:</span> The current registry view as set by <a href="commands/SetRegView.htm">SetRegView</a>.</td>
</tr>
<tr id="IconHidden">
<td>A_IconHidden</td>
<td>Contains 1 if the <a href="Program.htm#tray-icon">tray icon</a> is currently hidden or 0 otherwise. The icon can be hidden via <a href="commands/_NoTrayIcon.htm">#NoTrayIcon</a> or the <a href="commands/Menu.htm">Menu</a> command.</td>
</tr>
<tr id="IconTip">
<td>A_IconTip</td>
<td>Blank unless a custom tooltip for the <a href="Program.htm#tray-icon">tray icon</a> has been specified via <code><a href="commands/Menu.htm">Menu</a>, Tray, Tip</code> -- in which case it's the text of the tip.</td>
</tr>
<tr id="IconFile">
<td>A_IconFile</td>
<td>Blank unless a custom <a href="Program.htm#tray-icon">tray icon</a> has been specified via <code><a href="commands/Menu.htm">Menu</a>, tray, icon</code> -- in which case it's the full path and name of the icon's file.</td>
</tr>
<tr id="IconNumber">
<td>A_IconNumber</td>
<td>Blank if A_IconFile is blank. Otherwise, it's the number of the icon in A_IconFile (typically 1).</td>
</tr>
</table>
<h3 id="User_Idle_Time">User Idle Time</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="TimeIdle">
<td>A_TimeIdle</td>
<td>The number of milliseconds that have elapsed since the system last received keyboard, mouse, or other input. This is useful for determining whether the user is away. Physical input from the user as well as artificial input generated by <strong>any</strong> program or script (such as the <a href="commands/Send.htm">Send</a> or <a href="commands/MouseMove.htm">MouseMove</a> commands) will reset this value back to zero. Since this value tends to increase by increments of 10, do not check whether it is equal to another value. Instead, check whether it is greater or less than another value. For example: <code>IfGreater, A_TimeIdle, 600000, MsgBox, The last keyboard or mouse activity was at least 10 minutes ago</code>.</td>
</tr>
<tr id="TimeIdlePhysical">
<td>A_TimeIdlePhysical</td>
<td>Similar to above but ignores artificial keystrokes and/or mouse clicks whenever the corresponding hook (<a href="commands/_InstallKeybdHook.htm">keyboard</a> or <a href="commands/_InstallMouseHook.htm">mouse</a>) is installed; that is, it responds only to physical events. (This prevents simulated keystrokes and mouse clicks from falsely indicating that a user is present.) If neither hook is installed, this variable is equivalent to A_TimeIdle. If only one hook is installed, only its type of physical input affects A_TimeIdlePhysical (the other/non-installed hook's input, both physical and artificial, has no effect).</td>
</tr>
<tr id="TimeIdleKeyboard">
<td>A_TimeIdleKeyboard<br><span class="ver">[v1.1.28+]</span></td>
<td>If the <a href="commands/_InstallKeybdHook.htm">keyboard hook</a> is installed, this is the number of milliseconds that have elapsed since the system last received physical keyboard input. Otherwise, this variable is equivalent to A_TimeIdle.</td>
</tr>
<tr id="TimeIdleMouse">
<td>A_TimeIdleMouse<br><span class="ver">[v1.1.28+]</span></td>
<td>If the <a href="commands/_InstallMouseHook.htm">mouse hook</a> is installed, this is the number of milliseconds that have elapsed since the system last received physical mouse input. Otherwise, this variable is equivalent to A_TimeIdle.</td>
</tr>
</table>
<h3 id="gui">GUI Windows and Menu Bars</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="DefaultGui">
<td>A_DefaultGui <span class="ver">[v1.1.23+]</span></td>
<td>The name or number of the current thread's <a href="commands/Gui.htm#Default">default GUI</a>.</td>
</tr>
<tr id="DefaultListView">
<td>A_DefaultListView <span class="ver">[v1.1.23+]</span></td>
<td>The <a href="commands/Gui.htm#Events">variable name</a> or <a href="commands/Gui.htm#HwndOutputVar">HWND</a> of the <a href="commands/ListView.htm">ListView control</a> upon which the <a href="commands/ListView.htm#BuiltIn">ListView functions</a> operate. If the default GUI lacks a ListView, this variable is blank.</td>
</tr>
<tr id="DefaultTreeView">
<td>A_DefaultTreeView <span class="ver">[v1.1.23+]</span></td>
<td>The <a href="commands/Gui.htm#Events">variable name</a> or <a href="commands/Gui.htm#HwndOutputVar">HWND</a> of the <a href="commands/TreeView.htm">TreeView control</a> upon which the <a href="commands/TreeView.htm#BuiltIn">TreeView functions</a> operate. If the default GUI lacks a TreeView, this variable is blank.</td>
</tr>
<tr id="Gui">
<td>A_Gui</td>
<td>The name or number of the <a href="commands/Gui.htm">GUI</a> that launched the <a href="misc/Threads.htm">current thread</a>. This variable is blank unless a Gui control, menu bar item, or event such as GuiClose/GuiEscape launched the current thread.</td>
</tr>
<tr id="GuiControl">
<td>A_GuiControl</td>
<td>The name of the variable associated with the GUI control that launched the <a href="misc/Threads.htm">current thread</a>. If that control lacks an <a href="commands/Gui.htm#Events">associated variable</a>, A_GuiControl instead contains the first 63 characters of the control's text/caption (this is most often used to avoid giving each button a variable name). A_GuiControl is blank whenever: 1) A_Gui is blank; 2) a GUI menu bar item or event such as GuiClose/GuiEscape launched the current thread; 3) the control lacks an associated variable and has no caption; or 4) The control that originally launched the current thread no longer exists (perhaps due to <a href="commands/Gui.htm#Destroy">Gui Destroy</a>).</td>
</tr>
<tr id="GuiWidth">
<td>A_GuiWidth<br>
A_GuiHeight</td>
<td>These contain the GUI window's width and height when referenced in a <a href="commands/Gui.htm#GuiSize">GuiSize subroutine</a>. They apply to the window's client area, which is the area excluding title bar, menu bar, and borders. <span class="ver">[v1.1.11+]:</span> These values are affected by <a href="commands/Gui.htm#DPIScale">DPI scaling</a>.</td>
</tr>
<tr>
<td><span id="GuiX"></span><span id="GuiY"></span>A_GuiX<br>
A_GuiY</td>
<td>These contain the X and Y coordinates for <a href="commands/Gui.htm#GuiContextMenu">GuiContextMenu</a> and <a href="commands/Gui.htm#GuiDropFiles">GuiDropFiles</a> events. Coordinates are relative to the upper-left corner of the window. <span class="ver">[v1.1.11+]:</span> These values are affected by <a href="commands/Gui.htm#DPIScale">DPI scaling</a>.</td>
</tr>
<tr>
<td><span id="GuiEvent"></span><span id="GuiControlEvent"></span>A_GuiEvent<br><span class="small80">or A_GuiControlEvent</span></td>
<td><p>The type of event that launched the <a href="misc/Threads.htm">current thread</a>. If the thread was not launched via <a href="commands/Gui.htm">GUI action</a>, this variable is blank. Otherwise, it contains one of the following strings:</p>
<p><strong>Normal</strong>: The event was triggered by a single left-click or via keystrokes (<kbd>↑</kbd>, <kbd>→</kbd>, <kbd>↓</kbd>, <kbd>←</kbd>, <kbd>Tab</kbd>, <kbd>Space</kbd>, underlined shortcut key, etc.). This value is also used for menu bar items and the special events such as GuiClose and GuiEscape.</p>
<p><strong>DoubleClick</strong>: The event was triggered by a double-click. Note: The first click of the click-pair will still cause a <em>Normal</em> event to be received first. In other words, the subroutine will be launched twice: once for the first click and again for the second.</p>
<p><strong>RightClick</strong>: Occurs only for <a href="commands/Gui.htm#GuiContextMenu">GuiContextMenu</a>, <a href="commands/ListView.htm">ListViews</a>, and <a href="commands/TreeView.htm">TreeViews</a>.</p>
<p><strong>Context-sensitive values:</strong> For details see <a href="commands/Gui.htm#GuiContextMenu">GuiContextMenu</a>, <a href="commands/Gui.htm#GuiDropFiles">GuiDropFiles</a>, <a href="commands/GuiControls.htm#Slider">Slider</a>, <a href="commands/GuiControls.htm#MonthCal">MonthCal</a>, <a href="commands/ListView.htm">ListView</a>, and <a href="commands/TreeView.htm">TreeView</a>.</p>
</td>
</tr>
<tr id="EventInfo">
<td>A_EventInfo</td>
<td><p>Contains additional information about the following events:</p>
<ul>
<li>The <a href="commands/OnClipboardChange.htm#label">OnClipboardChange label</a></li>
<li><a href="Hotkeys.htm#Wheel">Mouse wheel hotkeys</a> (WheelDown/Up/Left/Right)</li>
<li><a href="commands/OnMessage.htm">OnMessage()</a></li>
<li><a href="commands/RegisterCallback.htm">RegisterCallback()</a></li>
<li><a href="misc/RegExCallout.htm">Regular Expression Callouts</a></li>
<li><a href="commands/Gui.htm#label">GUI events</a>, namely <a href="commands/Gui.htm#GuiContextMenu">GuiContextMenu</a>, <a href="commands/Gui.htm#GuiDropFiles">GuiDropFiles</a>, <a href="commands/GuiControls.htm#ListBox">ListBox</a>, <a href="commands/ListView.htm">ListView</a>, <a href="commands/TreeView.htm">TreeView</a>, and <a href="commands/GuiControls.htm#StatusBar">StatusBar</a>. If there is no additional information for an event, A_EventInfo contains 0.</li>
</ul></td>
</tr>
</table>
<p class="note"><strong>Note</strong>: Unlike variables such as A_ThisHotkey, each <a href="misc/Threads.htm">thread</a> retains its own value for A_Gui, A_GuiControl, A_GuiX/Y, A_GuiEvent, and A_EventInfo. Therefore, if a thread is interrupted by another, upon being resumed it will still see its original/correct values in these variables.</p>
<h3 id="h">Hotkeys, Hotstrings, and Custom Menu Items</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="ThisMenuItem">
<td>A_ThisMenuItem</td>
<td>The name of the most recently selected <a href="commands/Menu.htm">custom menu item</a> (blank if none).</td>
</tr>
<tr id="ThisMenu">
<td>A_ThisMenu</td>
<td>The name of the menu from which A_ThisMenuItem was selected.</td>
</tr>
<tr id="ThisMenuItemPos">
<td>A_ThisMenuItemPos</td>
<td>A number indicating the <u>current</u> position of A_ThisMenuItem within A_ThisMenu. The first item in the menu is 1, the second is 2, and so on. Menu separator lines are counted. This variable is blank if A_ThisMenuItem is blank or no longer exists within A_ThisMenu. It is also blank if A_ThisMenu itself no longer exists.</td>
</tr>
<tr id="ThisHotkey">
<td>A_ThisHotkey</td>
<td><p>The most recently executed <a href="Hotkeys.htm">hotkey</a> or <a href="Hotstrings.htm">non-auto-replace hotstring</a> (blank if none), e.g. #z. This value will change if the <a href="misc/Threads.htm">current thread</a> is interrupted by another hotkey, so be sure to copy it into another variable immediately if you need the original value for later use in a subroutine.</p>
<p>When a hotkey is first created -- either by the <a href="commands/Hotkey.htm">Hotkey command</a> or a <a href="Hotkeys.htm">double-colon label</a> in the script -- its key name and the ordering of its modifier symbols becomes the permanent name of that hotkey, shared by all <a href="commands/_IfWinActive.htm#variant">variants</a> of the hotkey.</p>
<p>When a hotstring is first created, the exact text used to create it becomes the permanent name of the hotstring.</p>
<p>See also: <a href="#ThisLabel">A_ThisLabel</a></p></td>
</tr>
<tr id="PriorHotkey">
<td>A_PriorHotkey</td>
<td>Same as above except for the previous hotkey. It will be blank if none.</td>
</tr>
<tr id="PriorKey">
<td>A_PriorKey</td>
<td><span class="ver">[v1.1.01+]:</span> The name of the last key which was pressed prior to the most recent key-press or key-release, or blank if no applicable key-press can be found in the key history. All input generated by AutoHotkey scripts is excluded. For this variable to be of use, the <a href="commands/_InstallKeybdHook.htm">keyboard</a> or <a href="commands/_InstallMouseHook.htm">mouse hook</a> must be installed and <a href="commands/KeyHistory.htm">key history</a> must be enabled.</td>
</tr>
<tr id="TimeSinceThisHotkey">
<td>A_TimeSinceThisHotkey</td>
<td>The number of milliseconds that have elapsed since A_ThisHotkey was pressed. It will be -1 whenever A_ThisHotkey is blank.</td>
</tr>
<tr id="TimeSincePriorHotkey">
<td>A_TimeSincePriorHotkey</td>
<td>The number of milliseconds that have elapsed since A_PriorHotkey was pressed. It will be -1 whenever A_PriorHotkey is blank.</td>
</tr>
<tr id="EndChar">
<td>A_EndChar</td>
<td>The <a href="Hotstrings.htm#EndChars">ending character</a> that was pressed by the user to trigger the most recent <a href="Hotstrings.htm">non-auto-replace hotstring</a>. If no ending character was required (due to the * option), this variable will be blank.</td>
</tr>
</table>
<h3 id="os">Operating System and User Info</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="ComSpec">
<td>ComSpec <span class="ver">[v1.0.43.08+]</span><br>
A_ComSpec <span class="ver">[v1.1.28+]</span></td>
<td>
<p>Contains the same string as the environment's ComSpec variable. Often used with <a href="commands/Run.htm">Run/RunWait</a>. For example:</p>
<pre class="NoIndent no-highlight">C:\Windows\system32\cmd.exe</pre>
</td>
</tr>
<tr id="Temp">
<td>A_Temp<br>
<span class="ver">[v1.0.43.09+]</span></td>
<td><p>The full path and name of the folder designated to hold temporary files. It is retrieved from one of the following locations (in order): 1) the <a href="Concepts.htm#environment-variables">environment variables</a> TMP, TEMP, or USERPROFILE; 2) the Windows directory. For example:</p>
<pre class="NoIndent no-highlight">C:\Users\<UserName>\AppData\Local\Temp</pre>
</td>
</tr>
<tr id="OSType">
<td>A_OSType</td>
<td>The type of operating system being run. Since AutoHotkey 1.1 only supports NT-based operating systems, this is always WIN32_NT. Older versions of AutoHotkey return WIN32_WINDOWS when run on Windows 95/98/ME.</td>
</tr>
<tr id="OSVersion">
<td>A_OSVersion</td>
<td><p>One of the following strings, if appropriate: WIN_7 <span class="ver">[requires AHK_L 42+]</span>, WIN_8 <span class="ver">[requires v1.1.08+]</span>, WIN_8.1 <span class="ver">[requires v1.1.15+]</span>, WIN_VISTA, WIN_2003, WIN_XP, WIN_2000.</p>
<p>Applying compatibility settings in the AutoHotkey executable or compiled script's properties causes the OS to report a different version number, which is reflected by A_OSVersion.</p>
<p><span class="ver">[v1.1.20+]:</span> If the OS version is not recognized as one of those listed above, a string in the format "major.minor.build" is returned. For example, <code>10.0.14393</code> is Windows 10 build 14393, also known as version 1607.</p>
<pre><em>; This example is obsolete as these operating systems are no longer supported.</em>
if A_OSVersion in WIN_NT4,WIN_95,WIN_98,WIN_ME <em>; Note: No spaces around commas.</em>
{
MsgBox This script requires Windows 2000/XP or later.
ExitApp
}</pre>
</td>
</tr>
<tr id="Is64bitOS">
<td>A_Is64bitOS</td>
<td><span class="ver">[v1.1.08+]:</span> Contains 1 (true) if the OS is 64-bit or 0 (false) if it is 32-bit.</td>
</tr>
<tr id="PtrSize">
<td>A_PtrSize</td>
<td><span class="ver">[AHK_L 42+]:</span> Contains the size of a pointer, in bytes. This is either 4 (32-bit) or 8 (64-bit), depending on what type of executable (EXE) is running the script.</td>
</tr>
<tr id="Language">
<td>A_Language</td>
<td>The system's default language, which is one of <a href="misc/Languages.htm">these 4-digit codes</a>.</td>
</tr>
<tr id="ComputerName">
<td>A_ComputerName</td>
<td>The name of the computer as seen on the network.</td>
</tr>
<tr id="UserName">
<td>A_UserName</td>
<td>The logon name of the user who launched this script.</td>
</tr>
<tr id="WinDir">
<td>A_WinDir</td>
<td>The Windows directory. For example: <code>C:\Windows</code></td>
</tr>
<tr id="ProgramFiles">
<td>A_ProgramFiles<br>
or ProgramFiles</td>
<td>
<p>The Program Files directory (e.g. <code>C:\Program Files</code> or <code>C:\Program Files (x86)</code>). This is usually the same as the <em>ProgramFiles</em> <a href="Concepts.htm#environment-variables">environment variable</a>.</p>
<p>On <a href="#Is64bitOS">64-bit systems</a> (and not 32-bit systems), the following applies:</p>
<ul>
<li>If the executable (EXE) that is running the script is 32-bit, A_ProgramFiles returns the path of the "Program Files (x86)" directory.</li>
<li>For 32-bit processes, the <em>ProgramW6432</em> environment variable contains the path of the 64-bit Program Files directory. On Windows 7 and later, it is also set for 64-bit processes.</li>
<li>The <em>ProgramFiles(x86)</em> environment variable contains the path of the 32-bit Program Files directory.</li>
</ul>
<p><span class="ver">[v1.0.43.08+]</span>: The A_ prefix may be omitted, which helps ease the transition to <a href="commands/_NoEnv.htm">#NoEnv</a>.</p>
</td>
</tr>
<tr id="AppData">
<td>A_AppData<br>
<span class="ver">[v1.0.43.09+]</span></td>
<td>
<p>The full path and name of the folder containing the current user's application-specific data. For example:</p>
<pre class="NoIndent no-highlight">C:\Users\<UserName>\AppData\Roaming</pre>
</td>
</tr>
<tr id="AppDataCommon">
<td>A_AppDataCommon<br>
<span class="ver">[v1.0.43.09+]</span></td>
<td>
<p>The full path and name of the folder containing the all-users application-specific data. For example:</p>
<pre class="NoIndent no-highlight">C:\ProgramData</pre>
</td>
</tr>
<tr id="Desktop">
<td>A_Desktop</td>
<td>
<p>The full path and name of the folder containing the current user's desktop files. For example:</p>
<pre class="NoIndent no-highlight">C:\Users\<UserName>\Desktop</pre>
</td>
</tr>
<tr id="DesktopCommon">
<td>A_DesktopCommon</td>
<td>
<p>The full path and name of the folder containing the all-users desktop files. For example:</p>
<pre class="NoIndent no-highlight">C:\Users\Public\Desktop</pre>
</td>
</tr>
<tr id="StartMenu">
<td>A_StartMenu</td>
<td>
<p>The full path and name of the current user's Start Menu folder. For example:</p>
<pre class="NoIndent no-highlight">C:\Users\<UserName>\AppData\Roaming\Microsoft\Windows\Start Menu</pre>
</td>
</tr>
<tr id="StartMenuCommon">
<td>A_StartMenuCommon</td>
<td>
<p>The full path and name of the all-users Start Menu folder. For example:</p>
<pre class="NoIndent no-highlight">C:\ProgramData\Microsoft\Windows\Start Menu</pre>
</td>
</tr>
<tr id="Programs">
<td>A_Programs</td>
<td>
<p>The full path and name of the Programs folder in the current user's Start Menu. For example:</p>
<pre class="NoIndent no-highlight">C:\Users\<UserName>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs</pre>
</td>
</tr>
<tr id="ProgramsCommon">
<td>A_ProgramsCommon</td>
<td>
<p>The full path and name of the Programs folder in the all-users Start Menu. For example:</p>
<pre class="NoIndent no-highlight">C:\ProgramData\Microsoft\Windows\Start Menu\Programs</pre>
</td>
</tr>
<tr id="Startup">
<td>A_Startup</td>
<td>
<p>The full path and name of the Startup folder in the current user's Start Menu. For example:</p>
<pre class="NoIndent no-highlight">C:\Users\<UserName>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup</pre>
</td>
</tr>
<tr id="StartupCommon">
<td>A_StartupCommon</td>
<td>
<p>The full path and name of the Startup folder in the all-users Start Menu. For example:</p>
<pre class="NoIndent no-highlight">C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup</pre>
</td>
</tr>
<tr id="MyDocuments">
<td>A_MyDocuments</td>
<td>
<p>The full path and name of the current user's "My Documents" folder. Unlike most of the similar variables, if the folder is the root of a drive, the final backslash is not included (e.g. it would contain <code>M:</code> rather than <code>M:\</code>). For example:</p>
<pre class="NoIndent no-highlight">C:\Users\<UserName>\Documents</pre>
</td>
</tr>
<tr id="IsAdmin">
<td>A_IsAdmin</td>
<td><p>If the current user has admin rights, this variable contains 1. Otherwise, it contains 0.</p>
<p id="RequireAdmin">To have the script restart itself as admin (or show a prompt to the user requesting admin), use <a href="commands/Run.htm#RunAs">Run *RunAs</a>. However, note that running the script as admin causes all programs launched by the script to also run as admin. For a possible alternative, see <a href="FAQ.htm#uac">the FAQ</a>.</p>
</td>
</tr>
<tr id="Screen">
<td><p>A_ScreenWidth<br>
A_ScreenHeight</p></td>
<td><p>The width and height of the primary monitor, in pixels (e.g. 1024 and 768).</p>
<p>To discover the dimensions of other monitors in a multi-monitor system, use <a href="commands/SysGet.htm">SysGet</a>.</p>
<p>To instead discover the width and height of the entire desktop (even if it spans multiple monitors), use the following example:</p>
<pre>
<a href="commands/SysGet.htm">SysGet</a>, VirtualWidth, 78
<a href="commands/SysGet.htm">SysGet</a>, VirtualHeight, 79
</pre>
<p>In addition, use <a href="commands/SysGet.htm">SysGet</a> to discover the work area of a monitor, which can be smaller than the monitor's total area because the taskbar and other registered desktop toolbars are excluded.</p></td>
</tr>
<tr id="ScreenDPI">
<td>A_ScreenDPI <span class="ver">[v1.1.11+]</span></td>
<td>Number of pixels per logical inch along the screen width. In a system with multiple display monitors, this value is the same for all monitors. On most systems this is 96; it depends on the system's text size (DPI) setting. See also <a href="commands/Gui.htm#DPIScale">Gui -DPIScale</a>.</td>
</tr>
<tr id="IPAddress">
<td>A_IPAddress1 through 4</td>
<td>The IP addresses of the first 4 network adapters in the computer.</td>
</tr>
</table>
<h3 id="misc">Misc.</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>
<tr id="Cursor">
<td>A_Cursor</td>
<td><p>The type of mouse cursor currently being displayed. It will be one of the following words: AppStarting, Arrow, Cross, Help, IBeam, Icon, No, Size, SizeAll, SizeNESW, SizeNS, SizeNWSE, SizeWE, UpArrow, Wait, Unknown. The acronyms used with the size-type cursors are compass directions, e.g. NESW = NorthEast+SouthWest. The hand-shaped cursors (pointing and grabbing) are classified as Unknown.</p></td>
</tr>
<tr id="Caret">
<td>A_CaretX<br>
A_CaretY</td>
<td><p>The current X and Y coordinates of the caret (text insertion point). The coordinates are relative to the active window unless <a href="commands/CoordMode.htm">CoordMode</a> is used to make them relative to the entire screen. If there is no active window or the caret position cannot be determined, these variables are blank.</p>
<p>The following script allows you to move the caret around to see its current position displayed in an auto-update tooltip. Note that some windows (e.g. certain versions of MS Word) report the same caret position regardless of its actual position.</p>
<pre>
#Persistent
SetTimer, WatchCaret, 100
return
WatchCaret:
ToolTip, X%A_CaretX% Y%A_CaretY%, A_CaretX, A_CaretY - 20
return
</pre>
</td>
</tr>
<tr id="Clipboard">
<td>Clipboard</td>
<td rowspan="2">Can be used to get or set the contents of the OS's clipboard. For details, see <a href="misc/Clipboard.htm">Clipboard</a>.</td>
</tr>
<tr id="A_Clipboard">
<td>A_Clipboard <span class="ver">[v1.1.35+]</span></td>
</tr>
<tr id="ClipboardAll">
<td>ClipboardAll</td>
<td>The entire contents of the clipboard (such as formatting and text). For details, see <a href="misc/Clipboard.htm#ClipboardAll">ClipboardAll</a>.</td>
</tr>
<tr id="ErrorLevel">
<td>ErrorLevel</td>
<td>This variable is set by some commands to indicate their success or failure. For details, see <a href="misc/ErrorLevel.htm">ErrorLevel</a>.</td>
</tr>
<tr id="LastError">
<td>A_LastError</td>
<td>The result from the OS's GetLastError() function or the last COM object invocation. For details, see <a href="commands/DllCall.htm#LastError">DllCall()</a> and <a href="commands/Run.htm#LastError">Run/RunWait</a>.</td>
</tr>
<tr id="TrueFalse">
<td>True<br />False</td>
<td><p>Contain 1 and 0. They can be used to make a script more readable. For details, see <a href="Concepts.htm#boolean">Boolean Values</a>.</p>
</td>
</tr>
</table>
<h3 id="loop">Loop</h3>
<table class="info">
<tr>
<th abbr="Var">Variable</th>
<th abbr="Descr">Description</th>
</tr>