| Both sides previous revision Previous revision Next revision | Previous revision |
| guides:v1_v2_cheat_sheet [2023-03-21 18:17] – Fix grammar typo micha-ohne-el | guides:v1_v2_cheat_sheet [2025-01-13 19:37] (current) – [v1→2 Conversion Cheat Sheet] Add auto-converter widget to page geek |
|---|
| ====== v1→2 Conversion Cheat Sheet ====== | ====== v1→2 Conversion Cheat Sheet ====== |
| | |
| | ===== Converter ===== |
| | |
| | Attempt to convert AHKv1 syntax to AHKv2 using the [[https://www.autohotkey.com/boards/viewtopic.php?f=6&t=25100|AHK-v2-script-converter]] project. |
| | |
| | <converter> |
| | ; Requires AutoHotkey v1.1.26+, and the keyboard hook must be installed. |
| | #InstallKeybdHook |
| | SendSuppressedKeyUp(key) { |
| | DllCall("keybd_event" |
| | , "char", GetKeyVK(key) |
| | , "char", GetKeySC(key) |
| | , "uint", KEYEVENTF_KEYUP := 0x2 |
| | , "uptr", KEY_BLOCK_THIS := 0xFFC3D450) |
| | } |
| | |
| | ; Disable Alt+key shortcuts for the IME. |
| | ~LAlt::SendSuppressedKeyUp("LAlt") |
| | |
| | ; Test hotkey: |
| | !CapsLock::MsgBox % A_ThisHotkey |
| | |
| | ; Remap CapsLock to LCtrl in a way compatible with IME. |
| | *CapsLock:: |
| | Send {Blind}{LCtrl DownR} |
| | SendSuppressedKeyUp("LCtrl") |
| | return |
| | *CapsLock up:: |
| | Send {Blind}{LCtrl Up} |
| | return |
| | </converter> |
| |
| ===== General ===== | ===== General ===== |
| - Commands do not support a first comma anymore.\\ Change ❌''Sleep, 1000'' to ✅''Sleep 1000''. | - Commands do not support a first comma anymore.\\ Change ❌''Sleep, 1000'' to ✅''Sleep 1000''. |
| - All commands have been turned into functions. Command syntax is just a function call without parentheses (commands can be //any// function, even user defined ones). Consequently, plain text parameters are gone and all parameters are expressions all the time.\\ Change ❌''MsgBox Hello'' to ✅''MsgBox "Hello"'' or ✅''MsgBox("Hello")'' | - All commands have been turned into functions. Command syntax is just a function call without parentheses (commands can be //any// function, even user defined ones). Consequently, plain text parameters are gone and all parameters are expressions all the time.\\ Change ❌''MsgBox Hello'' to ✅''MsgBox "Hello"'' or ✅''MsgBox("Hello")'' |
| - Memory is reserved using ''Buffer()'' objects not ''VarSetCapacity()''. Buffer is an Object, which always pass by reference, so you don't pass binary data by reference anymore. ''VarSetStrCapcaity()'' exists but //ONLY// for string optimization.\\ Change ❌''VarSetCapacity(var, capacity, fillByte)'' to ✅''var := Buffer(capacity, fillByte)'' | - Memory is reserved using ''Buffer()'' objects not ''VarSetCapacity()''. Buffer is an Object, which always pass by reference, so you don't pass binary data by reference anymore. ''VarSetStrCapacity()'' exists but //ONLY// for string optimization.\\ Change ❌''VarSetCapacity(var, capacity, fillByte)'' to ✅''var := Buffer(capacity, fillByte)'' |
| - Ampersand (''&'') is no longer the "address of" operator.\\ Change ❌''DllCall(..., "Ptr", &var)'' to ✅''DllCall(..., "Ptr", var)'' (where ''var'' is a ''Buffer'' object) | - Ampersand (''&'') is no longer the "address of" operator.\\ Change ❌''DllCall(..., "Ptr", &var)'' to ✅''DllCall(..., "Ptr", var)'' (where ''var'' is a ''Buffer'' object) |
| - Guis are fully object-oriented, distinguished by variable reference not by name. | - Guis are fully object-oriented, distinguished by variable reference not by name. |
| MsgBox "Bye " (varWritable := "Jeff") | MsgBox "Bye " (varWritable := "Jeff") |
| }</code> | }</code> |
| - Variables can be ''unset'' (which is a state, not a value). Unset variables throw when read. Unset makes a great default value.\\ Change ❌''MyFunc(param1, param2 := "") {...}'' to ✅''MyFunc(param1, param2 := unset) {...}''\\ Change ❌''if (param2 != "")'' to ✅''if IsSet(param2)''\\ Change ❌''var := [1, , 2]'' to ✅''var := [1, unset, 2]''\\ Change ❌''FunctionCall(required1, required2, , optional2)'' to ✅''FunctionCall(required1, required2, unset, optional2)''\\ Change ❌''var := "" ; Empty the variable'' to ✅''var := Unset'' (unless you need ''var'' to be an empty string) | - Variables start as ''unset'' (which is a state, not a value). Unset variables throw when read. Unset makes a great default parameter.\\ Change ❌''MyFunc(param1, param2 := "") {...}'' to ✅''MyFunc(param1, param2 := unset) {...}''\\ Change ❌''if (param2 != "")'' to ✅''if IsSet(param2)''\\ Change ❌''var := [1, , 2]'' to ✅''var := [1, unset, 2]''\\ Change ❌''FunctionCall(required1, required2, , optional2)'' to ✅''FunctionCall(required1, required2, unset, optional2)''\\ Change ❌''var := "" ; Empty the variable'' to ✅''var := Unset'' (unless you need ''var'' to be an empty string) |
| |
| **New Stuff** | **New Stuff** |