Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
user:geek:tricks [2022-03-20 19:05] – [DllCall] Add GetClipboardOwner geek | user:geek:tricks [2023-07-15 13:02] (current) – [Writing Libraries] Adjust for better sandbox behavior geek | ||
---|---|---|---|
Line 5: | Line 5: | ||
Repeat a String. | Repeat a String. | ||
- | <code autohotkey> | + | <runner ahk1> |
StrRepeat(String, | StrRepeat(String, | ||
{ | { | ||
return StrReplace(Format(" | return StrReplace(Format(" | ||
} | } | ||
- | </code> | + | |
+ | MsgBox, % StrRepeat(" | ||
+ | </runner> | ||
Pad a string to a given length. | Pad a string to a given length. | ||
- | <code autohotkey> | + | <runner ahk1> |
Var := " | Var := " | ||
Line 25: | Line 27: | ||
MsgBox, % SubStr(" | MsgBox, % SubStr(" | ||
MsgBox, % SubStr(Var " | MsgBox, % SubStr(Var " | ||
- | </code> | + | </runner> |
Remove extraneous delimiters when compiling a list in a loop WITHOUT using an if statement. | Remove extraneous delimiters when compiling a list in a loop WITHOUT using an if statement. | ||
- | <code autohotkey> | + | <runner ahk1> |
Loop, 9 | Loop, 9 | ||
List .= ", " A_Index | List .= ", " A_Index | ||
Line 38: | Line 40: | ||
; LTrim can be used to remove many delimiters | ; LTrim can be used to remove many delimiters | ||
MsgBox, % LTrim(List, ", ") | MsgBox, % LTrim(List, ", ") | ||
- | </code> | + | </runner> |
Check if a string starts with another string. | Check if a string starts with another string. | ||
Line 57: | Line 59: | ||
Use standard JSON format when defining your objects by placing the definition into a continuation section. | Use standard JSON format when defining your objects by placing the definition into a continuation section. | ||
- | <code autohotkey> | + | <runner ahk1> |
; http:// | ; http:// | ||
MyObject := | MyObject := | ||
Line 84: | Line 86: | ||
} | } | ||
) | ) | ||
- | </code> | + | |
+ | Print(MyObject) | ||
+ | </runner> | ||
===== Toggles ===== | ===== Toggles ===== | ||
Line 90: | Line 94: | ||
Do a toggle with only one line. | Do a toggle with only one line. | ||
- | <code autohotkey> | + | <runner |
- | Loop | + | Loop 10 |
MsgBox, % Toggle := !Toggle | MsgBox, % Toggle := !Toggle | ||
- | </code> | + | </runner> |
===== DllCall ===== | ===== DllCall ===== | ||
Line 162: | Line 166: | ||
When writing a library that has code which must be run before any of your functions can be used, you can create an initialization function that runs itself automatically when the script starts. This eliminates any need for the library' | When writing a library that has code which must be run before any of your functions can be used, you can create an initialization function that runs itself automatically when the script starts. This eliminates any need for the library' | ||
- | <code autohotkey> | + | <runner ahk1> |
+ | global sampleVariable | ||
Initialize() | Initialize() | ||
{ | { | ||
- | Static Dummy := Initialize() | + | static _ := Initialize() |
- | MsgBox, This init function has been called automatically | + | sampleVariable := " |
} | } | ||
- | </code> | + | |
+ | MsgBox, % sampleVariable | ||
+ | </runner> | ||
If your library defines hotkeys, it can break other scripts that include it in their auto-execute section. You can avoid this by wrapping your hotkey definitions in '' | If your library defines hotkeys, it can break other scripts that include it in their auto-execute section. You can avoid this by wrapping your hotkey definitions in '' | ||
- | <code autohotkey> | + | <runner ahk1> |
if False | if False | ||
{ | { | ||
Line 180: | Line 188: | ||
MsgBox, Auto-execution not interrupted | MsgBox, Auto-execution not interrupted | ||
- | </code> | + | |
+ | ExitApp | ||
+ | </runner> | ||
===== Windows ===== | ===== Windows ===== | ||
Line 304: | Line 314: | ||
Find, and optionally replace, all matches of regular expression efficiently using a custom enumerator. | Find, and optionally replace, all matches of regular expression efficiently using a custom enumerator. | ||
- | <code autohotkey> | + | <runner ahk1> |
Haystack = | Haystack = | ||
( | ( | ||
Line 353: | Line 363: | ||
} | } | ||
} | } | ||
- | </code> | + | </runner> |
===== Networking and Web ===== | ===== Networking and Web ===== | ||
Line 394: | Line 404: | ||
Overwrite a file in one step using '' | Overwrite a file in one step using '' | ||
- | <code autohotkey> | + | <runner ahk1> |
/* Old method: | /* Old method: | ||
FileDelete, | FileDelete, | ||
Line 400: | Line 410: | ||
*/ | */ | ||
- | FileOpen(" | + | FileOpen(" |
- | </code> | + | FileOpen(" |
+ | |||
+ | FileRead, contents, FileName.txt | ||
+ | MsgBox, Contains only: %contents% | ||
+ | </runner> | ||
===== Notes ===== | ===== Notes ===== |