versions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
versions [2023-01-24 13:13] – [v1 or v2?] Re-title article geekversions [2023-01-25 17:23] (current) – ↷ Page moved from playground:versions to versions geek
Line 109: Line 109:
 For example, the ''%%=%%'' symbol in v1 (''%%a%%'' is a variable in all cases, but the meaning of ''%%b%%'' varies): For example, the ''%%=%%'' symbol in v1 (''%%a%%'' is a variable in all cases, but the meaning of ''%%b%%'' varies):
  
-<code>+<code AutoHotkey>
 a = b           ; Assignment - legacy syntax, 'b' is literal a = b           ; Assignment - legacy syntax, 'b' is literal
 a = b + 1       ; Common mistake - literally assigns the text "b + 1" a = b + 1       ; Common mistake - literally assigns the text "b + 1"
Line 136: Line 136:
 The legacy syntax allows a command to be written with fewer “meta-characters”; often just the command and literally whatever textual parameter the command requires. For example: The legacy syntax allows a command to be written with fewer “meta-characters”; often just the command and literally whatever textual parameter the command requires. For example:
  
-<code>+<code AutoHotkey>
 ifWinNotExist ahk_class Notepad ifWinNotExist ahk_class Notepad
 { {
Line 152: Line 152:
 Because variable names would be interpreted as literal text by default, including the value of a variable requires marking it with extra symbols. So instead of surrounding the literal text with quote marks, you must surround the variables with ''%%%%%'' percent signs. For example, perhaps we want to modify the code above to wait specifically for a window belonging to the new Notepad process: Because variable names would be interpreted as literal text by default, including the value of a variable requires marking it with extra symbols. So instead of surrounding the literal text with quote marks, you must surround the variables with ''%%%%%'' percent signs. For example, perhaps we want to modify the code above to wait specifically for a window belonging to the new Notepad process:
  
-<code> +<code AutoHotkey
-    Run Notepad,,, PID +Run Notepad,,, PID 
-    WinWait ahk_pid %PID%+WinWait ahk_pid %PID%
 </code> </code>
  
Line 163: Line 163:
 The example above uses ''%%ifWinNotExist%%'', which is one of several legacy if-statements that check only a single condition. It is often preferred to use the newer syntax even in v1, such as to add a second condition. For example: The example above uses ''%%ifWinNotExist%%'', which is one of several legacy if-statements that check only a single condition. It is often preferred to use the newer syntax even in v1, such as to add a second condition. For example:
  
-<code>+<code AutoHotkey>
 if not (WinExist("ahk_class Notepad") or WinExist("ahk_class WordPadClass")) if not (WinExist("ahk_class Notepad") or WinExist("ahk_class WordPadClass"))
 { {
Line 177: Line 177:
 Since v1 commands use legacy syntax by default (although [[https://www.autohotkey.com/docs/Language.htm#numeric-parameters|some]] also accept a //subset// of expressions by default), the language requires us to mark the parameter in some way if we want it to be an expression. The marker chosen for v1 is the [[https://www.autohotkey.com/docs/Language.htm#-expression|percent-space prefix]]: Since v1 commands use legacy syntax by default (although [[https://www.autohotkey.com/docs/Language.htm#numeric-parameters|some]] also accept a //subset// of expressions by default), the language requires us to mark the parameter in some way if we want it to be an expression. The marker chosen for v1 is the [[https://www.autohotkey.com/docs/Language.htm#-expression|percent-space prefix]]:
  
-<code>+<code AutoHotkey>
 if not (WinExist("ahk_class Notepad") or WinExist("ahk_class WordPadClass")) if not (WinExist("ahk_class Notepad") or WinExist("ahk_class WordPadClass"))
 { {
Line 193: Line 193:
 By contrast, v2 strips away the legacy syntax, leaving only expressions. For example: By contrast, v2 strips away the legacy syntax, leaving only expressions. For example:
  
-<code>+<code AutoHotkey>
 if not (WinExist("ahk_class Notepad") or WinExist("ahk_class WordPadClass")) if not (WinExist("ahk_class Notepad") or WinExist("ahk_class WordPadClass"))
 { {
Line 215: Line 215:
 A great thing about AutoHotkey is that it is easy to make something useful happen with a few lines of simple code. Most users probably start with basic things like defining a hotkey to open a program, activate a window, send some template text or similar. Often a useful hotkey can be created with a single line, simply writing a command name and some text that the command uses. A great thing about AutoHotkey is that it is easy to make something useful happen with a few lines of simple code. Most users probably start with basic things like defining a hotkey to open a program, activate a window, send some template text or similar. Often a useful hotkey can be created with a single line, simply writing a command name and some text that the command uses.
  
-<code>+<code AutoHotkey>
 #n::Run Notepad #n::Run Notepad
 </code> </code>
Line 229: Line 229:
 A new user of v2 doesn’t need to learn all of the expression operators, or even what “expressions” are, to begin writing code. As with v1, they just need to learn some simple patterns, like how to pass some literal text to a function. A new user of v2 doesn’t need to learn all of the expression operators, or even what “expressions” are, to begin writing code. As with v1, they just need to learn some simple patterns, like how to pass some literal text to a function.
  
-<code>+<code AutoHotkey>
 #n::Run "Notepad" #n::Run "Notepad"
 </code> </code>