commands as functions (AHK v2 functions for AHK v1)

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

commands as functions (AHK v2 functions for AHK v1)

26 Mar 2017, 17:19

[Latest version:]
commands as functions (AHK v2 functions for AHK v1) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 18#p210818

==================================================

[Changelog:]

Code: Select all

;AHK v2 functions for AHK v1 changelog
;[created: 2017-03-26]

;[updated: 2017-08-25]
;added - ClipboardAll placeholder, ControlXXX, DriveXXX, InputEnd, RandomSeed
;corrected - SoundPlay, StrLower, StrUpper, Type
;modified - FileAppend, FileRead, FileSetAttrib, FileSetTime, MsgBox, RegDelete, RegRead, RegWrite, TrayTip, WinMove, WinSetEnabled, WinSetTitle
;removed - Deref, GuiXXX
;tidied - EnvSet, PixelSearch, RegDeleteKey, WinGetPos

;[updated: 2017-08-25]
;modified - InputBox, MsgBox
;tidied - Download

;[updated: 2018-01-29]
;added - CaretGetPos, TraySetIcon, WinGetClientPos
;modified - ClipboardAll (placeholder), ControlAddItem, ControlChoose, ControlChooseString, FileRead, PostMessage, RegDeleteKey, SendMessage, SoundGet, SoundSet
;corrected - ControlSendRaw, DriveLock, DriveSetLabel, MsgBox
;modified+ - changed optional parameters: ControlGetList, ControlSend, ControlSendRaw, ControlSetText, DriveEject, DriveGetList, DriveGetStatusCD, FileAppend
;removed - Menu
;tidied - MsgBox, RegDelete, RegRead, RegWrite, WinSetTitle
==================================================

At the time of writing (March 2017), AHK v2 alpha introduces 139+50=189 new functions.
- 139 are function versions of AHK v1 commands (with the same name as existing AHK v1 commands).
- 50 are variants of AHK v1 commands (with names different from any existing AHK v1 commands) or are functions that introduce new functionality.

List of functions (needed for the library):

Code: Select all

;based on:
;list of every command/function/variable from across all versions - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=27321&p=131642#p131642

;function versions of commands present in both AHK v1/v2 (139)
BlockInput
Click
ClipWait
Control
ControlClick
ControlFocus
ControlGet
ControlGetFocus
ControlGetPos
ControlGetText
ControlMove
ControlSend
ControlSendRaw
ControlSetText
CoordMode
Critical
DetectHiddenText
DetectHiddenWindows
Drive
DriveGet
Edit
EnvGet
EnvSet
Exit
ExitApp
FileAppend
FileCopy
FileCreateShortcut
FileDelete
FileEncoding
FileGetAttrib
FileGetShortcut
FileGetSize
FileGetTime
FileGetVersion
FileInstall
FileMove
FileRead
FileRecycle
FileRecycleEmpty
FileSetAttrib
FileSetTime
FormatTime
GroupActivate
GroupAdd
GroupClose
GroupDeactivate
Gui
GuiControl
GuiControlGet
Hotkey
ImageSearch
IniDelete
IniRead
IniWrite
Input
InputBox
KeyHistory
KeyWait
ListHotkeys
ListLines
ListVars
Menu
MouseClick
MouseClickDrag
MouseGetPos
MouseMove
MsgBox
OutputDebug
Pause
PixelGetColor
PixelSearch
PostMessage
Random
RegDelete
RegRead
RegWrite
Reload
Run
RunAs
RunWait
Send
SendEvent
SendInput
SendLevel
SendMessage
SendMode
SendPlay
SendRaw
SetCapsLockState
SetControlDelay
SetDefaultMouseSpeed
SetKeyDelay
SetMouseDelay
SetNumLockState
SetRegView
SetScrollLockState
SetStoreCapslockMode
SetTimer
SetTitleMatchMode
SetWinDelay
SetWorkingDir
Shutdown
Sleep
Sort
SoundBeep
SoundGet
SoundPlay
SoundSet
SplitPath
StatusBarGetText
StatusBarWait
StringCaseSense
Suspend
SysGet
Thread
ToolTip
TrayTip
WinActivate
WinActivateBottom
WinClose
WinGetClass
WinGetPos
WinGetText
WinGetTitle
WinHide
WinKill
WinMaximize
WinMinimize
WinMinimizeAll
WinMinimizeAllUndo
WinMove
WinRestore
WinSetTitle
WinShow
WinWait
WinWaitActive
WinWaitClose
WinWaitNotActive

;commands added from AHK v2 (50)
DateAdd
DateDiff
Deref
DirCopy
DirCreate
DirDelete
DirExist
DirMove
DirSelect
Download
FileSelect
MenuSelect
MonitorGet
MonitorGetCount
MonitorGetName
MonitorGetPrimary
MonitorGetWorkArea
ProcessClose
ProcessExist
ProcessSetPriority
ProcessWait
ProcessWaitClose
RegDeleteKey
StrLower
StrUpper
Type
WinGetControls
WinGetControlsHwnd
WinGetCount
WinGetExStyle
WinGetID
WinGetIDLast
WinGetList
WinGetMinMax
WinGetPID
WinGetProcessName
WinGetProcessPath
WinGetStyle
WinGetTransColor
WinGetTransparent
WinMoveBottom
WinMoveTop
WinRedraw
WinSetAlwaysOnTop
WinSetEnabled
WinSetExStyle
WinSetRegion
WinSetStyle
WinSetTransColor
WinSetTransparent
List of commands/functions being removed (57+7=64) (for reference):

Code: Select all

;old AHK v1 functions (7)
Asc
ComObjEnwrap
ComObjMissing
ComObjParameter
ComObjUnwrap
ObjInsert
ObjRemove

;old AHK v1 commands (57)
AutoTrim
DriveSpaceFree
EnvAdd
EnvDiv
EnvMult
EnvSub
EnvUpdate
FileCopyDir
FileCreateDir
FileMoveDir
FileReadLine
FileRemoveDir
FileSelectFile
FileSelectFolder
IfEqual
IfExist
IfGreater
IfGreaterOrEqual
IfInString
IfLess
IfLessOrEqual
IfMsgBox
IfNotEqual
IfNotExist
IfNotInString
IfWinActive
IfWinExist
IfWinNotActive
IfWinNotExist
Process
Progress
SetBatchLines
SetEnv
SetFormat
SoundGetWaveVolume
SoundSetWaveVolume
SplashImage
SplashTextOff
SplashTextOn
StringGetPos
StringLeft
StringLen
StringLower
StringMid
StringReplace
StringRight
StringSplit
StringTrimLeft
StringTrimRight
StringUpper
Transform
UrlDownloadToFile
WinGet
WinGetActiveStats
WinGetActiveTitle
WinMenuSelectItem
WinSet
The aim of this project is to make those functions available to AHK v1.

==================================================

I recently found out that Coco has been working on a similar project.
- I would say that his code is 98% the same as mine, plus he has some nice RegEx for the 'InputBox' function, and has recreated the 'Type' function, which is the one function I was yet to write.
- So reluctantly I think it would be better to support his effort, rather than cause massive confusion, with two independent sets of almost identical code.

Example functions:

Code: Select all

IniWrite(Value, Filename, Section, Key:="") ;Coco
{
    IniWrite %Value%, %Filename%, %Section%, %Key%
    return !ErrorLevel
}

IniWrite(Value, Filename, Section, Key:="") ;jeeswg
{
	IniWrite, % Value, % Filename, % Section, % Key
	return !ErrorLevel
}
GitHub - cocobelgica/AutoHotkey-Future: Port of AutoHotkey v2.0-a built-in functions for AHK v1.1+
https://github.com/cocobelgica/AutoHotkey-Future

The last work there was done in March 2016, MsgBox/InputBox/TrayTip for example, may need to be updated.

Useful comments regarding the functions (and potential issues/problems) are available here:
Default/Portable installation StdLib - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 13&t=10434
AutoHotkey-Future/Lib at master · cocobelgica/AutoHotkey-Future · GitHub
https://github.com/cocobelgica/AutoHotk ... master/Lib

The code from Mar 2016 has:
- 136 'AHK v1' functions (missing Edit/FileAppend/PostMessage/SendMessage) (EnvUpdate is there but shouldn't be).
- 49 'AHK v2' functions (missing RegDeleteKey).

Some code I wrote in Coco's style for the missing functions:

Code: Select all

Edit()
{
    Edit
}
FileAppend(Text:="", Filename:="", Encoding:="")
{
    FileAppend %Text%, %Filename%, %Encoding%
    return !ErrorLevel
}
PostMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    PostMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (ErrorLevel = "FAIL")
        ErrorLevel := "ERROR"
}
RegDeleteKey(RootKeySubKey)
{
    RegDelete %RootKeySubKey%
    return !ErrorLevel
}
SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")
{
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    if (ErrorLevel = "FAIL")
        ErrorLevel := "ERROR"
}
Code to combine the individual function ahk files, into one file:

Code: Select all

;w:: ;convert multiline text to one-liners for variable assignment
;vText := JEE_GetSelectedText()
ControlGet, vText, Selected, , Edit1, A
vText := StrReplace(vText, "``", "````")
vText := StrReplace(vText, "`r`n", "``n") ;for LF
;vText := StrReplace(vText, "`r`n", "``r``n") ;for CRLF
vText := StrReplace(vText, "%", "```%")
vText := StrReplace(vText, ";", "```;")
Clipboard := "vText = " vText
;SendInput ^v
return

q:: ;collect code from individual small ahk files and put onto clipboard
vTextEdit = Edit()`n{`n    Edit`n}
vTextFileAppend = FileAppend(Text:="", Filename:="", Encoding:="")`n{`n    FileAppend `%Text`%, `%Filename`%, `%Encoding`%`n    return !ErrorLevel`n}
vTextPostMessage = PostMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")`n{`n    PostMessage `%Msg`%, `%wParam`%, `%lParam`%, `%Control`%, `%WinTitle`%, `%WinText`%, `%ExcludeTitle`%, `%ExcludeText`%`n    if (ErrorLevel = "FAIL")`n        ErrorLevel := "ERROR"`n}
vTextRegDeleteKey = RegDeleteKey(RootKeySubKey)`n{`n    RegDelete `%RootKeySubKey`%`n    return !ErrorLevel`n}
vTextSendMessage = SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")`n{`n    SendMessage `%Msg`%, `%wParam`%, `%lParam`%, `%Control`%, `%WinTitle`%, `%WinText`%, `%ExcludeTitle`%, `%ExcludeText`%, `%Timeout`%`n    if (ErrorLevel = "FAIL")`n        ErrorLevel := "ERROR"`n}
;functions to add to final text
vListA := "Edit,FileAppend,PostMessage,RegDeleteKey,SendMessage"
;functions to remove from final text
vListR := "EnvUpdate"

vDir = %A_Desktop%\AutoHotkey-Future-master\Lib
if !InStr(FileExist(vDir), "D")
	return

vList := "`n"
Loop, Files, % vDir "\*.ahk", F
{
	vPath := A_LoopFileFullPath
	SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
	vList .= vNameNoExt "`n"
}
Loop, Parse, vListA, `,
	if !InStr(vList, "`n" A_LoopField "`n")
		vList .= A_LoopField "`n"
vList := Trim(vList, "`n")
Sort, vList

vOutput := ""
VarSetCapacity(vOutput, 100000*2)
Loop, Parse, vList, `n
{
	if A_LoopField in % vListR
		continue
	vPath := vDir "\" A_LoopField ".ahk"
	if FileExist(vPath)
		FileRead, vText, % vPath
	else
		vText := vText%A_LoopField%
	vText := StrReplace(vText, "`n", "`r`n")
	vOutput .= vText "`r`n"
}
;trim trailing spaces
vOutput := RegExReplace(vOutput, "m) +$")
Clipboard := vOutput
MsgBox % "done"
return
==================================================

A beta demonstration of what an 'AHK v2 functions for AHK v1' library might look like, based on Coco's code.

Note: FileInstall cannot be completely recreated as a function. [EDIT:][Actually, the post below mentions some workarounds.]
Note: The Gui command would make any script that uses such a library #Persistent, so I would advise commenting out that function. [EDIT:][You could have just the Gui function in a separate file if you wanted it some times but not other times.]

Code: Select all

;AHK v2 functions for AHK v1
BlockInput(Mode)
{
    BlockInput %Mode%
}
Click(Params*)
{
    local i, Param, Args
    for i, Param in Params
        Args .= " " . Param
    Click %Args%
}
ClipWait(SecondsToWait:="", Param:=1)
{
    ClipWait %SecondsToWait%, %Param%
    return !ErrorLevel
}
Control(Cmd, Value:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control %Cmd%, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlClick(ControlOrPos:="", WinTitle:="", WinText:="", WhichButton:="", ClickCount:="", Options:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlClick %ControlOrPos%, %WinTitle%, %WinText%, %WhichButton%, %ClickCount%, %Options%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlFocus(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlFocus %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlGet(Cmd, Value:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, %Cmd%, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
ControlGetFocus(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGetFocus OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
ControlGetPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlGetPos X, Y, Width, Height, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlGetText(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGetText OutputVar, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
ControlMove(Control:="", X:="", Y:="", Width:="", Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlMove %Control%, %X%, %Y%, %Width%, %Height%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlSend(Control:="", Keys:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlSend %Control%, %Keys%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlSendRaw(Control:="", Keys:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlSendRaw %Control%, %Keys%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlSetText(Control:="", NewText:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlSetText %Control%, %NewText%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
CoordMode(Param1, Param2:="Screen")
{
    CoordMode %Param1%, %Param2%
}
Critical(Param:="")
{
    Critical %Param%
}
DateAdd(DateTime, Time, TimeUnits)
{
    EnvAdd DateTime, %Time%, %TimeUnits%
    return DateTime
}
DateDiff(DateTime1, DateTime2, TimeUnits)
{
    EnvSub DateTime1, %DateTime2%, %TimeUnits%
    return DateTime1
}
Deref(String)
{
    local OutputVar
    Transform OutputVar, Deref, %String%
    return OutputVar
}
DetectHiddenText(OnOrOff)
{
    DetectHiddenText %OnOrOff%
}
DetectHiddenWindows(OnOrOff)
{
    DetectHiddenWindows %OnOrOff%
}
DirCopy(Source, Dest, Flag:=0)
{
    FileCopyDir %Source%, %Dest%, %Flag%
    return !ErrorLevel
}
DirCreate(DirName)
{
    FileCreateDir %DirName%
    return !ErrorLevel
}
DirDelete(DirName, Recurse:=0)
{
    FileRemoveDir %DirName%, %Recurse%
    return !ErrorLevel
}
DirExist(FilePattern)
{
    local AttributeString := FileExist(FilePattern)
    return InStr(AttributeString, "D") ? AttributeString : ""
}
DirMove(Source, Dest, Flag:=0)
{
    FileMoveDir %Source%, %Dest%, %Flag%
    return !ErrorLevel
}
DirSelect(StartingFolder:="", Options:=1, Prompt:="")
{
    local OutputVar
    FileSelectFolder OutputVar, %StartingFolder%, %Options%, %Prompt%
    if !ErrorLevel
        return OutputVar
}
Download(URL, FileName)
{
    URLDownloadToFile %URL%, %FileName%
    return !ErrorLevel
}
Drive(SubCommand, Drive:="", Value:="")
{
    Drive %SubCommand%, %Drive%, %Value%
    return !ErrorLevel
}
DriveGet(Cmd, Value:="")
{
    local OutputVar
    if (Cmd != "SpaceFree")
        DriveGet OutputVar, %Cmd%, %Value%
    else
        DriveSpaceFree, OutputVar, %Value%
    if !ErrorLevel
        return OutputVar
}
Edit()
{
    Edit
}
EnvGet(EnvVarName)
{
    local OutputVar
    EnvGet OutputVar, %EnvVarName%
    return OutputVar
}
EnvSet(EnvVar, Value:="")
{
    EnvSet, %EnvVar%, %Value%
    return !ErrorLevel
}
Exit(ExitCode:=0)
{
    Exit %ExitCode%
}
ExitApp(ExitCode:=0)
{
    ExitApp %ExitCode%
}
FileAppend(Text:="", Filename:="", Encoding:="")
{
    FileAppend %Text%, %Filename%, %Encoding%
    return !ErrorLevel
}
FileCopy(Source, Dest, Flag:=0)
{
    FileCopy %Source%, %Dest%, %Flag%
    return !ErrorLevel
}
FileCreateShortcut(Target, LinkFile, WorkingDir:="", Args:="", Description:="", IconFile:="", ShortcutKey:="", IconNumber:="", RunState:=1)
{
    FileCreateShortcut %Target%, %LinkFile%, %WorkingDir%, %Args%, %Description%, %IconFile%, %ShortcutKey%, %IconNumber%, %RunState%
    return !ErrorLevel
}
FileDelete(FilePattern)
{
    FileDelete %FilePattern%
    return !ErrorLevel
}
FileEncoding(Encoding:="")
{
    FileEncoding %Encoding%
}
FileGetAttrib(Filename:="")
{
    local OutputVar
    FileGetAttrib OutputVar, %Filename%
    if !ErrorLevel
        return OutputVar
}
FileGetShortcut(LinkFile, ByRef OutTarget:="", ByRef OutDir:="", ByRef OutArgs:="", ByRef OutDescription:="", ByRef OutIcon:="", ByRef OutIconNum:="", ByRef OutRunState:="")
{
    FileGetShortcut %LinkFile%, OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState
    return !ErrorLevel
}
FileGetSize(Filename:="", Units:="")
{
    local OutputVar
    FileGetSize OutputVar, %Filename%, %Units%
    if !ErrorLevel
        return OutputVar
}
FileGetTime(Filename:="", WhichTime:="M")
{
    local OutputVar
    FileGetTime OutputVar, %Filename%, %WhichTime%
    if !ErrorLevel
        return OutputVar
}
FileGetVersion(Filename:="")
{
    local OutputVar
    FileGetVersion OutputVar, %Filename%
    if !ErrorLevel
        return OutputVar
}
FileInstall(Source, Dest, Flag:=0)
{
    FileCopy %Source%, %Dest%, %Flag%
    return !ErrorLevel
}
FileMove(SourcePattern, DestPattern, Flag:=0)
{
    FileMove %SourcePattern%, %DestPattern%, %Flag%
    return !ErrorLevel
}
FileRead(Filename)
{
    local OutputVar
    FileRead OutputVar, %Filename%
    if !ErrorLevel
        return OutputVar
}
FileRecycle(FilePattern)
{
    FileRecycle %FilePattern%
    return !ErrorLevel
}
FileRecycleEmpty(DriveLetter:="")
{
    FileRecycleEmpty %DriveLetter%
    return !ErrorLevel
}
FileSelect(Options:=0, RootDir_Filename:="", Prompt:="", Filter:="")
{
    local OutputVar
    FileSelectFile OutputVar, %Options%, %RootDir_Filename%, %Prompt%, %Filter%
    if !ErrorLevel
        return OutputVar
}
FileSetAttrib(Attributes, FilePattern:="", OperateOnFolders:=0, Recurse:=0)
{
    FileSetAttrib %Attributes%, %FilePattern%, %OperateOnFolders%, %Recurse%
    return !ErrorLevel
}
FileSetTime(YYYYMMDDHH24MISS:="", FilePattern:="", WhichTime:="M", OperateOnFolders:=0, Recurse:=0)
{
    FileSetTime %YYYYMMDDHH24MISS%, %FilePattern%, %WhichTime%, %OperateOnFolders%, %Recurse%
    return !ErrorLevel
}
FormatTime(YYYYMMDDHH24MISS:="", Format:="")
{
    local OutputVar
    FormatTime OutputVar, %YYYYMMDDHH24MISS%, %Format%
    return OutputVar
}
GroupActivate(GroupName, R:="")
{
    GroupActivate %GroupName%, %R%
    return !ErrorLevel
}
GroupAdd(GroupName, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    GroupAdd %GroupName%, %WinTitle%, %WinText%,, %ExcludeTitle%, %ExcludeText%
}
GroupClose(GroupName, AR:="")
{
    GroupClose %GroupName%, %AR%
}
GroupDeactivate(GroupName, R:="")
{
    GroupDeactivate %GroupName%, %R%
}
Gui(SubCommand, Param1:="", Param2:="", Param3:="", Param4:="")
{
    global ; assume global for vControlVars
    Gui %SubCommand%, %Param1%, %Param2%, %Param3%, %Param4%
}
GuiControl(SubCommand:="", ControlID:="", Param3:="")
{
    global
    GuiControl %SubCommand%, %ControlID%, %Param3%
    return !ErrorLevel
}
GuiControlGet(SubCommand:="", ControlID:="", Param4:="")
{
    global
    local OutputVar
    GuiControlGet OutputVar, %SubCommand%, %ControlID%, %Param4%
    if !ErrorLevel
        return OutputVar
}
Hotkey(Param1, Param2:="", Param3:="")
{
    Hotkey %Param1%, %Param2%, %Param3%
    if (InStr(Param1, "IfWin") || InStr(Param3, "UseErrorLevel"))
        return !ErrorLevel
}
ImageSearch(ByRef OutputVarX:="", ByRef OutputVarY:="", X1:="", Y1:="", X2:="", Y2:="", ImageFile:="")
{
    ImageSearch OutputVarX, OutputVarY, %X1%, %Y1%, %X2%, %Y2%, %ImageFile%
    return !ErrorLevel
}
IniDelete(Filename, Section, Key:="")
{
    IniDelete %Filename%, %Section%, %Key%
    return !ErrorLevel
}
IniRead(Filename, Section:="", Key:="", Default:="")
{
    local OutputVar
    IniRead OutputVar, %Filename%, %Section%, %Key%, %Default%
    if !ErrorLevel
        return OutputVar
}
IniWrite(Value, Filename, Section, Key:="")
{
    IniWrite %Value%, %Filename%, %Section%, %Key%
    return !ErrorLevel
}
Input(Options:="", EndKeys:="", MatchList:="")
{
    local OutputVar
    Input OutputVar, %Options%, %EndKeys%, %MatchList%
    return OutputVar
}
InputBox(Title:="", Prompt:="", Options:="", Default:="")
{
    local _, _X, _Y, _W, _H, _T, _P, _Err
    ; v2 validates the value of a particular option:
    ; X and Y = integer (can be negative)
    ; W and H = postive integer only
    ; T = postive integer/float
    ; Credits to Lexikos [https://goo.gl/VjMTYu , https://goo.gl/ebEjon]
    RegExMatch(Options, "i)^[ \t]*(?:(?:X(?<X>-?\d+)|Y(?<Y>-?\d+)|W(?<W>\d+)"
        . "|H(?<H>\d+)|T(?<T>\d+(?:\.\d+)?)|(?<P>Password\S?)"
        . "|(?<Err>\S+)(*ACCEPT)"
        . ")(?=[ \t]|$)[ \t]*)*$", _)

    if (_Err != "")
        throw Exception("Invalid option.", -1, _Err)

    local OutputVar
    InputBox, OutputVar, %Title%, %Prompt%, % _P ? "HIDE" : "", %_W%, %_H%, %_X%, %_Y%,, %_T%, %Default%
    return OutputVar
}
KeyHistory()
{
    KeyHistory
}
KeyWait(KeyName, Options:="")
{
    KeyWait %KeyName%, %Options%
    return !ErrorLevel
}
ListHotkeys()
{
    ListHotkeys
}
ListLines(OnOrOff:="")
{
    ListLines %OnOrOff%
}
ListVars()
{
; Limitation -> won't work if called from within a function
    global
    ListVars
}
Menu(MenuName, Cmd, P3:="", P4:="", P5:="")
{
    Menu %MenuName%, %Cmd%, %P3%, %P4%, %P5%
}
MenuSelect(WinTitle:="", WinText:="", Menu:="", SubMenu1:="", SubMenu2:="", SubMenu3:="", SubMenu4:="", SubMenu5:="", SubMenu6:="", ExcludeTitle:="", ExcludeText:="")
{
    WinMenuSelectItem %WinTitle%, %WinText%, %Menu%, %SubMenu1%, %SubMenu2%, %SubMenu3%, %SubMenu4%, %SubMenu5%, %SubMenu6%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
MonitorGet(N:="", ByRef OutLeft:="", ByRef OutTop:="", ByRef OutRight:="", ByRef OutBottom:="")
{
    local Out
    SysGet Out, Monitor, %N%
    return (OutLeft != "" && OutTop != "" && OutRight != "" && OutBottom != "")
}
MonitorGetCount()
{
    local OutputVar
    SysGet OutputVar, MonitorCount
    return OutputVar
}
MonitorGetName(N:="")
{
    local OutputVar
    SysGet OutputVar, MonitorName
    return OutputVar
}
MonitorGetPrimary()
{
    local OutputVar
    SysGet OutputVar, MonitorPrimary
    return OutputVar
}
MonitorGetWorkArea(N:="", ByRef OutLeft:="", ByRef OutTop:="", ByRef OutRight:="", ByRef OutBottom:="")
{
    local Out
    SysGet Out, MonitorWorkArea, %N%
    return (OutLeft != "" && OutTop != "" && OutRight != "" && OutBottom != "")
}
MouseClick(WhichButton:="Left", X:="", Y:="", ClickCount:="", Speed:="", DU:="", R:="")
{
    MouseClick %WhichButton%, %X%, %Y%, %ClickCount%, %Speed%, %DU%, %R%
}
MouseClickDrag(WhichButton, X1:="", Y1:="", X2:="", Y2:="", Speed:="", R:="")
{
    MouseClickDrag %WhichButton%, %X1%, %Y1%, %X2%, %Y2%, %Speed%, %R%
}
MouseGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="", ByRef OutputVarWin:="", ByRef OutputVarControl:="", Mode:=0)
{
    MouseGetPos OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, %Mode%
}
MouseMove(X, Y, Speed:="", R:="")
{
    MouseMove %X%, %Y%, %Speed%, %R%
}
MsgBox(Params*)
{
    local Len
    if (Len := Params.Length())
    {
        if (Len == 1)
            MsgBox % Params[1]
        else
            MsgBox % Params[1], % Params[2], % Params[3], % Params[4]
    }
    else
        MsgBox
}
OutputDebug(Text)
{
    OutputDebug %Text%
}
Pause(OnOffToggle:="", OperateOnUnderlyingThread:=0)
{
    Pause %OnOffToggle%, %OperateOnUnderlyingThread%
}
PixelGetColor(X, Y, AltSlow:="")
{
    local OutputVar
    PixelGetColor OutputVar, %X%, %Y%, %AltSlow% RGB ; v2 uses RGB
    if !ErrorLevel
        return OutputVar
}
PixelSearch(ByRef OutputVarX:="", ByRef OutputVarY:="", X1:="", Y1:="", X2:="", Y2:="", ColorID:="", Variation:=0, Fast:="")
{
    PixelSearch, OutputVarX, OutputVarY, %X1%, %Y1%, %X2%, %Y2%, %ColorID%, %Variation%, %Fast% RGB
    return !ErrorLevel
}
PostMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    PostMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (ErrorLevel = "FAIL")
        ErrorLevel := "ERROR"
}
ProcessClose(PIDorName)
{
    Process Close, %PIDorName%
    return ErrorLevel
}
ProcessExist(PIDorName:="")
{
    Process Exist, %PIDorName%
    return ErrorLevel
}
ProcessSetPriority(Priority, PIDorName:="")
{
    Process Priority, %PIDorName%, %Priority%
    return ErrorLevel
}
ProcessWait(PIDorName, SecondsToWait:="")
{
    Process Wait, %PIDorName%, %SecondsToWait%
    return ErrorLevel
}
ProcessWaitClose(PIDorName, SecondsToWait:="")
{
    Process WaitClose, %PIDorName%, %SecondsToWait%
    return ErrorLevel
}
Random(Min:="", Max:="")
{
    local OutputVar
    Random OutputVar, %Min%, %Max%
    return OutputVar
}
RegDelete(RootKeySubKey:="", ValueName:="")
{
    RegDelete %RootKeySubKey%, %ValueName%
    return !ErrorLevel
}
RegDeleteKey(RootKeySubKey)
{
    RegDelete %RootKeySubKey%
    return !ErrorLevel
}
RegRead(RootKeySubKey:="", ValueName:="")
{
    local OutputVar
    RegRead OutputVar, %RootKeySubKey%, %ValueName%
    if !ErrorLevel
        return OutputVar
}
RegWrite(ValueType:="", RootKeySubKey:="", ValueName:="", Value:="")
{
    RegWrite %ValueType%, %RootKeySubKey%, %ValueName%, %Value%
    return !ErrorLevel
}
Reload()
{
    Reload
}
Run(Target, WorkingDir:="", Options:="", ByRef OutputVarPID:="")
{
    Run %Target%, %WorkingDir%, %Options%, OutputVarPID
    if InStr(Options, "UseErrorLevel")
        return !ErrorLevel
}
RunAs(User:="", Password:="", Domain:="")
{
    RunAs %User%, %Password%, %Domain%
}
RunWait(Target, WorkingDir:="", Options:="", ByRef OutputVarPID:="")
{
    RunWait %Target%, %WorkingDir%, %Options%, OutputVarPID
    return ErrorLevel
}
Send(Keys)
{
    Send %Keys%
}
SendEvent(Keys)
{
    SendEvent %keys%
}
SendInput(Keys)
{
    SendInput %Keys%
}
SendLevel(Level)
{
    SendLevel %Level%
}
SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")
{
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    if (ErrorLevel = "FAIL")
        ErrorLevel := "ERROR"
}
SendMode(Mode)
{
    SendMode %Mode%
}
SendPlay(Keys)
{
    SendPlay %Keys%
}
SendRaw(Keys)
{
    SendRaw %Keys%
}
SetCapsLockState(State:="")
{
    SetCapsLockState %State%
}
SetControlDelay(Delay)
{
    SetControlDelay %Delay%
}
SetDefaultMouseSpeed(Speed)
{
    SetDefaultMouseSpeed %Speed%
}
SetKeyDelay(Delay:="", PressDuration:="", Play:="")
{
    SetKeyDelay %Delay%, %PressDuration%, %Play%
}
SetMouseDelay(Delay, Play:="")
{
    SetMouseDelay %Delay%, %Play%
}
SetNumLockState(State:="")
{
    SetNumLockState %State%
}
SetRegView(RegView)
{
    SetRegView %RegView%
}
SetScrollLockState(State:="")
{
    SetScrollLockState %State%
}
SetStoreCapslockMode(OnOrOff)
{
    SetStoreCapslockMode %OnOrOff%
}
SetTimer(Label:="", Period:="", Priority:=0)
{
    SetTimer %Label%, %Period%, %Priority%
}
SetTitleMatchMode(MatchModeOrSpeed)
{
    SetTitleMatchMode %MatchModeOrSpeed%
}
SetWinDelay(Delay)
{
    SetWinDelay %Delay%
}
SetWorkingDir(DirName)
{
    SetWorkingDir %DirName%
    return !ErrorLevel
}
Shutdown(Code)
{
    Shutdown %Code%
}
Sleep(DelayInMilliseconds)
{
    Sleep %DelayInMilliseconds%
}
Sort(String, Options:="")
{
    Sort String, %Options%
    return String
}
SoundBeep(Frequency:=523, Duration:=150)
{
    SoundBeep %Frequency%, %Duration%
}
SoundGet(ComponentType:="", ControlType:="", DeviceNumber:=1)
{
    local OutputVar
    SoundGet OutputVar, %ComponentType%, %ControlType%, %DeviceNumber%
    if !ErrorLevel
        return OutputVar
}
SoundPlay(Filename, Wait:="")
{
    SoundPlay %Filenam%, %Wait%
    return !ErrorLevel
}
SoundSet(NewSetting, ComponentType:="", ControlType:="", DeviceNumber:=1)
{
    SoundSet %NewSetting%, %ComponentType%, %ControlType%, %DeviceNumber%
    return !ErrorLevel
}
SplitPath(Path, ByRef OutFileName:="", ByRef OutDir:="", ByRef OutExtension:="", ByRef OutNameNoExt:="", ByRef OutDrive:="")
{
    SplitPath % Path, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
}
StatusBarGetText(PartNum:=1, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    StatusBarGetText OutputVar, %PartNum%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
StatusBarWait(BarText:="", Seconds:="", PartNum:=1, WinTitle:="", WinText:="", Interval:=50, ExcludeTitle:="", ExcludeText:="")
{
    StatusBarWait %BarText%, %Seconds%, %PartNum%, %WinTitle%, %WinText%, %Interval%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
StringCaseSense(OnOffLocale)
{
    StringCaseSense %OnOffLocale%
}
StrLower(String, T:="")
{
    local OutputVar
    StringLower OutputVar, %String%, %T%
    return OutputVar
}
StrUpper(String, T:="")
{
    local OutputVar
    StringUpper OutputVar, %String%, %T%
    return OutputVar
}
Suspend(Mode:="Toggle")
{
    Suspend %Mode%
}
SysGet(SubCommand)
{
    local OutputVar
    SysGet OutputVar, %SubCommand%
    return OutputVar
}
Thread(Param1, Param2:="", Param3:="")
{
    Thread %Param1%, %Param2%, %Param3%
}
ToolTip(Text:="", X:="", Y:="", WhichToolTip:=1)
{
    ToolTip %Text%, %X%, %Y%, %WhichToolTip%
}
TrayTip(Title:="", Text:="", Seconds:="", Options:=0)
{
    TrayTip, %Title%, %Text%, %Seconds%, %Options%
}
Type(Value)
{
    local m, f, e
    if IsObject(Value)
    {
        static nMatchObj  := NumGet(&(m, RegExMatch("", "O)", m)))
        static nBoundFunc := NumGet(&(f := Func("Func").Bind()))
        static nFileObj   := NumGet(&(f := FileOpen("*", "w")))
        static nEnumObj   := NumGet(&(e := ObjNewEnum({})))

        return ObjGetCapacity(Value) != ""  ? "Object"
             : IsFunc(Value)                ? "Func"
             : ComObjType(Value) != ""      ? "ComObject"
             : NumGet(&Value) == nBoundFunc ? "BoundFunc"
             : NumGet(&Value) == nMatchObj  ? "RegExMatchObject"
             : NumGet(&Value) == nFileObj   ? "FileObject"
             : NumGet(&Value) == nEnumObj   ? "Object::Enumerator"
             :                                "Property"
    }
    else if (ObjGetCapacity([Value]) != "")
        return "String"
    else
        return InStr(Value, ".") ? "Float" : "Integer"
}
WinActivate(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinActivate %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinActivateBottom(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinActivateBottom %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinClose(WinTitle:="", WinText:="", SecondsToWait:="", ExcludeTitle:="", ExcludeText:="")
{
    WinClose %WinTitle%, %WinText%, %SecondsToWait%, %ExcludeTitle%, %ExcludeText%
}
WinGetClass(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGetClass OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetControls(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ControlList, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return StrSplit(OutputVar, "`n")
}
WinGetControlsHwnd(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar, ControlsHwnd, i
    WinGet OutputVar, ControlListHwnd, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    ControlsHwnd := StrSplit(OutputVar, "`n")
    for i in ControlsHwnd
        ControlsHwnd[i] += 0
    return ControlsHwnd
}
WinGetCount(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, Count, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetExStyle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ExStyle, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar + 0
}
WinGetID(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar + 0
}
WinGetIDLast(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, IDLast, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar + 0
}
WinGetList(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar, List
    WinGet OutputVar, List, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    List := []
    Loop % OutputVar
        List.Push(OutputVar%A_Index% + 0)
    return List
}
WinGetMinMax(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, MinMax, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetPID(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, PID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinGetPos, X, Y, Width, Height, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinGetProcessName(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ProcessName, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetProcessPath(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ProcessPath, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetStyle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, Style, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar + 0
}
WinGetText(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGetText OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
WinGetTitle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGetTitle OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetTransColor(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, TransColor, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetTransparent(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, Transparent, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinHide(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinHide %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinKill(WinTitle:="", WinText:="", SecondsToWait:="", ExcludeTitle:="", ExcludeText:="")
{
    WinKill %WinTitle%, %WinText%, %SecondsToWait%, %ExcludeTitle%, %ExcludeText%
}
WinMaximize(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinMaximize %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMinimize(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinMinimize %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMinimizeAll()
{
    WinMinimizeAll
}
WinMinimizeAllUndo()
{
    WinMinimizeAllUndo
}
WinMove(Params*)
{
    local WinTitle, WinText, X, Y, Width, Height, ExcludeTitle, ExcludeText
    local Len
    if (Len := Params.Length())
    {
        if (Len > 2)
        {
            WinTitle     := Params[1]
            WinText      := Params[2]
            X            := Params[3]
            Y            := Params[4]
            Width        := Params[5]
            Height       := Params[6]
            ExcludeTitle := Params[7]
            ExcludeText  := Params[8]
            WinMove %WinTitle%, %WinText%, %X%, %Y%, %Width%, %Height%, %ExcludeTitle%, %ExcludeText%
        }
        else
        {
            X := Params[1]
            Y := Params[2]
            WinMove %X%, %y%
        }
    }
    else
        WinMove
}
WinMoveBottom(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Bottom,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMoveTop(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Top,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinRedraw(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Redraw,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinRestore(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinRestore %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinSetAlwaysOnTop(OnOffToggle:="Toggle", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    if OnOffToggle in 1,0,-1 ; On,Off,Toggle
        OnOffToggle := OnOffToggle == -1 ? "Toggle" : OnOffToggle ? "On" : "Off"

    if OnOffToggle not in On,Off,Toggle
        throw Exception("Parameter #1 invalid.", -1) ; v2 raises an error

    WinSet AlwaysOnTop, %OnOffToggle%, ahk_id %Hwnd%
    return 1
}
WinSetEnabled(Value, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    ; 1, 0 and -1 are compared as strings, non-integer values(e.g.: 1.0) are not allowed
    local Style
    if (Value = "Toggle" || value == "-1")
    {
        WinGet Style, Style, ahk_id %Hwnd%
        Value := (Style & 0x8000000) ? "On" : "Off" ; WS_DISABLED = 0x8000000
    }

    if (Value = "On" || Value == "1")
        WinSet Enable, ahk_id %Hwnd%
    else if (Value = "Off" || Value == "0")
        WinSet Disable, ahk_id %Hwnd%
    else
        throw Exception("Paramter #1 invalid.", -1) ; v2 raises an error
    return 1
}
WinSetExStyle(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet ExStyle, %N%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinSetRegion(Options:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Region, %Options%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinSetStyle(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Style, %N%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinSetTitle(Param:="", Params*)
{
    local WinTitle, WinText, NewTitle, ExcludeTitle, ExcludeText
    if (Params.Length())
    {
        WinTitle     := Param
        WinText      := Params[1]
        NewTitle     := Params[2]
        ExcludeTitle := Params[3]
        ExcludeText  := Params[4]
        WinSetTitle %WinTitle%, %WinText%, %NewTitle%, %ExcludeTitle%, %ExcludeText%
    }
    else
        WinSetTitle %Param% ; WinSetTitle, NewTitle
}
WinSetTransColor(ColorN, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    WinSet TransColor, %ColorN%, ahk_id %Hwnd%
    return 1
}
WinSetTransparent(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    WinSet Transparent, %N%, ahk_id %Hwnd%
    return 1
}
WinShow(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinShow %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinWait(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWait %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinWaitActive(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWaitActive %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinWaitClose(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWaitClose %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinWaitNotActive(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWaitNotActive %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
[EDIT:]
Amended versions of functions, *not* changed in the full list of functions above:
FileSetAttrib, FileSetTime, SoundPlay, StrLower, StrUpper, WinSetEnabled
[still require amending: MsgBox, TrayTip]

Code: Select all

FileSetAttrib(Attributes, FilePattern:="", Mode:="")
{
    FileSetAttrib %Attributes%, %FilePattern%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
    return !ErrorLevel
}
FileSetTime(YYYYMMDDHH24MISS:="", FilePattern:="", WhichTime:="M", Mode:="")
{
    FileSetTime %YYYYMMDDHH24MISS%, %FilePattern%, %WhichTime%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
    return !ErrorLevel
}
SoundPlay(Filename, Wait:="")
{
    SoundPlay %Filename%, %Wait%
    return !ErrorLevel
}
StrLower(String, T:="")
{
    local OutputVar
    StringLower OutputVar, String, %T%
    return OutputVar
}
StrUpper(String, T:="")
{
    local OutputVar
    StringUpper OutputVar, String, %T%
    return OutputVar
}
WinSetEnabled(Value, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    ; 1, 0 and -1 are compared as strings, non-integer values(e.g.: 1.0) are not allowed
    local Style
    if (Value = "Toggle" || value == "-1")
    {
        WinGet Style, Style, ahk_id %Hwnd%
        Value := (Style & 0x8000000) ? "On" : "Off" ; WS_DISABLED = 0x8000000
    }

    if (Value = "On" || Value == "1")
        WinSet Enable,, ahk_id %Hwnd%
    else if (Value = "Off" || Value == "0")
        WinSet Disable,, ahk_id %Hwnd%
    else
        throw Exception("Paramter #1 invalid.", -1) ; v2 raises an error
    return 1
}
Last edited by jeeswg on 01 Aug 2018, 15:01, edited 19 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: commands as functions (AHK v2 functions for AHK v1)

26 Mar 2017, 20:58

See Default/Portable installation StdLib in Wish List.
Note: FileInstall cannot be completely recreated as a function.
It can. You can retrieve the data with FindResource/LoadResource/LockResource.

HotKeyIt's version of the compiler handles the function syntax, although the compiler itself might require AutoHotkey_H v2. I haven't tested it.
Note: The Gui command would make any script that uses such a library #Persistent, so I would advise commenting out that function.
There is no need to comment it out if it is in its own file, as it is in Coco's project. The file structure in Coco's project allows the functions to be auto-included from the function library (and only those functions which are called).

Of course, the presence of Gui() will still cause the script to be persistent.

Anyway, the Gui() function is very unlikely to be retained in v2. See this topic.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

27 Mar 2017, 16:50

I just compared the syntax text from the current AHK v1 help htms v. the AHK v2 htms, in WinMerge.

[script to get syntax text from AutoHotkey.chm (decompiled) htms, or htms from GitHub:]
list of every command/function/variable from across all versions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 79#p130479

Btw, wow, hundreds of files in the Lib folder, one for each function, that would be mayhem, I thought that was just temporary, for diagnostic purposes. I currently have 44 scripts in my library, 22 by others, 22 by me.

I'm not sure if this addition to the Hotkey command will cause an issue:
Hotkey, If, % FunctionObject

Comparing the texts, I noticed that the Label parameter has been removed from GroupAdd, and that PixelGetColor/PixelSearch now use RGB by default. However, Coco's functions already address these issues. [EDIT:] FileSetAttrib and FileSetTime have replaced 2 parameters with 1 and so I've provided updated functions above.

Perhaps one should suggest that PixelGetColor/PixelSearch should have 'BGR' as an option for Param4. I.e. you notice the issue and so are compelled to mention it, [EDIT:] whether you feel strongly about it or not. It could well be useful to people, I know I've often had to deal with both RGB and BGR. It might be the best option to allow AHK v2, or both AHK v1 and v2 to accept both RGB and BGR in Param4.

It's changes that affect *existing* commands/functions, that keep their name, that are the most confusing. It is difficult to find the best way to present all the AHK v2 changes, perhaps there should be an alphabetical list of all commands/functions/directives/variables mentioning any changes for AHK v2, with a separate bit on syntax and any other changes. I might take some steps towards this in coming weeks.

Ultimately I hope to create the documentation and converter scripts that will make the transition realistic for the average (and expert) user. My list of 17 issues regarding AHK v2, and comments on identifying continuation sections (prior to converting individual lines) are a good start for anyone interested in the meantime.

[docs for v1]
GitHub - Lexikos/AutoHotkey_L-Docs: Documentation for AutoHotkey
https://github.com/Lexikos/AutoHotkey_L-Docs

Code: Select all

syntax text from htm files for AutoHotkey v1.1.25.01
==================================================
FileRead, OutputVar, *Pnnn Filename
FileAppend [, Text, Filename, Encoding]
==================================================
Method syntax:
class ClassName {
    __Get([Key, Key2, ...])
    __Set([Key, Key2, ...], Value)
    __Call(Name [, Params...])
}

Function syntax:
MyGet(this [, Key, Key2, ...])
MySet(this [, Key, Key2, ...], Value)
MyCall(this, Name [, Params...])

ClassName := { __Get: Func("MyGet"), __Set: Func("MySet"), __Call: Func("MyCall") }
==================================================
AutoHotkey.exe /Debug[=SERVER:PORT] ...
==================================================
Number := Asc(String)
==================================================
AutoTrim, On|Off
==================================================
{
zero or more commands
}
==================================================
BlockInput, Mode
==================================================
Break [, LoopLabel]
==================================================
String := Chr(Number)
==================================================
ClipWait [, SecondsToWait, 1]
==================================================
ComObject := ComObjActive(CLSID)
ParamObj := ComObject(VarType, Value [, Flags])
ParamObj := ComObjMissing()
ComObject := ComObjEnwrap(DispPtr)
DispPtr := ComObjUnwrap(ComObject)
==================================================
ArrayObj := ComObjArray(VarType, Count1 [, Count2, ... Count8])
==================================================
ComObjConnect(ComObject [, Prefix])
==================================================
ComObject := ComObjCreate(CLSID [, IID])
==================================================
Enabled := ComObjError([Enable])
==================================================
Flags := ComObjFlags(ComObject [, NewFlags, Mask])
==================================================
ComObject := ComObjGet(Name)
==================================================
InterfacePointer := ComObjQuery(ComObject, [SID,] IID)
==================================================
VarType := ComObjType(ComObject)
Name    := ComObjType(ComObject, "Name")
IID     := ComObjType(ComObject, "IID")
==================================================
Value := ComObjValue(ComObject)
==================================================
Continue [, LoopLabel]
==================================================
Control, Cmd [, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlClick [, Control-or-Pos, WinTitle, WinText, WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText]
==================================================
ControlFocus [, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlGet, OutputVar, Cmd [, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlGetFocus, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlGetPos [, X, Y, Width, Height, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlGetText, OutputVar [, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlMove, Control, X, Y, Width, Height [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
ControlSendRaw: Same parameters as above.
==================================================
ControlSetText [, Control, NewText, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
CoordMode, ToolTip|Pixel|Mouse|Caret|Menu [, Screen|Window|Client]
==================================================
Critical [, Off]
Critical 50 ; See bottom of remarks.
==================================================
DetectHiddenText, On|Off
==================================================
DetectHiddenWindows, On|Off
==================================================
Result := DllCall("[DllFile\]Function" [, Type1, Arg1, Type2, Arg2, "Cdecl ReturnType"])
==================================================
Drive, Sub-command [, Drive , Value]
==================================================
DriveGet, OutputVar, Cmd [, Value]
==================================================
DriveSpaceFree, OutputVar, Path
==================================================
Edit
==================================================
Else
==================================================
EnvAdd, Var, Value [, TimeUnits]
Var += Value [, TimeUnits]
Var++
==================================================
EnvDiv, Var, Value
==================================================
EnvGet, OutputVar, EnvVarName
==================================================
EnvMult, Var, Value
==================================================
EnvSet, EnvVar, Value
==================================================
EnvSub, Var, Value [, TimeUnits]
Var -= Value [, TimeUnits]
Var--
==================================================
EnvUpdate
==================================================
Exit [, ExitCode]
==================================================
ExitApp [, ExitCode]
==================================================
FileAppend [, Text, Filename, Encoding]
==================================================
FileCopy, SourcePattern, DestPattern [, Flag]
==================================================
FileCopyDir, Source, Dest [, Flag]
==================================================
FileCreateDir, DirName
==================================================
FileCreateShortcut, Target, LinkFile [, WorkingDir, Args, Description, IconFile, ShortcutKey, IconNumber, RunState]
==================================================
FileDelete, FilePattern
==================================================
FileEncoding [, Encoding]
==================================================
AttributeString := FileExist(FilePattern)
==================================================
FileGetAttrib, OutputVar [, Filename]
AttributeString := FileExist(FilePattern)
==================================================
FileGetShortcut, LinkFile [, OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState]
==================================================
FileGetSize, OutputVar [, Filename, Units]
==================================================
FileGetTime, OutputVar [, Filename, WhichTime]
==================================================
FileGetVersion, OutputVar [, Filename]
==================================================
FileInstall, Source, Dest [, Flag]
==================================================
FileMove, SourcePattern, DestPattern [, Flag]
==================================================
FileMoveDir, Source, Dest [, Flag]
==================================================
file := FileOpen(Filename, Flags [, Encoding])
==================================================
FileRead, OutputVar, Filename
==================================================
FileReadLine, OutputVar, Filename, LineNum
==================================================
FileRecycle, FilePattern
==================================================
FileRecycleEmpty [, DriveLetter]
==================================================
FileRemoveDir, DirName [, Recurse?]
==================================================
FileSelectFile, OutputVar [, Options, RootDir\Filename, Prompt, Filter]
==================================================
FileSelectFolder, OutputVar [, StartingFolder, Options, Prompt]
==================================================
FileSetAttrib, Attributes [, FilePattern, OperateOnFolders?, Recurse?]
==================================================
FileSetTime [, YYYYMMDDHH24MISS, FilePattern, WhichTime, OperateOnFolders?, Recurse?]
==================================================
Finally Statement
==================================================
For Key [, Value] in Expression
==================================================
String := Format(FormatStr [, Values...])
Flags Width .Precision ULT Type
==================================================
FormatTime, OutputVar [, YYYYMMDDHH24MISS, Format]
==================================================
FunctionReference := Func(FunctionName)
==================================================
String := GetKeyName(Key)
Number := GetKeyVK(Key)
Number := GetKeySC(Key)
==================================================
GetKeyState, OutputVar, KeyName [, Mode]
KeyIsDown := GetKeyState("KeyName" [, "Mode"])
==================================================
Gosub, Label
==================================================
Goto, Label
==================================================
GroupActivate, GroupName [, R]
==================================================
GroupAdd, GroupName [, WinTitle, WinText, Label, ExcludeTitle, ExcludeText]
==================================================
GroupClose, GroupName [, A|R]
==================================================
GroupDeactivate, GroupName [, R]
==================================================
Gui, sub-command [, Param2, Param3, Param4]
CtrlEvent(CtrlHwnd, GuiEvent, EventInfo, ErrorLevel:="")
GuiSize(GuiHwnd, EventInfo, Width, Height)
GuiContextMenu(GuiHwnd, CtrlHwnd, EventInfo, IsRightClick, X, Y)
==================================================
GuiControl, Sub-command, ControlID [, Param3]
==================================================
GuiControlGet, OutputVar [, Sub-command, ControlID, Param4]
==================================================
Hotkey, KeyName [, Label, Options]
Hotkey, IfWinActive/Exist [, WinTitle, WinText]
Hotkey, If [, Expression]
Hotkey, If, % FunctionObject
==================================================
if Var between LowerBound and UpperBound
if Var not between LowerBound and UpperBound
==================================================
IfEqual, var, value (same: if var = value)
IfNotEqual, var, value (same: if var <> value) (!= can be used in place of <>)
IfGreater, var, value (same: if var > value)
IfGreaterOrEqual, var, value (same: if var >= value)
IfLess, var, value (same: if var < value)
IfLessOrEqual, var, value (same: if var <= value)
If var ; If var's contents are blank or 0, it is considered false. Otherwise, it is true.

See also: IfInString
==================================================
IfExist, FilePattern
IfNotExist, FilePattern
AttributeString := FileExist(FilePattern)
==================================================
if (expression)
==================================================
if Var in MatchList
if Var not in MatchList

if Var contains MatchList
if Var not contains MatchList
==================================================
IfInString, var, SearchString
IfNotInString, var, SearchString
Position := InStr(Haystack, Needle [, CaseSensitive?, StartingPos]]) ; See the InStr() function for details.
==================================================
if var is type
if var is not type
==================================================
IfMsgBox, ButtonName
==================================================
ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile
==================================================
IniDelete, Filename, Section [, Key]
==================================================
IniRead, OutputVar, Filename, Section, Key [, Default]
IniRead, OutputVarSection, Filename, Section
IniRead, OutputVarSectionNames, Filename
==================================================
IniWrite, Value, Filename, Section, Key
IniWrite, Pairs, Filename, Section
==================================================
Input [, OutputVar, Options, EndKeys, MatchList]
==================================================
InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
==================================================
FoundPos := InStr(Haystack, Needle [, CaseSensitive = false, StartingPos = 1, Occurrence = 1])
==================================================
TrueOrFalse := IsByRef(UnquotedVarName)
==================================================
MinParamsPlus1 := IsFunc(FunctionName)
==================================================
TrueOrFalse := IsLabel(LabelName)
==================================================
TrueOrFalse := IsObject(ObjectValue)
==================================================
KeyHistory
==================================================
KeyWait, KeyName [, Options]
==================================================
ListHotkeys
==================================================
ListLines [, On|Off]
==================================================
ListVars
==================================================
Handle := LoadPicture(Filename [, Options, ByRef ImageType])
==================================================
Loop [, Count]
==================================================
Loop, Files, FilePattern [, Mode]  ; v1.1.21+ (recommended)
Loop, FilePattern [, IncludeFolders?, Recurse?]
==================================================
Loop, Parse, InputVar [, Delimiters, OmitChars]
==================================================
Loop, Read, InputFile [, OutputFile]
==================================================
Loop, Reg, RootKey[\Key, Mode]  ; v1.1.21+ (recommended)
Loop, RootKey [, Key, IncludeSubkeys?, Recurse?]
==================================================
Value := Abs(Number)
Value := Ceil(Number)
Value := Exp(N)
Value := Floor(Number)
Value := Log(Number)
Value := Ln(Number)
Value := Mod(Dividend, Divisor)
Value := Round(Number [, N])
Value := Sqrt(Number)
Value := Sin(Number)
Value := Cos(Number)
Value := Tan(Number)
Value := ASin(Number)
Value := ACos(Number)
Value := ATan(Number)
==================================================
Menu, MenuName, Cmd [, P3, P4, P5]
FunctionName(ItemName, ItemPos, MenuName)
==================================================
Handle := MenuGetHandle(MenuName)
==================================================
MenuName := MenuGetName(Handle)
==================================================
MouseClick [, WhichButton , X, Y, ClickCount, Speed, D|U, R]
==================================================
MouseClickDrag, WhichButton, X1, Y1, X2, Y2 [, Speed, R]
==================================================
MouseGetPos, [OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 1|2|3]
==================================================
MouseMove, X, Y [, Speed, R]
==================================================
MsgBox, Text
MsgBox [, Options, Title, Text, Timeout]
==================================================
Number := NumGet(VarOrAddress [, Offset = 0][, Type = "UPtr"])
==================================================
NumPut(Number, VarOrAddress [, Offset = 0][, Type = "UPtr"])
==================================================
ObjAddRef(Ptr)
ObjRelease(Ptr)
==================================================
BoundFunc := ObjBindMethod(Obj, Method, Params)
==================================================
OnClipboardChange(Func [, AddRemove])
FunctionName(Type)
==================================================
OnExit [, Label]
OnExit(Func [, AddRemove])  ; Requires [v1.1.20+]
ExitFunc(ExitReason, ExitCode)
==================================================
OnMessage(MsgNumber [, Function, MaxThreads])
Name := OnMessage(MsgNumber, "FunctionName")
Name := OnMessage(MsgNumber, "")
Name := OnMessage(MsgNumber)

OnMessage(MsgNumber, FuncObj)     ; Option 1
OnMessage(MsgNumber, FuncObj, 1)  ; Option 2 (MaxThreads = 1)

OnMessage(MsgNumber, FuncObj, -1)
OnMessage(MsgNumber, FuncObj, 0)
==================================================
Number := Ord(String)
==================================================
OutputDebug, Text
==================================================
#p::Pause ; Pressing Win+P once will pause the script. Pressing it again will unpause.
Pause [, On|Off|Toggle, OperateOnUnderlyingThread?]
==================================================
PixelGetColor, OutputVar, X, Y [, Alt|Slow|RGB]
==================================================
PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID [, Variation, Fast|RGB]
==================================================
PostMessage, Msg [, wParam, lParam, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
SendMessage, Msg [, wParam, lParam, Control, WinTitle, WinText, ExcludeTitle, ExcludeText, Timeout]
==================================================
Process, Cmd [, PID-or-Name, Param3]
==================================================
SplashImage, Off
SplashImage [, ImageFile, Options, SubText, MainText, WinTitle, FontName]

Progress, Off
Progress, ProgressParam1 [, SubText, MainText, WinTitle, FontName]
==================================================
Random, OutputVar [, Min, Max]
Random, , NewSeed
==================================================
RegDelete, RootKey\SubKey [, ValueName]  ; v1.1.21+
RegDelete, RootKey, SubKey [, ValueName]
==================================================
FoundPos := RegExMatch(Haystack, NeedleRegEx [, UnquotedOutputVar = "", StartingPosition = 1])
==================================================
NewStr := RegExReplace(Haystack, NeedleRegEx [, Replacement = "", OutputVarCount = "", Limit = -1, StartingPosition = 1])
==================================================
Address := RegisterCallback("FunctionName" [, Options = "", ParamCount = FormalCount, EventInfo = Address])
==================================================
RegRead, OutputVar, RootKey\SubKey [, ValueName]  ; v1.1.21+
RegRead, OutputVar, RootKey, SubKey [, ValueName]
==================================================
RegWrite, ValueType, RootKey\SubKey [, ValueName, Value]  ; v1.1.21+
RegWrite, ValueType, RootKey, SubKey [, ValueName, Value]
==================================================
Reload
==================================================
Return [, Expression]
==================================================
Run, Target [, WorkingDir, Max|Min|Hide|UseErrorLevel, OutputVarPID]
RunWait, Target [, WorkingDir, Max|Min|Hide|UseErrorLevel, OutputVarPID]
==================================================
RunAs [, User, Password, Domain]
==================================================
Send Keys
SendRaw Keys
SendInput Keys
SendPlay Keys
SendEvent Keys
==================================================
SendLevel, Level
==================================================
SendMode Input|Play|Event|InputThenPlay
==================================================
SetBatchLines, 20ms
SetBatchLines, LineCount
==================================================
SetControlDelay, Delay
==================================================
SetDefaultMouseSpeed, Speed
==================================================
SetEnv, Var, Value
Var = Value
==================================================
Var := expression
==================================================
SetFormat, NumberType, Format
==================================================
SetKeyDelay [, Delay, PressDuration, Play]
==================================================
SetMouseDelay, Delay [, Play]
==================================================
SetCapsLockState [, State]
SetNumLockState [, State]
SetScrollLockState [, State]
==================================================
SetRegView, RegView
==================================================
SetStoreCapslockMode, On|Off
==================================================
SetTimer [, Label, Period|On|Off|Delete, Priority]
==================================================
SetTitleMatchMode, MatchMode
SetTitleMatchMode, Fast|Slow
==================================================
SetWinDelay, Delay
==================================================
SetWorkingDir, DirName
==================================================
Shutdown, Code
==================================================
Sleep, DelayInMilliseconds
==================================================
Sort, VarName [, Options]
==================================================
SoundBeep [, Frequency, Duration]
==================================================
SoundGet, OutputVar [, ComponentType, ControlType, DeviceNumber]
==================================================
SoundGetWaveVolume, OutputVar [, DeviceNumber]
==================================================
SoundPlay, Filename [, wait]
==================================================
SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]
==================================================
SoundSetWaveVolume, Percent [, DeviceNumber]
==================================================
SplashTextOff
SplashTextOn [, Width, Height, Title, Text]
==================================================
SplitPath, InputVar [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive]
==================================================
StatusBarGetText, OutputVar [, Part#, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
StatusBarWait [, BarText, Seconds, Part#, WinTitle, WinText, Interval, ExcludeTitle, ExcludeText]
==================================================
StringCaseSense, On|Off|Locale
==================================================
StringGetPos, OutputVar, InputVar, SearchText [, L#|R#, Offset]
Position := InStr(Haystack, Needle [, CaseSensitive?, StartingPos]) ; See the InStr() function for details.
==================================================
StringLeft, OutputVar, InputVar, Count
StringRight, OutputVar, InputVar, Count
NewStr := SubStr(String, StartPos [, Length]) ; See the SubStr() function for details.
==================================================
OutputVar := StrLen(InputVar)
StringLen, OutputVar, InputVar
==================================================
StringLower, OutputVar, InputVar [, T]
StringUpper, OutputVar, InputVar [, T]
==================================================
StringMid, OutputVar, InputVar, StartChar [, Count , L]
NewStr := SubStr(String, StartPos [, Length]) ; See the SubStr() function for details.
==================================================
OutputVar := StrReplace(Haystack, SearchText [, ReplaceText, OutputVarCount, Limit := -1])  ; v1.1.21+
StringReplace, OutputVar, InputVar, SearchText [, ReplaceText, ReplaceAll?]
==================================================
StringSplit, OutputArray, InputVar [, Delimiters, OmitChars]
Array := StrSplit(String [, Delimiters, OmitChars])  ; [v1.1.13+]
==================================================
StringTrimLeft, OutputVar, InputVar, Count
StringTrimRight, OutputVar, InputVar, Count
NewStr := SubStr(String, StartPos [, Length]) ; See the SubStr() function for details.
==================================================
StrPut(String [, Encoding = None ] )
StrPut(String, Address [, Length] [, Encoding = None ] )
StrGet(Address [, Length] [, Encoding = None ] )
==================================================
NewStr := SubStr(String, StartingPos [, Length])
==================================================
Suspend [, Mode]
==================================================
SysGet, OutputVar, Sub-command [, Param3]
==================================================
Thread, NoTimers [, false]
Thread, Priority, n
Thread, Interrupt [, Duration, LineCount]
==================================================
Throw [, Expression]
==================================================
ToolTip [, Text, X, Y, WhichToolTip]
==================================================
Transform, OutputVar, Cmd, Value1 [, Value2]
==================================================
TrayTip [, Title, Text, Seconds, Options]
==================================================
Result :=  Trim(String, OmitChars = " `t")
Result := LTrim(String, OmitChars = " `t")
Result := RTrim(String, OmitChars = " `t")
==================================================
Try Statement
==================================================
Loop {
    ...
} Until Expression
==================================================
UrlDownloadToFile, URL, Filename
==================================================
GrantedCapacity := VarSetCapacity(UnquotedVarName [, RequestedCapacity, FillByte])
==================================================
While Expression
While(Expression)
==================================================
WinActivate [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinActivateBottom [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
IfWinActive [, WinTitle, WinText,  ExcludeTitle, ExcludeText]
IfWinNotActive [, WinTitle, WinText, ExcludeTitle, ExcludeText]
UniqueID := WinActive("WinTitle", "WinText", "ExcludeTitle", "ExcludeText")
==================================================
WinClose [, WinTitle, WinText, SecondsToWait, ExcludeTitle, ExcludeText]
==================================================
IfWinExist [, WinTitle, WinText,  ExcludeTitle, ExcludeText]
IfWinNotExist [, WinTitle, WinText, ExcludeTitle, ExcludeText]
UniqueID := WinExist("WinTitle", "WinText", "ExcludeTitle", "ExcludeText")
==================================================
WinGet, OutputVar [, Cmd, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinGetActiveStats, Title, Width, Height, X, Y
==================================================
WinGetActiveTitle, OutputVar
==================================================
WinGetClass, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinGetPos [, X, Y, Width, Height, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinGetText, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinGetTitle, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinHide [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinKill [, WinTitle, WinText, SecondsToWait, ExcludeTitle, ExcludeText]
==================================================
WinMaximize [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinMenuSelectItem, WinTitle, WinText, Menu [, SubMenu1, SubMenu2, SubMenu3, SubMenu4, SubMenu5, SubMenu6, ExcludeTitle, ExcludeText]
==================================================
WinMinimize [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinMinimizeAll
WinMinimizeAllUndo
==================================================
WinMove, X, Y
WinMove, WinTitle, WinText, X, Y [, Width, Height, ExcludeTitle, ExcludeText]
==================================================
WinRestore [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinSet, Attribute, Value [, WinTitle, WinText,  ExcludeTitle, ExcludeText]
==================================================
WinSetTitle, NewTitle
WinSetTitle, WinTitle, WinText, NewTitle [, ExcludeTitle, ExcludeText]
==================================================
WinShow [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinWait [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
==================================================
WinWaitActive [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
WinWaitNotActive [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
==================================================
WinWaitClose [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
==================================================
#AllowSameLineComments
==================================================
#ClipboardTimeout Milliseconds
==================================================
#CommentFlag NewString
==================================================
#ErrorStdOut
==================================================
#EscapeChar NewChar
==================================================
#HotkeyInterval Milliseconds
==================================================
#HotkeyModifierTimeout Milliseconds
==================================================
#Hotstring NoMouse
#Hotstring EndChars NewChars
#Hotstring NewOptions
==================================================
#If [, Expression ]
==================================================
#IfTimeout Timeout
==================================================
#IfWinActive [, WinTitle, WinText]
#IfWinExist [, WinTitle, WinText]
#IfWinNotActive [, WinTitle, WinText]
#IfWinNotExist [, WinTitle, WinText]
#If [, Expression]
==================================================
#Include FileOrDirName
#Include <LibName>
#IncludeAgain FileOrDirName
==================================================
#InputLevel [, Level]
==================================================
#InstallKeybdHook
==================================================
#InstallMouseHook
==================================================
#KeyHistory MaxEvents
==================================================
#MaxHotkeysPerInterval Value
==================================================
#MaxMem Megabytes
==================================================
#MaxThreads Value
==================================================
#MaxThreadsBuffer On|Off
==================================================
#MaxThreadsPerHotkey Value
==================================================
#MenuMaskKey KeyName
==================================================
#NoEnv
==================================================
#NoTrayIcon
==================================================
#Persistent
==================================================
#SingleInstance [force|ignore|off]
==================================================
#UseHook [On|Off]
==================================================
#Warn [, WarningType, WarningMode]
==================================================
#WinActivateForce
==================================================
HBITMAP:bitmap-handle
HICON:icon-handle
==================================================
LabelName:
==================================================
Function(Match, CalloutNumber, FoundPos, Haystack, NeedleRegEx)
{
    ...
}
==================================================
Enum.Next(OutputVar1 [, OutputVar2, ...])
==================================================
String := File.Read([Characters])
File.Write(String)
Line := File.ReadLine()
File.WriteLine([String])
Num := File.ReadNumType()
File.WriteNumType(Num)
File.RawRead(VarOrAddress, Bytes)
File.RawWrite(VarOrAddress, Bytes)
File.Seek(Distance [, Origin = 0])
File.Position := Distance
File.Pos := Distance
Pos := File.Tell()
Pos := File.Position
Pos := File.Pos
FileSize := File.Length
File.Length := NewSize
IsAtEOF := File.AtEOF
File.Close()
Encoding := File.Encoding
File.Encoding := Encoding
File.__Handle
==================================================
Func.Call(Parameters)  ; v1.1.19+
Func.(Parameters)  ; Old form - deprecated
BoundFunc := Func.Bind(Parameters)
Func.Name
Func.IsBuiltIn
Func.IsVariadic
Func.MinParams
Func.MaxParams
Func.IsByRef(ParamIndex)
Func.IsOptional(ParamIndex)
==================================================
Object.InsertAt(Pos, Value1 [, Value2, ... ValueN])
Object.RemoveAt(Pos [, Length])
Object.Push([ Value, Value2, ..., ValueN ])
Value := Object.Pop()
MinIndex := Object.MinIndex()
MaxIndex := Object.MaxIndex()
Length := Object.Length()
Object.SetCapacity(MaxItems)
Object.SetCapacity(Key, ByteSize)
MaxItems := Object.GetCapacity()
ByteSize := Object.GetCapacity(Key)
Ptr := Object.GetAddress(Key)
Enum := Object._NewEnum()
Object.HasKey(Key)
Clone := Object.Clone()
ObjRawSet(Object, Key, Value)
Object.Insert(Pos, Value1 [, Value2, ... ValueN ])
Object.Insert(Value)
Object.Insert(StringOrObjectKey, Value)
Object.Remove(FirstKey, LastKey)
==================================================
[docs for v2]
GitHub - Lexikos/AutoHotkey_L-Docs at v2
https://github.com/Lexikos/AutoHotkey_L-Docs/tree/v2

Code: Select all

syntax text from htm files for AutoHotkey v2.0-a078-e25d96b
==================================================
Method syntax:
class ClassName {
    __Get([Key, Key2, ...])
    __Set([Key, Key2, ...], Value)
    __Call(Name [, Params...])
}

Function syntax:
MyGet(this [, Key, Key2, ...])
MySet(this [, Key, Key2, ...], Value)
MyCall(this, Name [, Params...])

ClassName := { __Get: Func("MyGet"), __Set: Func("MySet"), __Call: Func("MyCall") }
==================================================
AutoHotkey.exe /Debug[=SERVER:PORT] ...
==================================================
{
zero or more commands
}
==================================================
BlockInput, Mode
==================================================
Break [, LoopLabel]
==================================================
String := Chr(Number)
==================================================
ClipWait [, SecondsToWait, 1]
==================================================
ComObject := ComObjActive(CLSID)
==================================================
ArrayObj := ComObjArray(VarType, Count1 [, Count2, ... Count8])
==================================================
ComObjConnect(ComObject [, Prefix])
==================================================
ComObject := ComObjCreate(CLSID [, IID])
==================================================
ComObject := ComObject(VarType, Value [, Flags])
ComObject := ComObject(DispPtr)
==================================================
Enabled := ComObjError([Enable])
==================================================
Flags := ComObjFlags(ComObject [, NewFlags, Mask])
==================================================
ComObject := ComObjGet(Name)
==================================================
InterfacePointer := ComObjQuery(ComObject, [SID,] IID)
==================================================
VarType := ComObjType(ComObject)
Name    := ComObjType(ComObject, "Name")
IID     := ComObjType(ComObject, "IID")
==================================================
Value := ComObjValue(ComObject)
==================================================
Continue [, LoopLabel]
==================================================
Control, Cmd [, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlClick [, Control-or-Pos, WinTitle, WinText, WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText]
==================================================
ControlFocus [, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlGet, OutputVar, Cmd [, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlGetFocus, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlGetPos [, X, Y, Width, Height, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlGetText, OutputVar [, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlMove, Control, X, Y, Width, Height [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
ControlSendRaw: Same parameters as above.
==================================================
ControlSetText [, Control, NewText, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
CoordMode, ToolTip|Pixel|Mouse|Caret|Menu [, Screen|Window|Client]
==================================================
Critical [, Off]
Critical 50 ; See bottom of remarks.
==================================================
OutputVar := DateAdd(DateTime, Time, TimeUnits)
==================================================
OutputVar := DateDiff(DateTime1, DateTime2, TimeUnits)
==================================================
Deref, OutputVar, String
==================================================
DetectHiddenText, On|Off
==================================================
DetectHiddenWindows, On|Off
==================================================
DirCopy, Source, Dest [, Flag]
==================================================
DirCreate, DirName
==================================================
DirDelete, DirName [, Recurse?]
==================================================
DirMove, Source, Dest [, Flag]
==================================================
DirSelect, OutputVar [, StartingFolder, Options, Prompt]
==================================================
Result := DllCall("[DllFile\]Function" [, Type1, Arg1, Type2, Arg2, "Cdecl ReturnType"])
==================================================
Download, URL, Filename
==================================================
Drive, Sub-command [, Drive , Value]
==================================================
DriveGet, OutputVar, Cmd [, Value]
==================================================
Edit
==================================================
Else
==================================================
EnvGet, OutputVar, EnvVarName
==================================================
EnvSet, EnvVar, Value
==================================================
Exit [, ExitCode]
==================================================
ExitApp [, ExitCode]
==================================================
FileAppend [, Text, Filename, Encoding]
==================================================
FileCopy, SourcePattern, DestPattern [, Flag]
==================================================
FileCreateShortcut, Target, LinkFile [, WorkingDir, Args, Description, IconFile, ShortcutKey, IconNumber, RunState]
==================================================
FileDelete, FilePattern
==================================================
FileEncoding [, Encoding]
==================================================
AttributeString := FileExist(FilePattern)
==================================================
FileGetAttrib, OutputVar [, Filename]
AttributeString := FileExist(FilePattern)
==================================================
FileGetShortcut, LinkFile [, OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState]
==================================================
FileGetSize, OutputVar [, Filename, Units]
==================================================
FileGetTime, OutputVar [, Filename, WhichTime]
==================================================
FileGetVersion, OutputVar [, Filename]
==================================================
FileInstall, Source, Dest [, Flag]
==================================================
FileMove, SourcePattern, DestPattern [, Flag]
==================================================
file := FileOpen(Filename, Flags [, Encoding])
==================================================
FileRead, OutputVar, Filename
==================================================
FileRecycle, FilePattern
==================================================
FileRecycleEmpty [, DriveLetter]
==================================================
FileSelect, OutputVar [, Options, RootDir\Filename, Prompt, Filter]
==================================================
FileSetAttrib, Attributes [, FilePattern, Mode]
==================================================
FileSetTime [, YYYYMMDDHH24MISS, FilePattern, WhichTime, Mode]
==================================================
Finally Statement
==================================================
For Key [, Value] in Expression
==================================================
String := Format(FormatStr [, Values...])
Flags Width .Precision ULT Type
==================================================
FormatTime, OutputVar [, YYYYMMDDHH24MISS, Format]
==================================================
FunctionReference := Func(FunctionName)
==================================================
String := GetKeyName(Key)
Number := GetKeyVK(Key)
Number := GetKeySC(Key)
==================================================
GetKeyState, OutputVar, KeyName [, Mode]
OutputVar := GetKeyState("KeyName" [, "Mode"])
==================================================
Gosub, Label
==================================================
Goto, Label
==================================================
GroupActivate, GroupName [, R]
==================================================
GroupAdd, GroupName [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
GroupClose, GroupName [, A|R]
==================================================
GroupDeactivate, GroupName [, R]
==================================================
Gui, sub-command [, Param2, Param3, Param4]
CtrlEvent(CtrlHwnd, GuiEvent, EventInfo, ErrorLevel:="")
GuiSize(GuiHwnd, EventInfo, Width, Height)
GuiContextMenu(GuiHwnd, CtrlHwnd, EventInfo, IsRightClick, X, Y)
==================================================
GuiControl, Sub-command, ControlID [, Param3]
==================================================
GuiControlGet, OutputVar [, Sub-command, ControlID, Param4]
==================================================
Hotkey, KeyName [, Label, Options]
Hotkey, IfWinActive/Exist [, WinTitle, WinText]
Hotkey, If [, Expression]
Hotkey, If, % FunctionObject
==================================================
if (expression)
==================================================
ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile
==================================================
IniDelete, Filename, Section [, Key]
==================================================
IniRead, OutputVar, Filename, Section, Key [, Default]
IniRead, OutputVarSection, Filename, Section
IniRead, OutputVarSectionNames, Filename
==================================================
IniWrite, Value, Filename, Section, Key
IniWrite, Pairs, Filename, Section
==================================================
Input [, OutputVar, Options, EndKeys, MatchList]
==================================================
InputBox, OutputVar [, Text, Title, Options, Default]
==================================================
FoundPos := InStr(Haystack, Needle [, CaseSensitive = false, StartingPos = 1, Occurrence = 1])
==================================================
if Value is Type
if !(Value is Type)
==================================================
TrueOrFalse := IsByRef(UnquotedVarName)
==================================================
MinParamsPlus1 := IsFunc(FunctionName)
==================================================
TrueOrFalse := IsLabel(LabelName)
==================================================
TrueOrFalse := IsObject(ObjectValue)
==================================================
KeyHistory
==================================================
KeyWait, KeyName [, Options]
==================================================
ListHotkeys
==================================================
ListLines [, On|Off]
==================================================
ListVars
==================================================
Handle := LoadPicture(Filename [, Options, ByRef ImageType])
==================================================
Loop [, Count]
Loop(Count)
==================================================
Loop, Files, FilePattern [, Mode]
LoopFiles(FilePattern [, Mode])
==================================================
Loop, Parse, String [, Delimiters, OmitChars]
LoopParse(String [, Delimiters, OmitChars])
==================================================
Loop, Read, InputFile [, OutputFile]
LoopRead(InputFile [, OutputFile])
==================================================
Loop, Reg, KeyName [, Mode]
LoopReg(KeyName [, Mode])
==================================================
Value := Abs(Number)
Value := Ceil(Number)
Value := Exp(N)
Value := Floor(Number)
Value := Log(Number)
Value := Ln(Number)
Value := Mod(Dividend, Divisor)
Value := Round(Number [, N])
Value := Sqrt(Number)
Value := Sin(Number)
Value := Cos(Number)
Value := Tan(Number)
Value := ASin(Number)
Value := ACos(Number)
Value := ATan(Number)
==================================================
Menu, MenuName, Cmd [, P3, P4, P5]
FunctionName(ItemName, ItemPos, MenuName)
==================================================
Handle := MenuGetHandle(MenuName)
==================================================
MenuName := MenuGetName(Handle)
==================================================
MenuSelect, WinTitle, WinText, Menu [, SubMenu1, SubMenu2, SubMenu3, SubMenu4, SubMenu5, SubMenu6, ExcludeTitle, ExcludeText]
==================================================
Exists  := MonitorGet([N, Left, Top, Right, Bottom])
Exists  := MonitorGetWorkArea([N, Left, Top, Right, Bottom])
Count   := MonitorGetCount()
Primary := MonitorGetPrimary()
Name    := MonitorGetName([N])

MonitorGet [, N, Left, Top, Right, Bottom]
MonitorGetWorkArea [, N, Left, Top, Right, Bottom]
MonitorGetCount, Count
MonitorGetPrimary, Primary
MonitorGetName, Name [, N]
==================================================
MouseClick [, WhichButton , X, Y, ClickCount, Speed, D|U, R]
==================================================
MouseClickDrag, WhichButton, X1, Y1, X2, Y2 [, Speed, R]
==================================================
MouseGetPos, [OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 1|2|3]
==================================================
MouseMove, X, Y [, Speed, R]
==================================================
MsgBox [, Text, Title, Options, OutputVar]
Result := MsgBox([Text, Title, Options, ByRef OutputVar])
==================================================
Number := NumGet(VarOrAddress [, Offset = 0][, Type = "UPtr"])
==================================================
NumPut(Number, VarOrAddress [, Offset = 0][, Type = "UPtr"])
==================================================
ObjAddRef(Ptr)
ObjRelease(Ptr)
==================================================
BoundFunc := ObjBindMethod(Obj, Method, Params)
==================================================
OnClipboardChange(Func [, AddRemove])
FunctionName(Type)
==================================================
OnExit(Func [, AddRemove])
ExitFunc(ExitReason, ExitCode)
==================================================
OnMessage(MsgNumber [, Function, MaxThreads])

OnMessage(MsgNumber, Function)     ; Option 1
OnMessage(MsgNumber, Function, 1)  ; Option 2 (MaxThreads = 1)

OnMessage(MsgNumber, Function, -1)
OnMessage(MsgNumber, Function, 0)
==================================================
Number := Ord(String)
==================================================
OutputDebug, Text
==================================================
#p::Pause ; Pressing Win+P once will pause the script. Pressing it again will unpause.
Pause [, On|Off|Toggle, OperateOnUnderlyingThread?]
==================================================
PixelGetColor, OutputVar, X, Y [, Alt|Slow]
==================================================
PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID [, Variation, Fast]
==================================================
PostMessage, Msg [, wParam, lParam, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
SendMessage, Msg [, wParam, lParam, Control, WinTitle, WinText, ExcludeTitle, ExcludeText, Timeout]
==================================================
Random, OutputVar [, Min, Max]
Random, , NewSeed
==================================================
RegDelete, KeyName [, ValueName]
RegDeleteKey, KeyName
==================================================
FoundPos := RegExMatch(Haystack, NeedleRegEx [, OutputVar, StartingPosition = 1])
==================================================
NewStr := RegExReplace(Haystack, NeedleRegEx [, Replacement = "", OutputVarCount = "", Limit = -1, StartingPosition = 1])
==================================================
Address := RegisterCallback("FunctionName" [, Options = "", ParamCount = FormalCount, EventInfo = Address])
==================================================
RegRead, OutputVar, KeyName [, ValueName]
==================================================
RegWrite, ValueType, KeyName [, ValueName, Value]
==================================================
Reload
==================================================
Return [, Expression]
==================================================
Run, Target [, WorkingDir, Max|Min|Hide|UseErrorLevel, OutputVarPID]
RunWait, Target [, WorkingDir, Max|Min|Hide|UseErrorLevel, OutputVarPID]
==================================================
RunAs [, User, Password, Domain]
==================================================
Send Keys
SendRaw Keys
SendInput Keys
SendPlay Keys
SendEvent Keys
==================================================
SendLevel, Level
==================================================
SendMode Input|Play|Event|InputThenPlay
==================================================
SetControlDelay, Delay
==================================================
SetDefaultMouseSpeed, Speed
==================================================
Var := expression
==================================================
SetKeyDelay [, Delay, PressDuration, Play]
==================================================
SetMouseDelay, Delay [, Play]
==================================================
SetCapsLockState [, State]
SetNumLockState [, State]
SetScrollLockState [, State]
==================================================
SetRegView, RegView
==================================================
SetStoreCapslockMode, On|Off
==================================================
SetTimer [, Label, Period|On|Off|Delete, Priority]
==================================================
SetTitleMatchMode, MatchMode
SetTitleMatchMode, Fast|Slow
==================================================
SetWinDelay, Delay
==================================================
SetWorkingDir, DirName
==================================================
Shutdown, Code
==================================================
Sleep, DelayInMilliseconds
==================================================
Sort, OutputVar, String [, Options]
==================================================
SoundBeep [, Frequency, Duration]
==================================================
SoundGet, OutputVar [, ComponentType, ControlType, DeviceNumber]
==================================================
SoundPlay, Filename [, wait]
==================================================
SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]
==================================================
SplitPath, Path [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive]
==================================================
StatusBarGetText, OutputVar [, Part#, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
StatusBarWait [, BarText, Seconds, Part#, WinTitle, WinText, Interval, ExcludeTitle, ExcludeText]
==================================================
StringCaseSense, On|Off|Locale
==================================================
StrLower, OutputVar, String [, T]
StrUpper, OutputVar, String [, T]
==================================================
StrPut(String [, Encoding = None ] )
StrPut(String, Address [, Length] [, Encoding = None ] )
StrGet(Address [, Length] [, Encoding = None ] )
==================================================
OutputVar := StrReplace(Haystack, SearchText [, ReplaceText, OutputVarCount, Limit := -1])
StrReplace, OutputVar, Haystack, SearchText [, ReplaceText, OutputVarCount, Limit = -1]
==================================================
Array := StrSplit(String [, Delimiters, OmitChars])
==================================================
NewStr := SubStr(String, StartingPos [, Length])
==================================================
Suspend [, Mode]
==================================================
OutputVar := SysGet(Sub-command)
SysGet, OutputVar, Sub-command
==================================================
Thread, NoTimers [, false]
Thread, Priority, n
Thread, Interrupt [, Duration, LineCount]
==================================================
Throw [, Expression]
==================================================
ToolTip [, Text, X, Y, WhichToolTip]
==================================================
TrayTip [, Text, Title, Options]
==================================================
Result :=  Trim(String, OmitChars = " `t")
Result := LTrim(String, OmitChars = " `t")
Result := RTrim(String, OmitChars = " `t")
==================================================
Try Statement
==================================================
OutputVar := Type(Value)
==================================================
Loop {
    ...
} Until Expression
==================================================
GrantedCapacity := VarSetCapacity(UnquotedVarName [, RequestedCapacity, FillByte])
==================================================
While Expression
While(Expression)
==================================================
WinActivate [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinActivateBottom [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
UniqueID := WinActive("WinTitle", "WinText", "ExcludeTitle", "ExcludeText")
==================================================
WinClose [, WinTitle, WinText, SecondsToWait, ExcludeTitle, ExcludeText]
==================================================
UniqueID := WinExist("WinTitle", "WinText", "ExcludeTitle", "ExcludeText")
==================================================
WinGetX, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
OutputVar := WinGetX([WinTitle, WinText, ExcludeTitle, ExcludeText])
==================================================
WinGetClass, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinGetPos [, X, Y, Width, Height, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinGetText, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinGetTitle, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinHide [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinKill [, WinTitle, WinText, SecondsToWait, ExcludeTitle, ExcludeText]
==================================================
WinMaximize [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinMinimize [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinMinimizeAll
WinMinimizeAllUndo
==================================================
WinMove, X, Y
WinMove, WinTitle, WinText, X, Y [, Width, Height, ExcludeTitle, ExcludeText]
==================================================
WinRestore [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinSetAlwaysOnTop [, Value, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinMoveBottom [, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinMoveTop [, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinSetEnabled, Value [, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinRedraw [, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinSetStyle, Value [, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinSetExStyle, Value [, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinSetRegion [, Options, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinSetTransparent [, N, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinSetTransColor, Color [N] [, Options, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinSetTitle, NewTitle
WinSetTitle, WinTitle, WinText, NewTitle [, ExcludeTitle, ExcludeText]
==================================================
WinShow [, WinTitle, WinText, ExcludeTitle, ExcludeText]
==================================================
WinWait [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
==================================================
WinWaitActive [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
WinWaitNotActive [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
==================================================
WinWaitClose [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
==================================================
#ClipboardTimeout Milliseconds
==================================================
#ErrorStdOut
==================================================
#HotkeyInterval Milliseconds
==================================================
#HotkeyModifierTimeout Milliseconds
==================================================
#Hotstring NoMouse
#Hotstring EndChars NewChars
#Hotstring NewOptions
==================================================
#If [, Expression ]
==================================================
#IfTimeout Timeout
==================================================
#IfWinActive [, WinTitle, WinText]
#IfWinExist [, WinTitle, WinText]
#IfWinNotActive [, WinTitle, WinText]
#IfWinNotExist [, WinTitle, WinText]
#If [, Expression]
==================================================
#Include FileOrDirName
#Include <LibName>
#IncludeAgain FileOrDirName
==================================================
#InputLevel [, Level]
==================================================
#InstallKeybdHook
==================================================
#InstallMouseHook
==================================================
#KeyHistory MaxEvents
==================================================
#MaxHotkeysPerInterval Value
==================================================
#MaxThreads Value
==================================================
#MaxThreadsBuffer On|Off
==================================================
#MaxThreadsPerHotkey Value
==================================================
#MenuMaskKey KeyName
==================================================
#NoTrayIcon
==================================================
#Persistent
==================================================
#SingleInstance [force|ignore|off]
==================================================
#UseHook [On|Off]
==================================================
#Warn [, WarningType, WarningMode]
==================================================
#WinActivateForce
==================================================
HBITMAP:bitmap-handle
HICON:icon-handle
==================================================
LabelName:
==================================================
Function(Match, CalloutNumber, FoundPos, Haystack, NeedleRegEx)
{
    ...
}
==================================================
Enum.Next(OutputVar1 [, OutputVar2, ...])
==================================================
String := File.Read([Characters])
File.Write(String)
Line := File.ReadLine()
File.WriteLine([String])
Num := File.ReadNumType()
File.WriteNumType(Num)
File.RawRead(VarOrAddress, Bytes)
File.RawWrite(VarOrAddress, Bytes)
File.Seek(Distance [, Origin = 0])
File.Position := Distance
File.Pos := Distance
Pos := File.Tell()
Pos := File.Position
Pos := File.Pos
FileSize := File.Length
File.Length := NewSize
IsAtEOF := File.AtEOF
File.Close()
Encoding := File.Encoding
File.Encoding := Encoding
File.__Handle
==================================================
Func.Call(Parameters)
%Func%(Parameters)
BoundFunc := Func.Bind(Parameters)
Func.Name
Func.IsBuiltIn
Func.IsVariadic
Func.MinParams
Func.MaxParams
Func.IsByRef(ParamIndex)
Func.IsOptional(ParamIndex)
==================================================
Object.InsertAt(Pos, Value1 [, Value2, ... ValueN])
Object.RemoveAt(Pos [, Length])
Object.Push([ Value, Value2, ..., ValueN ])
Value := Object.Pop()
MinIndex := Object.MinIndex()
MaxIndex := Object.MaxIndex()
Length := Object.Length()
Object.SetCapacity(MaxItems)
Object.SetCapacity(Key, ByteSize)
MaxItems := Object.GetCapacity()
ByteSize := Object.GetCapacity(Key)
Ptr := Object.GetAddress(Key)
Enum := Object._NewEnum()
Object.HasKey(Key)
Clone := Object.Clone()
ObjRawSet(Object, Key, Value)
==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: commands as functions (AHK v2 functions for AHK v1)

03 Apr 2017, 18:14

A V2-like msgbox, doesn't accept string like okcancel for msgbox type as it does in v2, but returns button pressed or can be a var passed as byref. The Problem I found with using coco's version was the parameter order is different between v1 and v2, so msgbox(params) code would have to differ depending on version, making it a pita to test code between the two, this sort of unifies that as long as you stick to numbers for the msgbox type. I just didnt want to do a regexmatch to allow it to use strings for msgbox type, since regexmatch differs a little between V1 and V2.
Works for my use case, can't guarantee it will account for everyone's.
Too bad i had to dirty it up using cancer command ifmsgbox with returns to prevent it from continuing once it finds a match as there is no else for it as far as im aware.

Rules
- Return value: Button that was pressed, like in V2
- Options separated by space or tab, integer value for type of box, and/or timeout seconds (int or float) preceded by T within a string, e.g: "T4"
- Only numbers for the type of msgbox (as in V1), NO strings (like "OKCancel" in V2)
- If using a number as msgbox type, it can be passed within the string
e.g: Msgbox("text", "title", "4 T3", buttonPressed)
- Msgbox type can be a math expression, just dont quote it, and if adding timeout, precede timeout string with a space or tab
e.g: Msgbox("text", "title", 1+3 " T3")
- Timeout is optional and the T in timeout string is case insensitive
- Optional ByRef variable like in V2, value assigned is the button that was pressed

Code: Select all

MsgBox(Text:="", Title:="", Options:="", ByRef PressedButtonOutVar:="") {
	TimeoutValue:=""
	OptionValue:=""
	if (!Text && !Title && !Options)
		Msgbox
	else if (!Title && !Options)
		Msgbox, % Text
	else if (!Options)
		Msgbox, , % Title, % Text
	else {
		optionsArray:=StrSplit(Options, [A_Tab, A_Space])
		For key, value in optionsArray {
			if !InStr(value, "t")
				OptionValue:=optionsArray[key]
			else
				TimeoutValue:=Trim(optionsArray[key], "tT")
		}
		Msgbox, % OptionValue, % Title, % Text, % TimeoutValue
		optionsArray:=""
	}
	
	IfMsgBox, Timeout
		return PressedButtonOutVar:="timeout"
	IfMsgBox, OK
		return PressedButtonOutVar:="ok"
	IfMsgBox, Cancel
		return PressedButtonOutVar:="cancel"
	IfMsgBox, Yes
		return PressedButtonOutVar:="yes"
	IfMsgBox, No
		return PressedButtonOutVar:="no"
	IfMsgBox, Abort
		return PressedButtonOutVar:="abort"
	IfMsgBox, Ignore
		return PressedButtonOutVar:="ignore"
	IfMsgBox, Retry
		return PressedButtonOutVar:="retry"
	IfMsgBox, Continue
		return PressedButtonOutVar:="continue"
	IfMsgBox, TryAgain
		return PressedButtonOutVar:="tryagain"
	;and just in case
	return ""
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

03 Apr 2017, 18:52

I was hoping that Coco and Lexikos would team up again to do nice MsgBox/TrayTip functions, with some good RegEx, as they did with the InputBox function. Until such time, a provisional TrayTip function done to match the style of the others:

Code: Select all

TrayTip(Text:=" ", Title:=" ", Options:=0)
{
    local Num := 0
    Loop Parse, Options, % " `t"
    {
        (A_LoopField = "Iconi") ? (Num |= 1) : ""
        (A_LoopField = "Icon!") ? (Num |= 2) : ""
        (A_LoopField = "Iconx") ? (Num |= 3) : ""
        (A_LoopField = "Mute") ? (Num |= 16) : ""
        if A_LoopField is integer
            Num |= A_LoopField
    }
    TrayTip %Title%, %Text%,, %Num%
}
==================================================

@coffee. Great code, cheers.

AFAIK all the functions are working, apart from MsgBox and TrayTip that needed updating.

Btw these functions are only meant to be for AHK v1, so differences in RegExMatch/RegExReplace shouldn't be an issue.

You could simplify the last bit with:

Code: Select all

Loop Parse, % "Yes,No,OK,Cancel,Abort,Ignore,Retry,Continue,TryAgain,Timeout", % ","
    IfMsgBox %A_LoopField%
        return PressedButtonOutVar := A_LoopField

;or:
Loop Parse, % "Yes,No,OK,Cancel,Abort,Ignore,Retry,Continue,TryAgain,Timeout", % ","
    IfMsgBox %A_LoopField%
    {
        PressedButtonOutVar := A_LoopField
        break
    }
return PressedButtonOutVar
Hmm this reminds me, is it better to break out of a loop first, or is it OK to return while in the middle of a loop?

==================================================

[EDIT:] For two-way compatible output from RegEx, at present that would require objects, and you would check for whether it's v1/v2, and include the letter 'O' and a possibly a close (round) bracket if it's v1.

Some ways to check for v1/v2 at the bottom of this post:
conversion logic, v1 = -> v1 := -> v2, two-way compatibility - Page 4 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 69#p139769

==================================================

Alphabetical Command and Function Index
https://autohotkey.com/docs/commands/
Alphabetical Command and Function Index
https://lexikos.github.io/v2/docs/commands/index.htm

MsgBox
https://autohotkey.com/docs/commands/MsgBox.htm
MsgBox
https://lexikos.github.io/v2/docs/commands/MsgBox.htm

TrayTip
https://autohotkey.com/docs/commands/TrayTip.htm
TrayTip
https://lexikos.github.io/v2/docs/commands/TrayTip.htm

InputBox
https://autohotkey.com/docs/commands/InputBox.htm
InputBox
https://lexikos.github.io/v2/docs/commands/InputBox.htm
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: commands as functions (AHK v2 functions for AHK v1)

03 Apr 2017, 23:04

jeeswg wrote:I was hoping that Coco and Lexikos would team up again to do nice MsgBox/TrayTip functions, with some good RegEx, as they did with the InputBox function. Until such time, a provisional TrayTip function done to match the style of the others:

Btw these functions are only meant to be for AHK v1, so differences in RegExMatch/RegExReplace shouldn't be an issue.


Hmm this reminds me, is it better to break out of a loop first, or is it OK to return while in the middle of a loop?
Yeah, I forgot why I even created this, v2 obviously has this already, so its only supposed to run on v1.

For the most part, you should avoid having a clusterfuck of returns, like I had. Multiple returns are ok if they improve readability by using them as guard code and reduce conditional nesting. Generally, only 1 return. I dont think it would harm anything in this case, and would make it shorter.

I regexed the msgbox, using your parse loop at the end to remove the ifmsgbox clutter, just reordered the options by most common in my cases, so they hit first.

Same rules, you can now use the string values of v2 like okcancel etc etc, combined with a timeout with the same format as v2 and you can also use integers mixed in here to get the msgbox type.
So in options parameter, it can be "canceltryagaincontinue 16 768 t4" or "4 iconx t3 default2" or... you get the drift.
Had to create an array (boxtypearray) of the string options from v2 with their numerical values to make it static and not have to do another loop to convert values with a bunch of ifs. So the idea is, use it like v2 and get the options right lol. The array declaration is inside the else, so it is only filled in that condition.
It retains being able to use the math expressions, for instance, ..."title", 1+16 " default2 t3", outputvar
Option value grabs the numeric value of the string option for the messagebox type and adds it unto itself, or if it sees an digit only line it grabs the whole thing and adds it unto itself, which is pretty much how you configure the box type.

Code: Select all

MsgBox(Text:="", Title:="", Options:="", ByRef PressedButtonOutVar:="") {
	TimeoutValue:="", OptionValue:=0

	if (!Text && !Title && !Options)
		Msgbox
	else if (!Title && !Options)
		Msgbox, % Text
	else if (!Options)
		Msgbox, , % Title, % Text
	else {
		BoxTypeArray:={"OK": 0, "O": 0, "OKCancel": 1, "OC": 1, "O/C": 1
			, "AbortRetryIgnore": 2, "ARI": 2, "A/R/I": 2, "YesNoCancel": 3, "Y/N/C": 3, "YNC": 3
			, "YesNo": 4, "Y/N": 4, "YN": 4, "RetryCancel": 5, "R/C": 5, "RC": 5
			, "CancelTryAgainContinue": 6, "C/T/C": 6, "CTC": 6, "Iconx": 16, "Icon?": 32, "Icon!": 48, "Iconi": 64
			, "Default2": 256, "Default3": 512, "Default4": 768}
		optionsArray:=StrSplit(Options, [A_Tab, A_Space])
		For key, value in optionsArray {
			if RegexMatch(value, "Oi)^t(\d+\.*\d*$)", TimeMatch) ;matches integer or float, anchored to start and end, 4 or 3.23 etc
				TimeoutValue:=TimeMatch.value(1)
			else if RegexMatch(value, "Oi)^\d+$", OptionMatch) ;a value which is purely digits, anchored to start and end, is considerd a box type option, 1 or 2 or 256 etc
				OptionValue+=OptionMatch.value()
			else OptionValue+=BoxTypeArray[value] ;if string, the value is directly pulled from array, so far nothing ugly happens if you dont spell things right, it just doesnt get added
		}
		Msgbox, % OptionValue, % Title, % Text, % TimeoutValue
	}
	
	Loop, Parse, % "Timeout,OK,Cancel,Yes,No,Abort,Ignore,Retry,Continue,TryAgain", % ","
		IfMsgbox, % A_LoopField
		{
			PressedButtonOutVar:=A_LoopField
			break
		}
		
	return PressedButtonOutVar
}
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: commands as functions (AHK v2 functions for AHK v1)

19 Apr 2017, 05:14

If there's any interest, I removed some redundant logic in my previous post, made the array static, removed a regexmatch, changed the stringsplit to a parse loop for "performance" reasons (according to docs), and compressed lines with some ternary and removal of unneeded braces.
It has the added benefit(?) that if you somehow pass a negative box type number, it will work anyways. In contrast with v2, where it will throw an exception.

Code: Select all

MsgBox(p_text:="Press OK to continue", p_title:="", p_Options:="", ByRef r_PressedButtonVar:="") {
; >> Return value === same as in v2, button that was pressed
; >> p_Options === same as in v2, box type numbers and timeout
; 		Separated by space or tab, number/numeric string for box type, seconds (int/float) preceded by T as string for timeout, e.g: "T4"
; 		If using a number as box type, it can be passed within a string e.g: Msgbox("text", "title", "4 T3", buttonPressed)
; 		Msgbox type can be an unquoted math expression, and if adding timeout, prefix/postfix timeout string with a space or tab
; 		e.g: Msgbox("text", "title", 2+16 " T3") or Msgbox("text", "title", "T3 " 2+16)
; 		Timeout is optional and the T in timeout string is case insensitive
; >> r_PressedButtonVar === same as in V2, optional ByRef variable for button that was pressed
;**************************************************************************************************
	; Array for box types numerical values from V2, initialized only once during runtime
	static boxTypeArray:={"OK": 0, "O": 0, "OKCancel": 1, "OC": 1, "O/C": 1, "AbortRetryIgnore": 2, "ARI": 2, "A/R/I": 2
		, "YesNoCancel": 3, "Y/N/C": 3, "YNC": 3, "YesNo": 4, "Y/N": 4, "YN": 4, "RetryCancel": 5, "R/C": 5, "RC": 5
		, "CancelTryAgainContinue": 6, "C/T/C": 6, "CTC": 6, "Iconx": 16, "Icon?": 32, "Icon!": 48, "Iconi": 64
		, "Default2": 256, "Default3": 512, "Default4": 768}
	timeout:="", boxType:=0
	if (p_options) {
		Loop, parse, p_Options, % A_Space A_Tab
			(k:=Abs(A_LoopField)) || (k:=boxTypeArray[A_LoopField]) ? boxType:=boxType+k ; if number (abs), add number to boxType var
				: RegexMatch(A_LoopField, "Oi)^t(\d+\.?\d*)$", timeMatch) ? timeout:=timeMatch.value(1) ; timeoutvar = numbers after the T
				: ("")
	}

	Msgbox, % boxType, % p_Title, % p_Text, % timeout
	Loop, Parse, % "Timeout,OK,Cancel,Yes,No,Abort,Ignore,Retry,Continue,TryAgain", % ","
		IfMsgbox, % r_PressedButtonVar:=A_LoopField
				break

	return r_PressedButtonVar
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

22 Jul 2017, 16:25

I've added some modified and new functions (untested). Although there have been other changes to AHK v2 that I haven't implemented.

AFAICS the bulk of the changes have been made now, and I still haven't heard from Coco, so my recommendation would be for a main dev, to take over this project, make it an official lib, and iron out the remaining niggles. Anyone willing to take over can change my functions as maximally or minimally as they wish, to suit their personal coding preferences.

Note: I've updated my list of every command/function etc:
list of every command/function/variable from across all versions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=27321

==================================================

AutoHotkey v2 alpha (UPDATES) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 36#p153136
'Changed parameter order of ControlMove, ControlSend, ControlSetText, WinSetTitle and WinMove to be consistent with other functions.'

Code: Select all

ControlMove(X:="", Y:="", Width:="", Height:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlMove %Control%, %X%, %Y%, %Width%, %Height%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlSend(Keys:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlSend %Control%, %Keys%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlSetText(NewText:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlSetText %Control%, %NewText%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinMove(Params*)
{
    local WinTitle, WinText, X, Y, Width, Height, ExcludeTitle, ExcludeText
    local Len
    if (Len := Params.Length())
    {
        if (Len > 2)
        {
            X            := Params[1]
            Y            := Params[2]
            Width        := Params[3]
            Height       := Params[4]
            WinTitle     := Params[5]
            WinText      := Params[6]
            ExcludeTitle := Params[7]
            ExcludeText  := Params[8]
            WinMove %WinTitle%, %WinText%, %X%, %Y%, %Width%, %Height%, %ExcludeTitle%, %ExcludeText%
        }
        else
        {
            X := Params[1]
            Y := Params[2]
            WinMove %X%, %y%
        }
    }
    else
        WinMove
}
WinSetTitle(Param:="", Params*)
{
    local WinTitle, WinText, NewTitle, ExcludeTitle, ExcludeText
    if (Params.Length())
    {
        NewTitle     := Param
        WinTitle     := Params[1]
        WinText      := Params[2]
        ExcludeTitle := Params[3]
        ExcludeText  := Params[4]
        WinSetTitle %WinTitle%, %WinText%, %NewTitle%, %ExcludeTitle%, %ExcludeText%
    }
    else
        WinSetTitle %Param% ; WinSetTitle, NewTitle
}
'Split Control, ControlGet, Drive and DriveGet sub-commands into separate functions (with some renaming).'

Code: Select all

ControlAddItem(String, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd, Class
    Control Add, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if ErrorLevel
        return
    ControlGet Hwnd, Hwnd,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    WinGetClass Class, ahk_id %Hwnd%
    if (Class = "ListBox")
        SendMessage 0x18B, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCOUNT
    else if (Class = "ComboBox")
        SendMessage 0x146, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;CB_GETCOUNT
    return ErrorLevel
}
ControlChoose(N, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd, Class
    ControlGet Hwnd, Hwnd,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    WinGetClass Class, ahk_id %Hwnd%
    if !(N = 0)
        Control Choose, %N%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    else if (Class = "ListBox")
        SendMessage 0x185, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_SETSEL
    else if (Class = "ComboBox")
        SendMessage 0x14E, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;CB_SETCURSEL
    else
        ErrorLevel := 1
}
ControlChooseString(String, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd, Class
    Control ChooseString, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if ErrorLevel
        return
    ControlGet Hwnd, Hwnd,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    WinGetClass Class, ahk_id %Hwnd%
    if (Class = "ListBox")
        SendMessage 0x188, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCURSEL
    else if (Class = "ComboBox")
        SendMessage 0x147, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;CB_GETCURSEL
    return ErrorLevel+1
}
ControlDeleteItem(N, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control Delete, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlEditPaste(String, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control EditPaste, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlFindItem(String, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, FindString, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetChecked(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Checked,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetChoice(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Choice,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetCurrentCol(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, CurrentCol,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetCurrentLine(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, CurrentLine,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetEnabled(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Enabled,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetExStyle(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, ExStyle,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetHwnd(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Hwnd,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetLine(Index, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Line, %Index%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetLineCount(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, LineCount,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetList(Options, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, List, %Options%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetSelected(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Selected,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetStyle(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Style,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetTab(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Tab,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetVisible(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Visible,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlHide(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control Hide,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlHideDropDown(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control HideDropDown,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetChecked(TrueFalseToggle, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Boolean
    ControlGet Boolean, Checked,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (TrueFalseToggle = "Toggle" || TrueFalseToggle == "-1")
        TrueFalseToggle := !Boolean
    if (TrueFalseToggle = "On" || TrueFalseToggle == "1")
        Control Check,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    else if (TrueFalseToggle = "Off" || TrueFalseToggle == "0")
        Control Uncheck,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetEnabled(TrueFalseToggle, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Boolean
    ControlGet Boolean, Enabled,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (TrueFalseToggle = "Toggle" || TrueFalseToggle == "-1")
        TrueFalseToggle := !Boolean
    if (TrueFalseToggle = "On" || TrueFalseToggle == "1")
        Control Enable,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    else if (TrueFalseToggle = "Off" || TrueFalseToggle == "0")
        Control Disable,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetExStyle(Value, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control ExStyle, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetStyle(Value, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control ExStyle, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetTab(N, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    SendMessage 0x1330, %N%,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;TCM_SETCURFOCUS
    Sleep 0
    SendMessage 0x130C, %N%,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;TCM_SETCURSEL
}
ControlShow(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control ShowDropDown,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlShowDropDown(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control ShowDropDown,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
DriveEject(Drive, Retract:=false)
{
    Drive Eject, %Drive%, %Retract%
}
DriveGetCapacity(Path)
{
    local OutputVar
    DriveGet OutputVar, Capacity, %Path%
    return OutputVar
}
DriveGetFilesystem(Drive)
{
    local OutputVar
    DriveGet OutputVar, Filesystem, %Drive%
    return OutputVar
}
DriveGetLabel(Drive)
{
    local OutputVar
    DriveGet OutputVar, Label, %Drive%
    return OutputVar
}
DriveGetList(Type)
{
    local OutputVar
    DriveGet OutputVar, List, %Type%
    return OutputVar
}
DriveGetSerial(Drive)
{
    local OutputVar
    DriveGet OutputVar, Serial, %Drive%
    return OutputVar
}
DriveGetSpaceFree(Path)
{
    local OutputVar
    DriveSpaceFree OutputVar, %Path%
    return OutputVar
}
DriveGetStatus(Drive)
{
    local OutputVar
    DriveGet OutputVar, Status, %Drive%
    return OutputVar
}
DriveGetStatusCD(Drive)
{
    local OutputVar
    DriveGet OutputVar, StatusCD, %Drive%
    return OutputVar
}
DriveGetType(Drive)
{
    local OutputVar
    DriveGet OutputVar, Type, %Drive%
    return OutputVar
}
DriveLock(Drive, NewLabel)
{
    Drive Lock, %Drive%
}
DriveSetLabel(Drive)
{
    Drive Label, %Drive%, %NewLabel%
}
DriveUnlock(Drive)
{
    Drive Unlock, %Drive%
}
Btw any ideas on how to differentiate between a ListBox and a ComboBox, other than by getting the class name via WinGetClass? Or to retrieve the version number of the control class? Thanks.
Last edited by jeeswg on 12 Aug 2017, 14:18, edited 4 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

22 Jul 2017, 16:37

Code: Select all

q:: ;split functions to separate files
vText := Clipboard
vText := RegExReplace(vText, "\}`r`n(\w)", "}`r`n" Chr(1) "$1")
vDir = %A_Desktop%\ahk fc ;forwards compatibility
FileCreateDir, % vDir
Loop, Parse, vText, % Chr(1)
{
	vTemp := RTrim(A_LoopField, "`r`n")
	vName := RegExReplace(vTemp, "s)\(.*") ".ahk"
	;MsgBox, % vName "`r`n" vTemp
	vPath := vDir "\" vName
	if !FileExist(vPath)
		FileAppend, % vTemp, % "*" vPath
		;FileAppend, % vTemp, % "*" vPath, UTF-8
}
Run, % vDir
MsgBox, % "done"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: commands as functions (AHK v2 functions for AHK v1)

24 Jul 2017, 12:30

Was just going to post here that it looks like no one has split ControlGet, etc into subfunctions. But now I see it in your second last post.

I am trying to convert ControlGet, var, List to var := ControlGetList(). But having no luck. How do you leave the options parameter blank if it is only for ListView? I am using this in a list box. Please excuse my ignorance, if possible. I would like to learn to move away from command syntax.
try it and see
...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

24 Jul 2017, 13:10

This script should do what you want. I put examples for both a listview and a listbox, because you mentioned both. Btw a good place to check for hints is the AHK v2 help.

Code: Select all

q::
vText1 := ControlGetList("", "SysListView321", "A")
vText2 := ControlGetList("", "ListBox1", "A")
MsgBox, % vText1
MsgBox, % vText2
return

;Control Functions
;https://lexikos.github.io/v2/docs/commands/Control.htm#GetList
Alphabetical Command and Function Index
https://autohotkey.com/docs/commands/
Alphabetical Function Index
https://lexikos.github.io/v2/docs/commands/index.htm
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: commands as functions (AHK v2 functions for AHK v1)

24 Jul 2017, 15:10

OK, I guess I was forgetting quote marks around parameters. I was thinking that was needed only for literal strings. But maybe that's what parameters are, unless they're a variable. I think I'm learning.

Hmm, But I have some functions working with blank parameters without the quote marks...???

EDIT: This is my specific problem. Code:

Code: Select all

vText := ControlGetList(,CrlNN, "My Window")

WinGetPos(X, Y, Wi, He, "My Window")
SciTE error:

Code: Select all

C:\Users\users\Documents\AutoHotkey\Lib\WinGetPos.ahk (1) : ==> Functions cannot contain functions.
     Specifically: WinGetPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
I am convinced that I am an idiot.
try it and see
...
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: commands as functions (AHK v2 functions for AHK v1)

24 Jul 2017, 15:55

derz00 wrote:OK, I guess I was forgetting quote marks around parameters. I was thinking that was needed only for literal strings. But maybe that's what parameters are, unless they're a variable. I think I'm learning.

Hmm, But I have some functions working with blank parameters without the quote marks...???
In expressions, text without quotes are variables and with quotes are strings. Function(variable, "string"). If you have function parameters without quotes, then it's a variable and you are just evaluating it and passing it to the function.

At this point, if you are going through all the trouble to make v1 commands/functions like v2 functions and full expression syntax, why not use v2? You are already making the changes and using functions, finish it up by doing the remaining changes and start using v2. Any changes lexicos makes from current v2 081a onwards will probably be much easier to adapt to than cracking your skull on trying to make v1 like v2. v2 078 had a lot of similarities with v1, but on the current release, there's no ambiguity on what strings and variables are.
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: commands as functions (AHK v2 functions for AHK v1)

24 Jul 2017, 16:33

True enough. I wanted to start writing my new scripts to be compatible with v2, but not really having time to switch all my main scripts. But I guess I should focus on that...
try it and see
...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

24 Jul 2017, 16:39

@coffee: I have a massive amount of conversion to do, and the best approach would be to make my AHK v1 scripts more and more AHK v2-like, until I then jump over to AHK v2. The only way I've tried to make v1 more like v2 is by creating the functions, but I had always wanted function versions of commands anyway, and polyethene and (later I found out) Coco had already done a lot of work on this, so to do the project was a no-brainer. It's a fair but not massive amount of effort to make the functions, however, if the main devs want the functions to meet their exact specifications, e.g. error handling etc and answers to Coco's queries (see 'Useful comments regarding the functions' above), it would be more efficient for them to enact the final touches.

I plan to do some tutorials, some GUI work, and some miscellaneous stuff, and I'll then finish converting my main scripts, and share my converter scripts. It is generally better to know all the details of the problem before you try to solve it, I have had to reconvert certain functions, and I will have to rewrite various parts of my converter scripts, so it is prudent to delay conversion to a certain extent cf. rushing in.

Considering how to deal with double quotes, continuation sections, dereferencing, and one-line/multi-line verbatim text (I believe I have reasonable workarounds with which to proceed, however, perhaps a Verbatim command and/or continuation section enhancements are in order), has been a bit of a headache, even if you don't ask for two-way compatibility.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

12 Aug 2017, 14:41

This post takes me up-to-date with present AHK functions AFAIAC. [Note: I will add here in future: FileRead/FileAppend updates.]

Here are some more function updates/additions based on changes from this post onwards:
AutoHotkey v2 alpha (UPDATES) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 36#p153136

As ever, do notify of any issues, and thanks again to the writers of AutoHotkey.

FileSetAttrib
InputEnd
RandomSeed

RegDelete
RegDeleteKey
RegRead
RegWrite

WARNING: I have not thoroughly tested the registry functions, only use them if you are expert, and test carefully on a safe area of the registry before any widescale use. Although Coco did an excellent job on all functions, it seems he didn't consider registry functions for use within a registry loop, which I have tried to achieve.

Code: Select all

FileSetAttrib(Attributes, FilePattern:="", Mode:="")
{
    if !RegExMatch(Attributes, "^[+\-\^]")
    {
        FileSetAttrib -RASHOT, %FilePattern%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
        Attributes := "+" Attributes
    }
    FileSetAttrib %Attributes%, %FilePattern%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
    return !ErrorLevel
}

InputEnd()
{
    Input
    return !ErrorLevel
}

RandomSeed(NewSeed)
{
    Random , %NewSeed%
}

RegDelete(oParams*) ;KeyName, ValueName
{
    if (oParams.Length() = 1)
        oParams[2] := "AHK_DEFAULT"
    if oParams.Length()
    {
        if InStr(oParams[3], "\")
            RegDelete % oParams[1], % oParams[2]
        else
            RegDelete % oParams[1],, % oParams[2]
    }
    else
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else if (A_LoopRegName = "")
            RegDelete %A_LoopRegKey%, %A_LoopRegSubkey%, AHK_DEFAULT
        else
            RegDelete %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%
    }
    return !ErrorLevel
}
RegDeleteKey(KeyName)
{
    RegDelete %KeyName%
    return !ErrorLevel
}
RegRead(oParams*) ;KeyName, ValueName
{
    local OutputVar
    if oParams.Length()
    {
        if InStr(oParams[1], "\")
            RegRead OutputVar, % oParams[1], % oParams[2]
        else
            RegRead OutputVar, % oParams[1],, % oParams[2]
    }
    else
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegRead OutputVar, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%
    }
    if !ErrorLevel
        return OutputVar
}
RegWrite(oParams*) ;Value, ValueType, KeyName, ValueName
{
    if (oParams.Length() > 2)
    {
        if InStr(oParams[3], "\")
            RegWrite % oParams[2], % oParams[3], % oParams[4], % oParams[1]
        else
            RegWrite % oParams[2], % oParams[3],, % oParams[4], % oParams[1]
    }
    else if (oParams.Length() = 1)
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, % oParams[1]
    }
    else if (oParams.Length() = 0)
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else if InStr(A_LoopRegType, "_SZ")
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, % ""
        else
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, 0
    }
    return !ErrorLevel
}
- AFAIK a ClipboardAll function is impossible for AHK v1, although I believe a workaround is:
ClipSaved := IsFunc("ClipboardAll") ? ClipboardAll() : ClipboardAll

- I am not sure if registry loop handling has been added for RegDeleteKey.
- Also, I believe a 'RegCreateKey' function is needed for AutoHotkey, to create a key without creating a value. I.e. RegWrite/RegCreateKey cf. RegDelete/RegDeleteKey.
- I believe that some key logic for handling key names is as follows:

Code: Select all

if InStr(KeyName, "\")
    RegDelete %KeyName%, %ValueName%
else
    RegDelete %KeyName%,, %ValueName%
- A_LoopRegKey in AHK v1 is somewhat confusingly named, it is always the root key.
- Handy links:
https://autohotkey.com/docs/commands/LoopReg.htm
https://autohotkey.com/docs/commands/RegDelete.htm
https://autohotkey.com/docs/commands/RegRead.htm
https://autohotkey.com/docs/commands/RegWrite.htm
https://lexikos.github.io/v2/docs/commands/LoopReg.htm
https://lexikos.github.io/v2/docs/comma ... Delete.htm
https://lexikos.github.io/v2/docs/commands/RegRead.htm
https://lexikos.github.io/v2/docs/commands/RegWrite.htm
Last edited by jeeswg on 24 Aug 2017, 21:55, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

24 Aug 2017, 19:02

I will finish FileRead and FileAppend [EDIT: Done.], and post a complete set of 'AHK v2 functions for AHK v1' soon.

Since functions are of the form:
Text := FileRead(Filename, Options)
and AHK v2 is introducing special handing for binary variables, I believe that, like the ClipboardAll function, you could not have a two-way compatible way, via replicating AHK v2 functions, of creating a binary variable via FileRead.

To achieve two-way compatibility for scripts that read binary data to a variable, you would have to create a custom function using a ByRef variable, or perhaps you could use a File object instead.

Code: Select all

FileAppend(Text:="", Filename:="", Options:="")
{
    local EOL, Encoding
    EOL := "*"
    Loop Parse, Options, % " `t"
    {
        if (A_LoopField = "`n")
            EOL := ""
        else if (A_LoopField ~= "$UTF-|$CP")
            Encoding := A_LoopField
    }
    FileAppend %Text%, %EOL%%Filename%, %Encoding%
    return !ErrorLevel
}
FileRead(Filename, Options:="")
{
    local OutputVar, Options2
    Loop Parse, Options, % " `t"
    {
        if (SubStr(A_LoopField, 1, 1) = "m")
            Options2 .= "*" A_LoopField " "
        else if (A_LoopField = "`n")
            Options2 .= "*t "
        else if (SubStr(A_LoopField, 1, 2) = "CP")
            Options2 .= "*" SubStr(A_LoopField, 2) " "
    }
    FileRead OutputVar, %Options2%%Filename%
    if !ErrorLevel
        return OutputVar
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

24 Aug 2017, 22:12

Note: the RegDelete and RegWrite functions are untested, in case anyone has a virtual machine they can test them on.

Note: I noticed that force expression was used on SplitPath, I am not sure if any other parameters require this.

Code: Select all

;AHK v2 functions for AHK v1
;[updated: 2017-08-25]

;use at your own risk
;warning: RegDelete and RegWrite functions are untested

;functions from AHK v2 not replicated:
;GuiCreate
;GuiCtrlFromHwnd
;GuiFromHwnd

;known issues/limitations:
;ClipboardAll - binary variable
;FileAppend - binary variable (RAW)
;FileRead - binary variable (RAW)
;InputBox - password character

;see also:
;GitHub - cocobelgica/AutoHotkey-Future: Port of AutoHotkey v2.0-a built-in functions for AHK v1.1+
;https://github.com/cocobelgica/AutoHotkey-Future
;AutoHotkey-Future/Lib at master · cocobelgica/AutoHotkey-Future · GitHub
;https://github.com/cocobelgica/AutoHotkey-Future/tree/master/Lib
;Default/Portable installation StdLib - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=13&t=10434

;==================================================

BlockInput(Mode)
{
    BlockInput %Mode%
}
Click(Params*)
{
    local i, Param, Args
    for i, Param in Params
        Args .= " " . Param
    Click %Args%
}
ClipboardAll()
{
    ;this function allows the ClipboardAll function to appear in an AHK v1 script without crashing it
    MsgBox warning: the ClipboardAll function doesn't work in AutoHotkey v1
}
ClipWait(SecondsToWait:="", Param:=1)
{
    ClipWait %SecondsToWait%, %Param%
    return !ErrorLevel
}
ControlAddItem(String, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd, Class
    Control Add, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if ErrorLevel
        return
    ControlGet Hwnd, Hwnd,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    WinGetClass Class, ahk_id %Hwnd%
    if (Class = "ListBox")
        SendMessage 0x18B, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCOUNT
    else if (Class = "ComboBox")
        SendMessage 0x146, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;CB_GETCOUNT
    return ErrorLevel
}
ControlChoose(N, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd, Class
    ControlGet Hwnd, Hwnd,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    WinGetClass Class, ahk_id %Hwnd%
    if !(N = 0)
        Control Choose, %N%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    else if (Class = "ListBox")
        SendMessage 0x185, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_SETSEL
    else if (Class = "ComboBox")
        SendMessage 0x14E, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;CB_SETCURSEL
    else
        ErrorLevel := 1
}
ControlChooseString(String, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd, Class
    Control ChooseString, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if ErrorLevel
        return
    ControlGet Hwnd, Hwnd,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    WinGetClass Class, ahk_id %Hwnd%
    if (Class = "ListBox")
        SendMessage 0x188, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCURSEL
    else if (Class = "ComboBox")
        SendMessage 0x147, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;CB_GETCURSEL
    return ErrorLevel+1
}
ControlClick(ControlOrPos:="", WinTitle:="", WinText:="", WhichButton:="", ClickCount:="", Options:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlClick %ControlOrPos%, %WinTitle%, %WinText%, %WhichButton%, %ClickCount%, %Options%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlDeleteItem(N, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control Delete, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlEditPaste(String, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control EditPaste, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlFindItem(String, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, FindString, %String%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlFocus(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlFocus %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlGetChecked(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Checked,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetChoice(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Choice,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetCurrentCol(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, CurrentCol,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetCurrentLine(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, CurrentLine,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetEnabled(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Enabled,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetExStyle(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, ExStyle,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetFocus(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGetFocus OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
ControlGetHwnd(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Hwnd,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetLine(Index, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Line, %Index%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetLineCount(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, LineCount,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetList(Options, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, List, %Options%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlGetPos X, Y, Width, Height, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlGetSelected(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Selected,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetStyle(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Style,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetTab(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Tab,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlGetText(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGetText OutputVar, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
ControlGetVisible(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    ControlGet OutputVar, Visible,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
ControlHide(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control Hide,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlHideDropDown(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control HideDropDown,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlMove(X:="", Y:="", Width:="", Height:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlMove %Control%, %X%, %Y%, %Width%, %Height%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlSend(Keys:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlSend %Control%, %Keys%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlSendRaw(Control:="", Keys:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlSendRaw %Control%, %Keys%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlSetChecked(TrueFalseToggle, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Boolean
    ControlGet Boolean, Checked,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (TrueFalseToggle = "Toggle" || TrueFalseToggle == "-1")
        TrueFalseToggle := !Boolean
    if (TrueFalseToggle = "On" || TrueFalseToggle == "1")
        Control Check,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    else if (TrueFalseToggle = "Off" || TrueFalseToggle == "0")
        Control Uncheck,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetEnabled(TrueFalseToggle, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Boolean
    ControlGet Boolean, Enabled,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (TrueFalseToggle = "Toggle" || TrueFalseToggle == "-1")
        TrueFalseToggle := !Boolean
    if (TrueFalseToggle = "On" || TrueFalseToggle == "1")
        Control Enable,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    else if (TrueFalseToggle = "Off" || TrueFalseToggle == "0")
        Control Disable,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetExStyle(Value, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control ExStyle, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetStyle(Value, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control ExStyle, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlSetTab(N, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    SendMessage 0x1330, %N%,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;TCM_SETCURFOCUS
    Sleep 0
    SendMessage 0x130C, %N%,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;TCM_SETCURSEL
}
ControlSetText(NewText:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    ControlSetText %Control%, %NewText%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
ControlShow(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control ShowDropDown,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlShowDropDown(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    Control ShowDropDown,, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
CoordMode(Param1, Param2:="Screen")
{
    CoordMode %Param1%, %Param2%
}
Critical(Param:="")
{
    Critical %Param%
}
DateAdd(DateTime, Time, TimeUnits)
{
    EnvAdd DateTime, %Time%, %TimeUnits%
    return DateTime
}
DateDiff(DateTime1, DateTime2, TimeUnits)
{
    EnvSub DateTime1, %DateTime2%, %TimeUnits%
    return DateTime1
}
DetectHiddenText(OnOrOff)
{
    DetectHiddenText %OnOrOff%
}
DetectHiddenWindows(OnOrOff)
{
    DetectHiddenWindows %OnOrOff%
}
DirCopy(Source, Dest, Flag:=0)
{
    FileCopyDir %Source%, %Dest%, %Flag%
    return !ErrorLevel
}
DirCreate(DirName)
{
    FileCreateDir %DirName%
    return !ErrorLevel
}
DirDelete(DirName, Recurse:=0)
{
    FileRemoveDir %DirName%, %Recurse%
    return !ErrorLevel
}
DirExist(FilePattern)
{
    local AttributeString := FileExist(FilePattern)
    return InStr(AttributeString, "D") ? AttributeString : ""
}
DirMove(Source, Dest, Flag:=0)
{
    FileMoveDir %Source%, %Dest%, %Flag%
    return !ErrorLevel
}
DirSelect(StartingFolder:="", Options:=1, Prompt:="")
{
    local OutputVar
    FileSelectFolder OutputVar, %StartingFolder%, %Options%, %Prompt%
    if !ErrorLevel
        return OutputVar
}
Download(URL, FileName)
{
    URLDownloadToFile %URL%, %FileName%
    return !ErrorLevel
}
DriveEject(Drive, Retract:=false)
{
    Drive Eject, %Drive%, %Retract%
}
DriveGetCapacity(Path)
{
    local OutputVar
    DriveGet OutputVar, Capacity, %Path%
    return OutputVar
}
DriveGetFilesystem(Drive)
{
    local OutputVar
    DriveGet OutputVar, Filesystem, %Drive%
    return OutputVar
}
DriveGetLabel(Drive)
{
    local OutputVar
    DriveGet OutputVar, Label, %Drive%
    return OutputVar
}
DriveGetList(Type)
{
    local OutputVar
    DriveGet OutputVar, List, %Type%
    return OutputVar
}
DriveGetSerial(Drive)
{
    local OutputVar
    DriveGet OutputVar, Serial, %Drive%
    return OutputVar
}
DriveGetSpaceFree(Path)
{
    local OutputVar
    DriveSpaceFree OutputVar, %Path%
    return OutputVar
}
DriveGetStatus(Drive)
{
    local OutputVar
    DriveGet OutputVar, Status, %Drive%
    return OutputVar
}
DriveGetStatusCD(Drive)
{
    local OutputVar
    DriveGet OutputVar, StatusCD, %Drive%
    return OutputVar
}
DriveGetType(Drive)
{
    local OutputVar
    DriveGet OutputVar, Type, %Drive%
    return OutputVar
}
DriveLock(Drive, NewLabel)
{
    Drive Lock, %Drive%
}
DriveSetLabel(Drive)
{
    Drive Label, %Drive%, %NewLabel%
}
DriveUnlock(Drive)
{
    Drive Unlock, %Drive%
}
Edit()
{
    Edit
}
EnvGet(EnvVarName)
{
    local OutputVar
    EnvGet OutputVar, %EnvVarName%
    return OutputVar
}
EnvSet(EnvVar, Value:="")
{
    EnvSet %EnvVar%, %Value%
    return !ErrorLevel
}
Exit(ExitCode:=0)
{
    Exit %ExitCode%
}
ExitApp(ExitCode:=0)
{
    ExitApp %ExitCode%
}
FileAppend(Text:="", Filename:="", Options:="")
{
    local EOL, Encoding
    EOL := "*"
    Loop Parse, Options, % " `t"
    {
        if (A_LoopField = "`n")
            EOL := ""
        else if (A_LoopField ~= "$UTF-|$CP")
            Encoding := A_LoopField
    }
    FileAppend %Text%, %EOL%%Filename%, %Encoding%
    return !ErrorLevel
}
FileCopy(Source, Dest, Flag:=0)
{
    FileCopy %Source%, %Dest%, %Flag%
    return !ErrorLevel
}
FileCreateShortcut(Target, LinkFile, WorkingDir:="", Args:="", Description:="", IconFile:="", ShortcutKey:="", IconNumber:="", RunState:=1)
{
    FileCreateShortcut %Target%, %LinkFile%, %WorkingDir%, %Args%, %Description%, %IconFile%, %ShortcutKey%, %IconNumber%, %RunState%
    return !ErrorLevel
}
FileDelete(FilePattern)
{
    FileDelete %FilePattern%
    return !ErrorLevel
}
FileEncoding(Encoding:="")
{
    FileEncoding %Encoding%
}
FileGetAttrib(Filename:="")
{
    local OutputVar
    FileGetAttrib OutputVar, %Filename%
    if !ErrorLevel
        return OutputVar
}
FileGetShortcut(LinkFile, ByRef OutTarget:="", ByRef OutDir:="", ByRef OutArgs:="", ByRef OutDescription:="", ByRef OutIcon:="", ByRef OutIconNum:="", ByRef OutRunState:="")
{
    FileGetShortcut %LinkFile%, OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState
    return !ErrorLevel
}
FileGetSize(Filename:="", Units:="")
{
    local OutputVar
    FileGetSize OutputVar, %Filename%, %Units%
    if !ErrorLevel
        return OutputVar
}
FileGetTime(Filename:="", WhichTime:="M")
{
    local OutputVar
    FileGetTime OutputVar, %Filename%, %WhichTime%
    if !ErrorLevel
        return OutputVar
}
FileGetVersion(Filename:="")
{
    local OutputVar
    FileGetVersion OutputVar, %Filename%
    if !ErrorLevel
        return OutputVar
}
FileInstall(Source, Dest, Flag:=0)
{
    FileCopy %Source%, %Dest%, %Flag%
    return !ErrorLevel
}
FileMove(SourcePattern, DestPattern, Flag:=0)
{
    FileMove %SourcePattern%, %DestPattern%, %Flag%
    return !ErrorLevel
}
FileRead(Filename, Options:="")
{
    local OutputVar, Options2
    Loop Parse, Options, % " `t"
    {
        if (SubStr(A_LoopField, 1, 1) = "m")
            Options2 .= "*" A_LoopField " "
        else if (A_LoopField = "`n")
            Options2 .= "*t "
        else if (SubStr(A_LoopField, 1, 2) = "CP")
            Options2 .= "*" SubStr(A_LoopField, 2) " "
    }
    FileRead OutputVar, %Options2%%Filename%
    if !ErrorLevel
        return OutputVar
}
FileRecycle(FilePattern)
{
    FileRecycle %FilePattern%
    return !ErrorLevel
}
FileRecycleEmpty(DriveLetter:="")
{
    FileRecycleEmpty %DriveLetter%
    return !ErrorLevel
}
FileSelect(Options:=0, RootDir_Filename:="", Prompt:="", Filter:="")
{
    local OutputVar
    FileSelectFile OutputVar, %Options%, %RootDir_Filename%, %Prompt%, %Filter%
    if !ErrorLevel
        return OutputVar
}
FileSetAttrib(Attributes, FilePattern:="", Mode:="")
{
    if !RegExMatch(Attributes, "^[+\-\^]")
    {
        FileSetAttrib -RASHOT, %FilePattern%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
        Attributes := "+" Attributes
    }
    FileSetAttrib %Attributes%, %FilePattern%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
    return !ErrorLevel
}
FileSetTime(YYYYMMDDHH24MISS:="", FilePattern:="", WhichTime:="M", Mode:="")
{
    FileSetTime %YYYYMMDDHH24MISS%, %FilePattern%, %WhichTime%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
    return !ErrorLevel
}
FormatTime(YYYYMMDDHH24MISS:="", Format:="")
{
    local OutputVar
    FormatTime OutputVar, %YYYYMMDDHH24MISS%, %Format%
    return OutputVar
}
GroupActivate(GroupName, R:="")
{
    GroupActivate %GroupName%, %R%
    return !ErrorLevel
}
GroupAdd(GroupName, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    GroupAdd %GroupName%, %WinTitle%, %WinText%,, %ExcludeTitle%, %ExcludeText%
}
GroupClose(GroupName, AR:="")
{
    GroupClose %GroupName%, %AR%
}
GroupDeactivate(GroupName, R:="")
{
    GroupDeactivate %GroupName%, %R%
}
Hotkey(Param1, Param2:="", Param3:="")
{
    Hotkey %Param1%, %Param2%, %Param3%
    if (InStr(Param1, "IfWin") || InStr(Param3, "UseErrorLevel"))
        return !ErrorLevel
}
ImageSearch(ByRef OutputVarX:="", ByRef OutputVarY:="", X1:="", Y1:="", X2:="", Y2:="", ImageFile:="")
{
    ImageSearch OutputVarX, OutputVarY, %X1%, %Y1%, %X2%, %Y2%, %ImageFile%
    return !ErrorLevel
}
IniDelete(Filename, Section, Key:="")
{
    IniDelete %Filename%, %Section%, %Key%
    return !ErrorLevel
}
IniRead(Filename, Section:="", Key:="", Default:="")
{
    local OutputVar
    IniRead OutputVar, %Filename%, %Section%, %Key%, %Default%
    if !ErrorLevel
        return OutputVar
}
IniWrite(Value, Filename, Section, Key:="")
{
    IniWrite %Value%, %Filename%, %Section%, %Key%
    return !ErrorLevel
}
Input(Options:="", EndKeys:="", MatchList:="")
{
    local OutputVar
    Input OutputVar, %Options%, %EndKeys%, %MatchList%
    return OutputVar
}
InputBox(Title:="", Prompt:="", Options:="", Default:="")
{
    local _, _X, _Y, _W, _H, _T, _P, _Err
    ; v2 validates the value of a particular option:
    ; X and Y = integer (can be negative)
    ; W and H = postive integer only
    ; T = postive integer/float
    ; Credits to Lexikos [https://goo.gl/VjMTYu , https://goo.gl/ebEjon]
    RegExMatch(Options, "i)^[ \t]*(?:(?:X(?<X>-?\d+)|Y(?<Y>-?\d+)|W(?<W>\d+)"
        . "|H(?<H>\d+)|T(?<T>\d+(?:\.\d+)?)|(?<P>Password\S?)"
        . "|(?<Err>\S+)(*ACCEPT)"
        . ")(?=[ \t]|$)[ \t]*)*$", _)

    if (_Err != "")
        throw Exception("Invalid option.", -1, _Err)

    local OutputVar
    InputBox, OutputVar, %Title%, %Prompt%, % _P ? "HIDE" : "", %_W%, %_H%, %_X%, %_Y%,, %_T%, %Default%
    return OutputVar
}
InputEnd()
{
    Input
    return !ErrorLevel
}
KeyHistory()
{
    KeyHistory
}
KeyWait(KeyName, Options:="")
{
    KeyWait %KeyName%, %Options%
    return !ErrorLevel
}
ListHotkeys()
{
    ListHotkeys
}
ListLines(OnOrOff:="")
{
    ListLines %OnOrOff%
}
ListVars()
{
; Limitation -> won't work if called from within a function
    global
    ListVars
}
Menu(MenuName, Cmd, P3:="", P4:="", P5:="")
{
    Menu %MenuName%, %Cmd%, %P3%, %P4%, %P5%
}
MenuSelect(WinTitle:="", WinText:="", Menu:="", SubMenu1:="", SubMenu2:="", SubMenu3:="", SubMenu4:="", SubMenu5:="", SubMenu6:="", ExcludeTitle:="", ExcludeText:="")
{
    WinMenuSelectItem %WinTitle%, %WinText%, %Menu%, %SubMenu1%, %SubMenu2%, %SubMenu3%, %SubMenu4%, %SubMenu5%, %SubMenu6%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
MonitorGet(N:="", ByRef OutLeft:="", ByRef OutTop:="", ByRef OutRight:="", ByRef OutBottom:="")
{
    local Out
    SysGet Out, Monitor, %N%
    return (OutLeft != "" && OutTop != "" && OutRight != "" && OutBottom != "")
}
MonitorGetCount()
{
    local OutputVar
    SysGet OutputVar, MonitorCount
    return OutputVar
}
MonitorGetName(N:="")
{
    local OutputVar
    SysGet OutputVar, MonitorName
    return OutputVar
}
MonitorGetPrimary()
{
    local OutputVar
    SysGet OutputVar, MonitorPrimary
    return OutputVar
}
MonitorGetWorkArea(N:="", ByRef OutLeft:="", ByRef OutTop:="", ByRef OutRight:="", ByRef OutBottom:="")
{
    local Out
    SysGet Out, MonitorWorkArea, %N%
    return (OutLeft != "" && OutTop != "" && OutRight != "" && OutBottom != "")
}
MouseClick(WhichButton:="Left", X:="", Y:="", ClickCount:="", Speed:="", DU:="", R:="")
{
    MouseClick %WhichButton%, %X%, %Y%, %ClickCount%, %Speed%, %DU%, %R%
}
MouseClickDrag(WhichButton, X1:="", Y1:="", X2:="", Y2:="", Speed:="", R:="")
{
    MouseClickDrag %WhichButton%, %X1%, %Y1%, %X2%, %Y2%, %Speed%, %R%
}
MouseGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="", ByRef OutputVarWin:="", ByRef OutputVarControl:="", Mode:=0)
{
    MouseGetPos OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, %Mode%
}
MouseMove(X, Y, Speed:="", R:="")
{
    MouseMove %X%, %Y%, %Speed%, %R%
}
MsgBox(p_text:="Press OK to continue", p_title:="", p_Options:="", ByRef r_PressedButtonVar:="")
{
; >> Return value === same as in v2, button that was pressed
; >> p_Options === same as in v2, box type numbers and timeout
; 		Separated by space or tab, number/numeric string for box type, seconds (int/float) preceded by T as string for timeout, e.g: "T4"
; 		If using a number as box type, it can be passed within a string e.g: Msgbox("text", "title", "4 T3", buttonPressed)
; 		Msgbox type can be an unquoted math expression, and if adding timeout, prefix/postfix timeout string with a space or tab
; 		e.g: Msgbox("text", "title", 2+16 " T3") or Msgbox("text", "title", "T3 " 2+16)
; 		Timeout is optional and the T in timeout string is case insensitive
; >> r_PressedButtonVar === same as in V2, optional ByRef variable for button that was pressed
;**************************************************************************************************
	; Array for box types numerical values from V2, initialized only once during runtime
	static boxTypeArray:={"OK": 0, "O": 0, "OKCancel": 1, "OC": 1, "O/C": 1, "AbortRetryIgnore": 2, "ARI": 2, "A/R/I": 2
		, "YesNoCancel": 3, "Y/N/C": 3, "YNC": 3, "YesNo": 4, "Y/N": 4, "YN": 4, "RetryCancel": 5, "R/C": 5, "RC": 5
		, "CancelTryAgainContinue": 6, "C/T/C": 6, "CTC": 6, "Iconx": 16, "Icon?": 32, "Icon!": 48, "Iconi": 64
		, "Default2": 256, "Default3": 512, "Default4": 768}
	timeout:="", boxType:=0
	if (p_options) {
		Loop, parse, p_Options, % A_Space A_Tab
			(k:=Abs(A_LoopField)) || (k:=boxTypeArray[A_LoopField]) ? boxType:=boxType+k ; if number (abs), add number to boxType var
				: RegexMatch(A_LoopField, "Oi)^t(\d+\.?\d*)$", timeMatch) ? timeout:=timeMatch.value(1) ; timeoutvar = numbers after the T
				: ("")
	}

	Msgbox, % boxType, % p_Title, % p_Text, % timeout
	Loop, Parse, % "Timeout,OK,Cancel,Yes,No,Abort,Ignore,Retry,Continue,TryAgain", % ","
		IfMsgbox, % r_PressedButtonVar:=A_LoopField
				break

	return r_PressedButtonVar
}
OutputDebug(Text)
{
    OutputDebug %Text%
}
Pause(OnOffToggle:="", OperateOnUnderlyingThread:=0)
{
    Pause %OnOffToggle%, %OperateOnUnderlyingThread%
}
PixelGetColor(X, Y, AltSlow:="")
{
    local OutputVar
    PixelGetColor OutputVar, %X%, %Y%, %AltSlow% RGB ; v2 uses RGB
    if !ErrorLevel
        return OutputVar
}
PixelSearch(ByRef OutputVarX:="", ByRef OutputVarY:="", X1:="", Y1:="", X2:="", Y2:="", ColorID:="", Variation:=0, Fast:="")
{
    PixelSearch OutputVarX, OutputVarY, %X1%, %Y1%, %X2%, %Y2%, %ColorID%, %Variation%, %Fast% RGB
    return !ErrorLevel
}
PostMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    PostMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (ErrorLevel = "FAIL")
        ErrorLevel := "ERROR"
}
ProcessClose(PIDorName)
{
    Process Close, %PIDorName%
    return ErrorLevel
}
ProcessExist(PIDorName:="")
{
    Process Exist, %PIDorName%
    return ErrorLevel
}
ProcessSetPriority(Priority, PIDorName:="")
{
    Process Priority, %PIDorName%, %Priority%
    return ErrorLevel
}
ProcessWait(PIDorName, SecondsToWait:="")
{
    Process Wait, %PIDorName%, %SecondsToWait%
    return ErrorLevel
}
ProcessWaitClose(PIDorName, SecondsToWait:="")
{
    Process WaitClose, %PIDorName%, %SecondsToWait%
    return ErrorLevel
}
Random(Min:="", Max:="")
{
    local OutputVar
    Random OutputVar, %Min%, %Max%
    return OutputVar
}
RandomSeed(NewSeed)
{
    Random , %NewSeed%
}
RegDelete(oParams*) ;KeyName, ValueName
{
    if (oParams.Length() = 1)
        oParams[2] := "AHK_DEFAULT"
    if oParams.Length()
    {
        if InStr(oParams[3], "\")
            RegDelete % oParams[1], % oParams[2]
        else
            RegDelete % oParams[1],, % oParams[2]
    }
    else
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else if (A_LoopRegName = "")
            RegDelete %A_LoopRegKey%, %A_LoopRegSubkey%, AHK_DEFAULT
        else
            RegDelete %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%
    }
    return !ErrorLevel
}
RegDeleteKey(KeyName)
{
    RegDelete %KeyName%
    return !ErrorLevel
}
RegRead(oParams*) ;KeyName, ValueName
{
    local OutputVar
    if oParams.Length()
    {
        if InStr(oParams[1], "\")
            RegRead OutputVar, % oParams[1], % oParams[2]
        else
            RegRead OutputVar, % oParams[1],, % oParams[2]
    }
    else
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegRead OutputVar, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%
    }
    if !ErrorLevel
        return OutputVar
}
RegWrite(oParams*) ;Value, ValueType, KeyName, ValueName
{
    if (oParams.Length() > 2)
    {
        if InStr(oParams[3], "\")
            RegWrite % oParams[2], % oParams[3], % oParams[4], % oParams[1]
        else
            RegWrite % oParams[2], % oParams[3],, % oParams[4], % oParams[1]
    }
    else if (oParams.Length() = 1)
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, % oParams[1]
    }
    else if (oParams.Length() = 0)
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else if InStr(A_LoopRegType, "_SZ")
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, % ""
        else
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, 0
    }
    return !ErrorLevel
}
Reload()
{
    Reload
}
Run(Target, WorkingDir:="", Options:="", ByRef OutputVarPID:="")
{
    Run %Target%, %WorkingDir%, %Options%, OutputVarPID
    if InStr(Options, "UseErrorLevel")
        return !ErrorLevel
}
RunAs(User:="", Password:="", Domain:="")
{
    RunAs %User%, %Password%, %Domain%
}
RunWait(Target, WorkingDir:="", Options:="", ByRef OutputVarPID:="")
{
    RunWait %Target%, %WorkingDir%, %Options%, OutputVarPID
    return ErrorLevel
}
Send(Keys)
{
    Send %Keys%
}
SendEvent(Keys)
{
    SendEvent %keys%
}
SendInput(Keys)
{
    SendInput %Keys%
}
SendLevel(Level)
{
    SendLevel %Level%
}
SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")
{
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    if (ErrorLevel = "FAIL")
        ErrorLevel := "ERROR"
}
SendMode(Mode)
{
    SendMode %Mode%
}
SendPlay(Keys)
{
    SendPlay %Keys%
}
SendRaw(Keys)
{
    SendRaw %Keys%
}
SetCapsLockState(State:="")
{
    SetCapsLockState %State%
}
SetControlDelay(Delay)
{
    SetControlDelay %Delay%
}
SetDefaultMouseSpeed(Speed)
{
    SetDefaultMouseSpeed %Speed%
}
SetKeyDelay(Delay:="", PressDuration:="", Play:="")
{
    SetKeyDelay %Delay%, %PressDuration%, %Play%
}
SetMouseDelay(Delay, Play:="")
{
    SetMouseDelay %Delay%, %Play%
}
SetNumLockState(State:="")
{
    SetNumLockState %State%
}
SetRegView(RegView)
{
    SetRegView %RegView%
}
SetScrollLockState(State:="")
{
    SetScrollLockState %State%
}
SetStoreCapslockMode(OnOrOff)
{
    SetStoreCapslockMode %OnOrOff%
}
SetTimer(Label:="", Period:="", Priority:=0)
{
    SetTimer %Label%, %Period%, %Priority%
}
SetTitleMatchMode(MatchModeOrSpeed)
{
    SetTitleMatchMode %MatchModeOrSpeed%
}
SetWinDelay(Delay)
{
    SetWinDelay %Delay%
}
SetWorkingDir(DirName)
{
    SetWorkingDir %DirName%
    return !ErrorLevel
}
Shutdown(Code)
{
    Shutdown %Code%
}
Sleep(DelayInMilliseconds)
{
    Sleep %DelayInMilliseconds%
}
Sort(String, Options:="")
{
    Sort String, %Options%
    return String
}
SoundBeep(Frequency:=523, Duration:=150)
{
    SoundBeep %Frequency%, %Duration%
}
SoundGet(ComponentType:="", ControlType:="", DeviceNumber:=1)
{
    local OutputVar
    SoundGet OutputVar, %ComponentType%, %ControlType%, %DeviceNumber%
    if !ErrorLevel
        return OutputVar
}
SoundPlay(Filename, Wait:="")
{
    SoundPlay %Filename%, %Wait%
    return !ErrorLevel
}
SoundSet(NewSetting, ComponentType:="", ControlType:="", DeviceNumber:=1)
{
    SoundSet %NewSetting%, %ComponentType%, %ControlType%, %DeviceNumber%
    return !ErrorLevel
}
SplitPath(Path, ByRef OutFileName:="", ByRef OutDir:="", ByRef OutExtension:="", ByRef OutNameNoExt:="", ByRef OutDrive:="")
{
    SplitPath % Path, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
}
StatusBarGetText(PartNum:=1, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    StatusBarGetText OutputVar, %PartNum%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
StatusBarWait(BarText:="", Seconds:="", PartNum:=1, WinTitle:="", WinText:="", Interval:=50, ExcludeTitle:="", ExcludeText:="")
{
    StatusBarWait %BarText%, %Seconds%, %PartNum%, %WinTitle%, %WinText%, %Interval%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
StringCaseSense(OnOffLocale)
{
    StringCaseSense %OnOffLocale%
}
StrLower(String, T:="")
{
    local OutputVar
    StringLower OutputVar, String, %T%
    return OutputVar
}
StrUpper(String, T:="")
{
    local OutputVar
    StringUpper OutputVar, String, %T%
    return OutputVar
}
Suspend(Mode:="Toggle")
{
    Suspend %Mode%
}
SysGet(SubCommand)
{
    local OutputVar
    SysGet OutputVar, %SubCommand%
    return OutputVar
}
Thread(Param1, Param2:="", Param3:="")
{
    Thread %Param1%, %Param2%, %Param3%
}
ToolTip(Text:="", X:="", Y:="", WhichToolTip:=1)
{
    ToolTip %Text%, %X%, %Y%, %WhichToolTip%
}
TrayTip(Text:=" ", Title:=" ", Options:=0)
{
    local Num := 0
    Loop Parse, Options, % " `t"
    {
        (A_LoopField = "Iconi") ? (Num |= 1) : ""
        (A_LoopField = "Icon!") ? (Num |= 2) : ""
        (A_LoopField = "Iconx") ? (Num |= 3) : ""
        (A_LoopField = "Mute") ? (Num |= 16) : ""
        if A_LoopField is integer
            Num |= A_LoopField
    }
    TrayTip %Title%, %Text%,, %Num%
}
Type(Value)
{
    local m, f, e
    if IsObject(Value)
    {
        static nMatchObj  := NumGet(&(m, RegExMatch("", "O)", m)))
        static nBoundFunc := NumGet(&(f := Func("Func").Bind()))
        static nFileObj   := NumGet(&(f := FileOpen("*", "w")))
        static nEnumObj   := NumGet(&(e := ObjNewEnum({})))

        return ObjGetCapacity(Value) != ""  ? "Object"
             : IsFunc(Value)                ? "Func"
             : ComObjType(Value) != ""      ? "ComObject"
             : NumGet(&Value) == nBoundFunc ? "BoundFunc"
             : NumGet(&Value) == nMatchObj  ? "RegExMatchObject"
             : NumGet(&Value) == nFileObj   ? "FileObject"
             : NumGet(&Value) == nEnumObj   ? "Object::Enumerator"
             :                                "Property"
    }
    else if (ObjGetCapacity([Value], 1) != "")
        return "String"
    else
        return InStr(Value, ".") ? "Float" : "Integer"
}
WinActivate(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinActivate %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinActivateBottom(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinActivateBottom %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinClose(WinTitle:="", WinText:="", SecondsToWait:="", ExcludeTitle:="", ExcludeText:="")
{
    WinClose %WinTitle%, %WinText%, %SecondsToWait%, %ExcludeTitle%, %ExcludeText%
}
WinGetClass(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGetClass OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetControls(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ControlList, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return StrSplit(OutputVar, "`n")
}
WinGetControlsHwnd(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar, ControlsHwnd, i
    WinGet OutputVar, ControlListHwnd, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    ControlsHwnd := StrSplit(OutputVar, "`n")
    for i in ControlsHwnd
        ControlsHwnd[i] += 0
    return ControlsHwnd
}
WinGetCount(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, Count, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetExStyle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ExStyle, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar + 0
}
WinGetID(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar + 0
}
WinGetIDLast(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, IDLast, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar + 0
}
WinGetList(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar, List
    WinGet OutputVar, List, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    List := []
    Loop % OutputVar
        List.Push(OutputVar%A_Index% + 0)
    return List
}
WinGetMinMax(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, MinMax, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetPID(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, PID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinGetPos X, Y, Width, Height, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinGetProcessName(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ProcessName, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetProcessPath(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, ProcessPath, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetStyle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, Style, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar + 0
}
WinGetText(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGetText OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if !ErrorLevel
        return OutputVar
}
WinGetTitle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGetTitle OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetTransColor(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, TransColor, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinGetTransparent(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local OutputVar
    WinGet OutputVar, Transparent, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return OutputVar
}
WinHide(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinHide %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinKill(WinTitle:="", WinText:="", SecondsToWait:="", ExcludeTitle:="", ExcludeText:="")
{
    WinKill %WinTitle%, %WinText%, %SecondsToWait%, %ExcludeTitle%, %ExcludeText%
}
WinMaximize(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinMaximize %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMinimize(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinMinimize %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMinimizeAll()
{
    WinMinimizeAll
}
WinMinimizeAllUndo()
{
    WinMinimizeAllUndo
}
WinMove(Params*)
{
    local WinTitle, WinText, X, Y, Width, Height, ExcludeTitle, ExcludeText
    local Len
    if (Len := Params.Length())
    {
        if (Len > 2)
        {
            X            := Params[1]
            Y            := Params[2]
            Width        := Params[3]
            Height       := Params[4]
            WinTitle     := Params[5]
            WinText      := Params[6]
            ExcludeTitle := Params[7]
            ExcludeText  := Params[8]
            WinMove %WinTitle%, %WinText%, %X%, %Y%, %Width%, %Height%, %ExcludeTitle%, %ExcludeText%
        }
        else
        {
            X := Params[1]
            Y := Params[2]
            WinMove %X%, %y%
        }
    }
    else
        WinMove
}
WinMoveBottom(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Bottom,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMoveTop(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Top,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinRedraw(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Redraw,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinRestore(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinRestore %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinSetAlwaysOnTop(OnOffToggle:="Toggle", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    if OnOffToggle in 1,0,-1 ; On,Off,Toggle
        OnOffToggle := OnOffToggle == -1 ? "Toggle" : OnOffToggle ? "On" : "Off"

    if OnOffToggle not in On,Off,Toggle
        throw Exception("Parameter #1 invalid.", -1) ; v2 raises an error

    WinSet AlwaysOnTop, %OnOffToggle%, ahk_id %Hwnd%
    return 1
}
WinSetEnabled(Value, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    ; 1, 0 and -1 are compared as strings, non-integer values(e.g.: 1.0) are not allowed
    local Style
    if (Value = "Toggle" || Value == "-1")
    {
        WinGet Style, Style, ahk_id %Hwnd%
        Value := (Style & 0x8000000) ? "On" : "Off" ; WS_DISABLED = 0x8000000
    }

    if (Value = "On" || Value == "1")
        WinSet Enable,, ahk_id %Hwnd%
    else if (Value = "Off" || Value == "0")
        WinSet Disable,, ahk_id %Hwnd%
    else
        throw Exception("Paramter #1 invalid.", -1) ; v2 raises an error
    return 1
}
WinSetExStyle(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet ExStyle, %N%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinSetRegion(Options:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Region, %Options%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinSetStyle(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinSet Style, %N%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinSetTitle(Param:="", Params*)
{
    local WinTitle, WinText, NewTitle, ExcludeTitle, ExcludeText
    if (Params.Length())
    {
        NewTitle     := Param
        WinTitle     := Params[1]
        WinText      := Params[2]
        ExcludeTitle := Params[3]
        ExcludeText  := Params[4]
        WinSetTitle %WinTitle%, %WinText%, %NewTitle%, %ExcludeTitle%, %ExcludeText%
    }
    else
        WinSetTitle %Param% ; WinSetTitle, NewTitle
}
WinSetTransColor(ColorN, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    WinSet TransColor, %ColorN%, ahk_id %Hwnd%
    return 1
}
WinSetTransparent(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

    WinSet Transparent, %N%, ahk_id %Hwnd%
    return 1
}
WinShow(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    WinShow %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinWait(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWait %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinWaitActive(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWaitActive %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinWaitClose(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWaitClose %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}
WinWaitNotActive(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWaitNotActive %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return !ErrorLevel
}

;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
Location: Middle of the round cube
Contact:

Re: commands as functions (AHK v2 functions for AHK v1)

07 Sep 2017, 17:49

jeeswg wrote:

Code: Select all

MsgBox(p_text:="Press OK to continue", p_title:="", p_Options:="", ByRef r_PressedButtonVar:="")
{
; >> Return value === same as in v2, button that was pressed
; >> p_Options === same as in v2, box type numbers and timeout
; 		Separated by space or tab, number/numeric string for box type, seconds (int/float) preceded by T as string for timeout, e.g: "T4"
; 		If using a number as box type, it can be passed within a string e.g: Msgbox("text", "title", "4 T3", buttonPressed)
; 		Msgbox type can be an unquoted math expression, and if adding timeout, prefix/postfix timeout string with a space or tab
; 		e.g: Msgbox("text", "title", 2+16 " T3") or Msgbox("text", "title", "T3 " 2+16)
; 		Timeout is optional and the T in timeout string is case insensitive
; >> r_PressedButtonVar === same as in V2, optional ByRef variable for button that was pressed
;**************************************************************************************************
	; Array for box types numerical values from V2, initialized only once during runtime
	static boxTypeArray:={"OK": 0, "O": 0, "OKCancel": 1, "OC": 1, "O/C": 1, "AbortRetryIgnore": 2, "ARI": 2, "A/R/I": 2
		, "YesNoCancel": 3, "Y/N/C": 3, "YNC": 3, "YesNo": 4, "Y/N": 4, "YN": 4, "RetryCancel": 5, "R/C": 5, "RC": 5
		, "CancelTryAgainContinue": 6, "C/T/C": 6, "CTC": 6, "Iconx": 16, "Icon?": 32, "Icon!": 48, "Iconi": 64
		, "Default2": 256, "Default3": 512, "Default4": 768}
	timeout:="", boxType:=0
	if (p_options) {
		Loop, parse, p_Options, % A_Space A_Tab
			(k:=Abs(A_LoopField)) || (k:=boxTypeArray[A_LoopField]) ? boxType:=boxType+k ; if number (abs), add number to boxType var
				: RegexMatch(A_LoopField, "Oi)^t(\d+\.?\d*)$", timeMatch) ? timeout:=timeMatch.value(1) ; timeoutvar = numbers after the T
				: ("")
	}

	Msgbox, % boxType, % p_Title, % p_Text, % timeout
	Loop, Parse, % "Timeout,OK,Cancel,Yes,No,Abort,Ignore,Retry,Continue,TryAgain", % ","
		IfMsgbox, % r_PressedButtonVar:=A_LoopField
				break

	return r_PressedButtonVar
}

About this MsgBox() function.

What do you mean by ; >> r_PressedButtonVar === same as in V2, optional ByRef variable for button that was pressed ? Am I missing something?
try it and see
...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

07 Sep 2017, 18:07

That function was written by coffee (the only function I didn't write myself apart from perhaps InputBox and Type). Basically the variable should contain Yes/No etc based on which MsgBox button you clicked/pressed. AHK v2 doesn't use the IfMsgBox command.

Hmm, I don't see it here:
MsgBox
https://lexikos.github.io/v2/docs/commands/MsgBox.htm

Perhaps the function definition was changed. I might investigate ...

lexikos did a nice function for InputBox with some quite advanced RegEx, so I was waiting for him to do a nice function for MsgBox, rather than do one that was potentially lame by comparison. I'll review the current MsgBox function at some point. I'll try to rewrite it to match the other functions, hopefully within the next 24 hours.

[EDIT:]
AutoHotkey v2 alpha (UPDATES) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 36#p153136
•Removed MsgBox's redundant OutputVar.
==================================================

[EDIT:]
Well, the InputBox function's RegEx makes use of (*ACCEPT) which is mentioned here, but in the end isn't used in the MsgBox function at present.
Default/Portable installation StdLib - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 978#p74978
Default/Portable installation StdLib - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 262#p75262

I've changed the MsgBox function to make it more consistent with the other functions. The code hasn't really changed apart from replacing += with |=.

Code: Select all

MsgBox(Text:="Press OK to continue", Title:="", Options:="")
{
    local Timeout, BoxType, k, Result, TimeMatch
    static BoxTypeArray:={"OK": 0, "O": 0, "OKCancel": 1, "OC": 1, "O/C": 1, "AbortRetryIgnore": 2, "ARI": 2, "A/R/I": 2
        , "YesNoCancel": 3, "Y/N/C": 3, "YNC": 3, "YesNo": 4, "Y/N": 4, "YN": 4, "RetryCancel": 5, "R/C": 5, "RC": 5
        , "CancelTryAgainContinue": 6, "C/T/C": 6, "CTC": 6, "Iconx": 16, "Icon?": 32, "Icon!": 48, "Iconi": 64
        , "Default2": 256, "Default3": 512, "Default4": 768}
    Timeout := "", BoxType := 0
    if (Options)
    {
        Loop, Parse, Options, % " `t"
            (k:=Abs(A_LoopField)) || (k:=BoxTypeArray[A_LoopField]) ? (BoxType|=k)
                : RegExMatch(A_LoopField, "Oi)^t(\d+\.?\d*)$", TimeMatch) ? Timeout:=TimeMatch.Value(1)
                : ("")
    }
    MsgBox % BoxType, % Title, % Text, % Timeout
    Loop Parse, % "Timeout,OK,Cancel,Yes,No,Abort,Ignore,Retry,Continue,TryAgain", % ","
        IfMsgBox % Result:=A_LoopField
            break
    return Result
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 33 guests