commands as functions (AHK v2 functions for AHK v1)

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

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

21 Sep 2017, 17:17

Download: case-corrected 'URLDownloadToFile' to 'UrlDownloadToFile'
InputBox: first two parameters swapped
MsgBox: final parameter removed

Please notify of any issues.

Code: Select all

;AHK v2 functions for AHK v1
;[updated: 2017-09-21] Download, MsgBox, InputBox (major)
;[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(Text:="", Title:="", 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%, %Text%, % _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(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
}
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
}
[EDIT:] The MsgBox function needs to be corrected from:
Press OK to continue
to:
Press OK to continue.
The dot needs to be added. I will add this in the next release.

[EDIT:] The SendMessage and PostMessage functions need updating, they will be added to the next release.

Code: Select all

PostMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    PostMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    ErrorLevel := (ErrorLevel = "FAIL")
}
SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")
{
    local MsgReply
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    MsgReply := (ErrorLevel = "FAIL") ? "" : ErrorLevel
    ErrorLevel := (ErrorLevel = "FAIL")
    return MsgReply
}
Last edited by jeeswg on 14 Nov 2017, 17:25, edited 1 time in total.
iseahound
Posts: 355
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

05 Nov 2017, 23:30

Can you release the above post separately? Your first post has 7 different code boxes, and none of them are even up to date.

This will be useful to many people.
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

05 Nov 2017, 23:49

@iseahound: I've put a link to the latest version in the first post. Cheers.
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

28 Jan 2018, 23:26

I've updated the library, here are some summary notes.
- Added. I've added CaretGetPos, TraySetIcon and WinGetClientPos.
- Removed. I've removed Menu.
- MinParams. By using Func objects, I retrieved the minimum number of parameters for each function in AHK v2, and each of these clone functions, and adjusted any functions in this library accordingly.
- ComboBox/ListBox. There are 3 ControlXXX functions in this library that check the control class name. I've made it so that they check that the class name contains a string, rather than matches it exactly, as I've seen varying class names, that still work with the ControlXXX functions.
- PostMessage/SendMessage. These two functions have changed significantly, in what they return, and how they set ErrorLevel. Although it will require manual script conversion to use them, particularly for SendMessage, they are far more useful in their new forms.
- SoundGet/SoundSet. I realised that these cloned functions weren't working on my PC. I changed the default value for DeviceNumber from 1 to blank in the library.
- [EDIT:] Corrected ControlSetStyle/ControlShow and FileAppend.

Code: Select all

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

;AHK v2 functions for AHK v1
;[updated: 2018-01-29]

;use at your own risk
;warning: the RegDelete/RegDeleteKey/RegWrite functions are untested

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

;known issues/limitations:
;ClipboardAll - binary variable
;FileAppend - binary variable (RAW)
;FileInstall - will only perform a FileCopy
;FileRead - binary variable (RAW)
;InputBox - password character
;ListVars - can only list global variables
;Type - doesn't fully match AHK v2 function
;WinGetClientPos - not giving the same results as AHK v2

;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%
}
CaretGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="")
{
    OutputVarX := A_CaretX, OutputVarY := A_CaretY
}
Click(Params*)
{
    local i, Param, Args
    for i, Param in Params
        Args .= " " . Param
    Click %Args%
}
ClipboardAll(Data:="", Size:="")
{
    ;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 InStr(Class, "ListBox")
        SendMessage 0x18B, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCOUNT
    else if InStr(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 InStr(Class, "ListBox")
        SendMessage 0x185, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_SETSEL
    else if InStr(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 InStr(Class, "ListBox")
        SendMessage 0x188, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCURSEL
    else InStr(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(Keys, Control:="", 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 Style, %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 Show,, %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)
{
    Drive Lock, %Drive%
}
DriveSetLabel(Drive, NewLabel:="")
{
    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) " "
        else if (SubStr(A_LoopField, 1, 5) = "UTF-8")
            Options2 .= "*P65001 "
        else if (SubStr(A_LoopField, 1, 6) = "UTF-16")
            Options2 .= "*P1200 "
    }
    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(Text:="", Title:="", 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%, %Text%, % _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
}
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(Text:="Press OK to continue.", Title:="", Options:="")
{
    local Timeout, Type, k, Result, TimeMatch
    static TypeArray:={"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 := "", Type := 0
    if (Options)
    {
        Loop, Parse, Options, % " `t"
            (k:=Abs(A_LoopField)) || (k:=TypeArray[A_LoopField]) ? (Type|=k)
                : RegExMatch(A_LoopField, "Oi)^t(\d+\.?\d*)$", TimeMatch) ? Timeout:=TimeMatch.Value(1)
                : ("")
    }
    MsgBox % Type, % Title, % Text, % Timeout
    Loop Parse, % "Timeout,OK,Cancel,Yes,No,Abort,Ignore,Retry,Continue,TryAgain", % ","
        IfMsgBox % Result:=A_LoopField
            break
    return Result
}
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%
    ErrorLevel := (ErrorLevel = "FAIL")
    ;PostMessage returns an empty string.
}
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(Params*) ;KeyName, ValueName
{
    ;MsgBox, % "REGDELETE"
    if (Params.Length() = 1)
        Params[2] := "AHK_DEFAULT"
    if Params.Length()
    {
        if InStr(Params[3], "\")
            RegDelete % Params[1], % Params[2]
        else
            RegDelete % Params[1],, % Params[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:="")
{
    ;MsgBox, % "REGDELETEKEY"
    if !(A_LoopRegSubkey = "")
        RegDelete %A_LoopRegKey%
    else if !(A_LoopRegKey = "")
        RegDelete %A_LoopRegKey%\%A_LoopRegSubkey%
    else
        RegDelete %KeyName%
    return !ErrorLevel
}
RegRead(Params*) ;KeyName, ValueName
{
    local OutputVar
    if Params.Length()
    {
        if InStr(Params[1], "\")
            RegRead OutputVar, % Params[1], % Params[2]
        else
            RegRead OutputVar, % Params[1],, % Params[2]
    }
    else
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegRead OutputVar, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%
    }
    if !ErrorLevel
        return OutputVar
}
RegWrite(Params*) ;Value, ValueType, KeyName, ValueName
{
    ;if !(Params.3 = "HKEY_CURRENT_USER\Software\Microsoft\Notepad")
        ;MsgBox, % "REGWRITE`r`n" JEE_ObjPreview(Params)
    if (Params.Length() > 2)
    {
        if InStr(Params[3], "\")
            RegWrite % Params[2], % Params[3], % Params[4], % Params[1]
        else
            RegWrite % Params[2], % Params[3],, % Params[4], % Params[1]
    }
    else if (Params.Length() = 1)
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, % Params[1]
    }
    else if (Params.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:="")
{
    local MsgReply
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    MsgReply := (ErrorLevel = "FAIL") ? "" : ErrorLevel
    ErrorLevel := (ErrorLevel = "FAIL")
    return MsgReply
}
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:="")
{
    local OutputVar
    SoundGet OutputVar, %ComponentType%, %ControlType%, %DeviceNumber%
    if !ErrorLevel
        return OutputVar
}
SoundPlay(Filename, Wait:="")
{
    SoundPlay %Filename%, %Wait%
    return !ErrorLevel
}
SoundSet(NewSetting, ComponentType:="", ControlType:="", DeviceNumber:="")
{
    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%
}
TraySetIcon(FileName:="", IconNumber:="", Freeze:="")
{
    Menu Tray, Icon, %FileName%, %IconNumber%, %Freeze%
}
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
}
WinGetClientPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local hWnd, RECT
    hWnd := WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText)
    VarSetCapacity(RECT, 16, 0)
    DllCall("user32\GetClientRect", Ptr,hWnd, Ptr,&RECT)
    DllCall("user32\ClientToScreen", Ptr,hWnd, Ptr,&RECT)
    X := NumGet(&RECT, 0, "Int"), Y := NumGet(&RECT, 4, "Int")
    Width := NumGet(&RECT, 8, "Int"), Height := NumGet(&RECT, 12, "Int")
}
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*) ;X, Y [, Width, Height, WinTitle, WinText, ExcludeTitle, ExcludeText]
{
    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(NewTitle, Params*) ;NewTitle [, WinTitle, WinText, ExcludeTitle, ExcludeText]
{
    local WinTitle, WinText, ExcludeTitle, ExcludeText
    if (Params.Length())
    {
        WinTitle     := Params[1]
        WinText      := Params[2]
        ExcludeTitle := Params[3]
        ExcludeText  := Params[4]
        WinSetTitle %WinTitle%, %WinText%, %NewTitle%, %ExcludeTitle%, %ExcludeText%
    }
    else
        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:] Auxiliary functions expansion pack first release. These make it easier/possible to write two-way compatible scripts/functions.

Code: Select all

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

;AHK v2 functions for AHK v1
;auxiliary functions expansion pack
;these functions are AHK v1/v2 two-way compatible
;[first released: 2018-02-21]

;- operators:
;JEE_Between
;JEE_MC
;JEE_MX
;JEE_StrIsType
;- raw read/write:
;JEE_ClipboardFromFile
;JEE_ClipboardToFile
;JEE_FileReadBin
;JEE_FileWriteBin
;- other:
;JEE_ComObjMissing
;JEE_InStr
;JEE_RegExMatch
;JEE_RegExReplace
;JEE_SubStr

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

;if vNum between %vLim1% and %vLim2%
JEE_Between(vNum, vLim1, vLim2, vOpt="ii")
{
	if (vOpt = "ii")
		return (vLim1 <= vNum && vNum <= vLim2)
	if (vOpt = "xx")
		return (vLim1 < vNum && vNum < vLim2)
	if (vOpt = "xi")
		return (vLim1 < vNum && vNum <= vLim2)
	if (vOpt = "ix")
		return (vLim1 <= vNum && vNum < vLim2)
}

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

;set clipboard contents based on a clp file
JEE_ClipboardFromFile(vPath)
{
	static vFunc := "ClipboardAll", vFunc2 := "FileRead"
	if !(SubStr(A_AhkVersion, 1, 2) = "1.")
		Clipboard := %vFunc%(%vFunc2%(vPath, "RAW"))
	else
	{
		if !oFile := FileOpen(vPath, "r")
			return
		hWnd := A_ScriptHwnd ? A_ScriptHwnd : WinExist("ahk_pid " DllCall("kernel32\GetCurrentProcessId", UInt))
		DllCall("user32\OpenClipboard", Ptr,hWnd)
		DllCall("user32\EmptyClipboard")
		oFile.Pos := 0
		while (vFormat := oFile.ReadUIntType())
		{
			;GMEM_ZEROINIT := 0x40, GMEM_MOVEABLE := 0x2
			vSize := oFile.ReadUIntType()
			hData := DllCall("kernel32\GlobalAlloc", UInt,0x42, UPtr,vSize, Ptr)
			pData := DllCall("kernel32\GlobalLock", Ptr,hData, Ptr)
			oFile.RawRead(pData+0, vSize)
			DllCall("user32\SetClipboardData", UInt,vFormat, Ptr,hData, Ptr)
			DllCall("kernel32\GlobalUnlock", Ptr,hData)
		}
		DllCall("user32\CloseClipboard")
		oFile.Close()
	}
}

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

;save current clipboard contents to a clp file
JEE_ClipboardToFile(vPath)
{
	static vFunc := "ClipboardAll"
	if !oFile := FileOpen(vPath, "w") ;empties file
		return
	if !(SubStr(A_AhkVersion, 1, 2) = "1.")
		oFile.RawWrite(%vFunc%().Data)
	else
	{
		ClipSaved := ClipboardAll
		vSize := StrLen(ClipSaved) << !!A_IsUnicode
		oFile.RawWrite(&ClipSaved, vSize) ;appends data, advances pointer
	}
	oFile.Close()
}

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

;conversion logic, v1 = -> v1 := -> v2, two-way compatibility - Page 3 - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=27069&p=131336#p131336
;One of my favorite error codes: Optional parameter missing – The Old New Thing
;https://blogs.msdn.microsoft.com/oldnewthing/20140129-00/?p=1933/

JEE_ComObjMissing()
{
	;VT_ERROR := 0xA ;DISP_E_PARAMNOTFOUND := 0x80020004
	return ComObject(0xA, 0x80020004)
}

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

JEE_FileReadBin(ByRef vData, vPath)
{
	oFile := FileOpen(vPath, "r")
	oFile.Pos := 0
	oFile.RawRead(vData, oFile.Length)
	oFile.Close()
}

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

JEE_FileWriteBin(ByRef vData, vSize, vPath)
{
	if !oFile := FileOpen(vPath, "w") ;empties file
		return
	oFile.RawWrite(&vData, vSize) ;appends data, advances pointer
	oFile.Close()
}

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

;works like InStr (AHK v2) (on AHK v1/v2)
JEE_InStr(ByRef vText, vNeedle, vCaseSen:=0, vPos:=1, vOcc:=1)
{
	static vIsV1 := !!InStr(1,1,1,0)
	if (vPos = 0)
		return
	if vIsV1 && (vPos <= -1)
		vPos++
	return InStr(vText, vNeedle, vCaseSen, vPos, vOcc)
}

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

;string contains one of comma-separated list
;unlike AHK v1: no special handling for ',,'
JEE_MC(ByRef vText, ByRef vNeedles)
{
	;Loop is not two-way compatible at present
	;Loop, Parse, vNeedles, % ","
	;	if InStr(vText, A_LoopField)
	;		return A_Index
	for vKey, vValue in StrSplit(vNeedles, ",")
		if InStr(vText, vValue)
			return vKey
	return 0
}

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

;exact match, comma-separated list
JEE_MX(ByRef vText, ByRef vNeedles)
{
	;Loop is not two-way compatible at present
	;Loop, Parse, vNeedles, % ","
	;	if !("" vText != A_LoopField)
	;		return A_Index
	for vKey, vValue in StrSplit(vNeedles, ",")
		if !("" vText != vValue)
			return vKey
	return 0
}

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

;works like RegExMatch (AHK v2) (on AHK v1/v2)
JEE_RegExMatch(ByRef vText, vNeedle, ByRef oArray:="", vPos:=1)
{
	;we're not interested in the return value, but we need it to get RegExMatch to take place
	static vRet := RegExMatch("","",o), vIsV1 := !IsObject(o)
	if !vIsV1
		return RegExMatch(vText, vNeedle, oArray, vPos)
	if (vPos = 0)
		return
	if vIsV1 && (vPos <= -1)
		vPos++
	if RegExMatch(vNeedle, "^[A-Za-z`a`n`r `t]*\)")
		vNeedle := "O" vNeedle
	else
		vNeedle := "O)" vNeedle
	return RegExMatch(vText, vNeedle, oArray, vPos)
}

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

;works like RegExReplace (AHK v2) (on AHK v1/v2)
JEE_RegExReplace(ByRef vText, vNeedle, vReplaceText, ByRef vCount, vLimit:=-1, vPos:=1)
{
	static vIsV1 := !RegExReplace(10, 1,,,, -1)
	if (vPos = 0)
		return
	if vIsV1 && (vPos <= -1)
		vPos++
	return RegExReplace(vText, vNeedle, vReplaceText, vCount, vLimit, vPos)
}

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

;If Var is [not] integer|float|number|digit|xdigit|alpha|upper|lower|alnum|space|time
;e.g. if JEE_StrIsType(vText, "digit")
JEE_StrIsType(vText, vType)
{
	%vType% := vType ;for AHK v2
	;if JEE_StrIsType(vText, vType) ;[appearance of line below if converted, warning: this would cause an infinite loop]
	if vText is %vType% ;[DO NOT CONVERT]
		return 1
	else
		return 0
}

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

;works like SubStr (AHK v2) (on AHK v1/v2)
JEE_SubStr(ByRef vText, vPos, vLen:="")
{
	static vIsV1 := !!SubStr(1,0)
	if (vPos = 0)
		return
	if vIsV1 && (vPos <= -1)
		vPos++
	if (vLen = "")
		return SubStr(vText, vPos)
	return SubStr(vText, vPos, vLen)
}

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

- [EDIT:] Modifications that will appear in the next release: CaretGetPos.
- Note: Custom CaretGetPos function based no:
convert coordinates between Client/Screen/Window modes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 58#p177058

Code: Select all

CaretGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="")
{
    hWnd := WinExist("A")
    VarSetCapacity(GUITHREADINFO, A_PtrSize=8?72:48, 0)
    NumPut(A_PtrSize=8?72:48, &GUITHREADINFO, 0, "UInt") ;cbSize
    TID := DllCall("user32\GetWindowThreadProcessId", Ptr,hWnd, UIntP,0, UInt)
    DllCall("user32\GetGUIThreadInfo", UInt,TID, Ptr,&GUITHREADINFO)
    hWndC := NumGet(&GUITHREADINFO, A_PtrSize=8?48:28, "Ptr") ;hwndCaret
    OutputVarX := NumGet(&GUITHREADINFO, A_PtrSize=8?56:32, "Int") ;rcCaret ;x
    OutputVarY := NumGet(&GUITHREADINFO, A_PtrSize=8?60:36, "Int") ;rcCaret ;y
    Mode := SubStr(A_CoordModeCaret, 1, 1)
    VarSetCapacity(POINT, 8)
    NumPut(OutputVarX, &POINT, 0, "Int")
    NumPut(OutputVarY, &POINT, 4, "Int")
    DllCall("user32\ClientToScreen", Ptr,hWndC, Ptr,&POINT)
    OutputVarX := NumGet(&POINT, 0, "Int")
    OutputVarY := NumGet(&POINT, 4, "Int")
    if (Mode = "S") ;screen
        return
    else if (Mode = "C") ;client
    {
        VarSetCapacity(POINT, 8, 0)
        DllCall("user32\ClientToScreen", Ptr,hWnd, Ptr,&POINT)
        OriginX := NumGet(&POINT, 0, "Int")
        OriginY := NumGet(&POINT, 4, "Int")
    }
    else if (Mode = "W") ;window
    {
        VarSetCapacity(RECT, 16, 0)
        DllCall("user32\GetWindowRect", Ptr,hWnd, Ptr,&RECT)
        OriginX := NumGet(&RECT, 0, "Int")
        OriginY := NumGet(&RECT, 4, "Int")
    }
    OutputVarX -= OriginX, OutputVarY -= OriginY
}
- [EDIT:] Additions that will appear in the next release: A_TrayMenu.ClickCount.

Code: Select all

;A_TrayMenu.ClickCount
class A_TrayMenu
{
	static varClickCount := 2
	ClickCount[]
	{
		get
		{
			return this.varClickCount
		}
		set
		{
			Menu, Tray, Click, % value
			return this.varClickCount := value
		}
	}
}
Last edited by jeeswg on 05 Mar 2018, 09:38, edited 3 times in total.
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

13 Feb 2018, 00:35

- I've corrected ControlSetStyle and FileAppend. These are two important corrections so I've corrected the latest version of the script posted above directly, instead of waiting for the next full release.
- The issue with FileAppend was that it might have been using the wrong encoding e.g. ANSI instead of UTF-8/UTF-16. Btw be careful with file encodings generally in standard AutoHotkey, because you might specify an encoding, but AutoHotkey will overrule it (if the file already exists and has a byte order mark).
- I will be creating a large test script, to be run on both AHK v2, and on 'AHK v1+AHK v2 functions', to check that they are both giving the same results. I mention this in case anyone has already created such a script that I can compare it with.
- Note: always double-check when using these functions for the first time, and always double-check when using functions on important data, especially functions that relate to registry loops or modifying the registry.
User avatar
Drugwash
Posts: 642
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

13 Feb 2018, 09:40

Thank you for reminding me about GetGUIThreadInfo() which set me on the right track.
However, this CaretGetPos() function as it is has a major flaw: it cannot retrieve the coordinates of the caret if the control isn't focused. And I specifically needed that in a script of mine.
So in order for it to be complete, I'd add a forcedHwnd parameter to it:

Code: Select all

CaretGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="", forcedHwnd:="")
{
    if forcedHwnd
      {
      hPwin := DllCall("SetFocus", "Ptr", forcedHwnd, "Ptr")
      hWnd := forcedHwnd
      }
    else hWnd := WinExist("A")
    VarSetCapacity(GUITHREADINFO, A_PtrSize=8?72:48, 0)
    NumPut(A_PtrSize=8?72:48, &GUITHREADINFO, 0, "UInt") ;cbSize
    TID := DllCall("user32\GetWindowThreadProcessId", "Ptr",hWnd, "UIntP",0, UInt)
    DllCall("user32\GetGUIThreadInfo", "UInt",TID, "Ptr",&GUITHREADINFO)
    if hPwin
      DllCall("SetFocus", "Ptr", hPwin, "Ptr")
    […]
}
That way the user could direct the function to retrieve the caret position from a specific control by feeding it with that control's handle and by briefly setting focus to that control (and restoring it afterwards).

Also I'm not sure about the calculations you do between Client/Screen/Window. GetGUIThreadInfo() already returns client coordinates relative to the focused control. If the user wants precisely those coordinates - not relative to the main window - then he's in a bit of a trouble.
So I'd say in case the forcedHwnd parameter is present (and valid), the client coordinates should be returned as is, maybe even regardless of A_CoordModeCaret. Otherwise the user would have to recreate the whole function with the desired modifications and that would just be a waste of time.

There's also no return value. If for some reason any of the handles is invalid, there's no focused control or GetGuiThreadInfo() fails, the function should return False, otherwise it should return True - that should differentiate between success and failure when coordinates are identical on both input and output.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

13 Feb 2018, 15:59

- Thanks for your comments Drugwash.
- I've made a slight modification to my original JEE_CaretGetPos function, to allow specifying an hWnd, which you can find here:
convert coordinates between Client/Screen/Window modes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 23#p200323
- If you want to, on that thread, you can propose an amended function that provides a return value.
- My JEE_CaretGetPos function does allow you to retrieve the original caret coordinates, although the AHK v2 CaretGetPos function (and my clone of it) does not.
- The main thing I want to know about, in this thread re. functions, is whenever one of the functions in this library gives different results to AHK v2 (apart from in any special circumstances which I have mentioned e.g. InputBox's hide character). If you want the AHK v2 functions themselves to be changed/improved, then that would have to go in the Wish List forum, or a custom function would have to be made like the one I've mentioned.
- Thanks for reminding me about return values. In this link it is mentioned that the return values need to be reviewed for various AHK v2 functions:
v2-thoughts
https://autohotkey.com/v2/v2-thoughts.htm
I will compare the return values for this library with the AHK v2 functions, when I produce my massive test script, to test all functions. One thing I'd hope for, in the AHK v2 functions, is to return an hWnd if WinWait/WinWaitActive are successful. Cheers.
User avatar
Drugwash
Posts: 642
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

13 Feb 2018, 16:14

You're welcome.
Actually I don't care much about v2 since it's breaking too much away from the original AHK - just wanted to share my thoughts while I was here. Feel free to forward the ideas/observations I made above wherever appropriate if you feel they're worth mentioning. :)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
lexikos
Posts: 6207
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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

17 Feb 2018, 17:30

Drugwash wrote:it cannot retrieve the coordinates of the caret if the control isn't focused.
It cannot retrieve the coordinates of the caret if there is no caret. The control creates the caret when you focus it and destroys it when the control loses focus. What you are getting is not the position of the caret, but the position the caret would be in if the control was (still) focused.
User avatar
Drugwash
Posts: 642
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

18 Feb 2018, 02:28

That is technically true, the other technique using EM_* messages retrieves the position of the selection in the (Rich)Edit control, not the position of the invisible/nonexistant caret. Nonetheless, that position may be of critical interest in certain scripts and I believe there should be this - let's call it "unorthodox" - possibility to retrieve it, for completeness sake.

This is all necessary because EM_POSFROMCHAR returns -1 when caret/selection is beyond last character and there's no other way to retrieve the actual caret position in pixels.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

29 Mar 2018, 00:30

Added. CallbackCreate, CallbackFree, A_TrayMenu.ClickCount.
Modified. CaretGetPos, MsgBox.
Modified. Return hWnd: WinWait, WinWaitActive (I've assumed that WinWait/WinWaitActive will return an hWnd in future).
Modified. Support numbers: DetectHiddenText, DetectHiddenWindows, ListLines, Pause, SetCapsLockState, SetNumLockState, SetScrollLockState, SetStoreCapsLockMode, Suspend.
Tidied. WinSetAlwaysOnTop.
Please notify of any issues re. CallbackCreate and CallbackFree.

Code: Select all

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

;AHK v2 functions for AHK v1
;[updated: 2018-03-29]

;use at your own risk
;warning: the RegDelete/RegDeleteKey/RegWrite functions are untested

;link:
;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689

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

;known issues/limitations:
;CallbackCreate - less functionality than the AHK v2 function
;ClipboardAll - binary variable
;FileAppend - binary variable (RAW)
;FileInstall - will only perform a FileCopy
;FileRead - binary variable (RAW)
;InputBox - password character
;ListVars - can only list global variables
;(PostMessage/SendMessage) - currently do not support Var to mean &Var
;Type - doesn't fully match AHK v2 function
;WinGetClientPos - not giving the same results as AHK v2
;(WinWait/WinWaitActive) - I've assumed that WinWait/WinWaitActive will return an hWnd in future

;see also (re. functions):
;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

;see also (re. GUIs):
;objects: backport AHK v2 Gui/Menu classes to AHK v1 - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=43530

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

BlockInput(Mode)
{
    BlockInput %Mode%
}
CallbackCreate(Function, Options:="", ParamCount:="")
{
    return RegisterCallback(Function, Options, ParamCount)
}
CallbackFree(Address)
{
    DllCall("kernel32\GlobalFree", Ptr,Address, Ptr)
}
CaretGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="")
{
    local GUITHREADINFO, hWnd, hWndC, Mode, OriginX, OriginY, POINT, RECT, TID
    ;this works but there was an issue regarding A_CaretX/A_CaretY not updating correctly:
    ;OutputVarX := A_CaretX, OutputVarY := A_CaretY
    hWnd := WinExist("A")
    VarSetCapacity(GUITHREADINFO, A_PtrSize=8?72:48, 0)
    NumPut(A_PtrSize=8?72:48, &GUITHREADINFO, 0, "UInt") ;cbSize
    TID := DllCall("user32\GetWindowThreadProcessId", Ptr,hWnd, UIntP,0, UInt)
    DllCall("user32\GetGUIThreadInfo", UInt,TID, Ptr,&GUITHREADINFO)
    hWndC := NumGet(&GUITHREADINFO, A_PtrSize=8?48:28, "Ptr") ;hwndCaret
    OutputVarX := NumGet(&GUITHREADINFO, A_PtrSize=8?56:32, "Int") ;rcCaret ;x
    OutputVarY := NumGet(&GUITHREADINFO, A_PtrSize=8?60:36, "Int") ;rcCaret ;y
    Mode := SubStr(A_CoordModeCaret, 1, 1)
    VarSetCapacity(POINT, 8)
    NumPut(OutputVarX, &POINT, 0, "Int")
    NumPut(OutputVarY, &POINT, 4, "Int")
    DllCall("user32\ClientToScreen", Ptr,hWndC, Ptr,&POINT)
    OutputVarX := NumGet(&POINT, 0, "Int")
    OutputVarY := NumGet(&POINT, 4, "Int")
    if (Mode = "S") ;screen
        return
    else if (Mode = "C") ;client
    {
        VarSetCapacity(POINT, 8, 0)
        DllCall("user32\ClientToScreen", Ptr,hWnd, Ptr,&POINT)
        OriginX := NumGet(&POINT, 0, "Int")
        OriginY := NumGet(&POINT, 4, "Int")
    }
    else if (Mode = "W") ;window
    {
        VarSetCapacity(RECT, 16, 0)
        DllCall("user32\GetWindowRect", Ptr,hWnd, Ptr,&RECT)
        OriginX := NumGet(&RECT, 0, "Int")
        OriginY := NumGet(&RECT, 4, "Int")
    }
    OutputVarX -= OriginX, OutputVarY -= OriginY
}
Click(Params*)
{
    local i, Param, Args
    for i, Param in Params
        Args .= " " . Param
    Click %Args%
}
ClipboardAll(Data:="", Size:="")
{
    ;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 InStr(Class, "ListBox")
        SendMessage 0x18B, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCOUNT
    else if InStr(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 InStr(Class, "ListBox")
        SendMessage 0x185, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_SETSEL
    else if InStr(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 InStr(Class, "ListBox")
        SendMessage 0x188, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCURSEL
    else InStr(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(Keys, Control:="", 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 Style, %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 Show,, %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)
{
    if OnOrOff in 1,0
        OnOrOff := OnOrOff ? "On" : "Off"
    DetectHiddenText %OnOrOff%
}
DetectHiddenWindows(OnOrOff)
{
    if OnOrOff in 1,0
        OnOrOff := OnOrOff ? "On" : "Off"
    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)
{
    Drive Lock, %Drive%
}
DriveSetLabel(Drive, NewLabel:="")
{
    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) " "
        else if (SubStr(A_LoopField, 1, 5) = "UTF-8")
            Options2 .= "*P65001 "
        else if (SubStr(A_LoopField, 1, 6) = "UTF-16")
            Options2 .= "*P1200 "
    }
    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(Text:="", Title:="", 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%, %Text%, % _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:="")
{
    if OnOrOff in 1,0
        OnOrOff := OnOrOff ? "On" : "Off"
    ListLines %OnOrOff%
}
ListVars()
{
    ; Limitation -> won't work if called from within a function
    global
    ListVars
}
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*) ;Text, Title, Options
{
    local Match, Options, Result, Temp, Text, Timeout, Title, Type
    static TypeArray := {"OK":0, "O":0, "OKCancel":1, "O/C":1, "OC":1, "AbortRetryIgnore":2, "A/R/I":2, "ARI":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}

    Text := !Params.Length() ? "Press OK to continue." : Params.HasKey(1) ? Params.1 : ""
    Title := Params.HasKey(2) ? Params.2 : A_ScriptName
    Options := Params.3, Timeout := "", Type := 0
    if (Options)
    {
        Loop, Parse, Options, % " `t"
            (Temp := Abs(A_LoopField)) || (Temp := TypeArray[A_LoopField]) ? (Type |= Temp)
                : RegExMatch(A_LoopField, "Oi)^T(\d+\.?\d*)$", Match) ? Timeout := Match.1
                : 0
    }
    MsgBox % Type, % Title, % Text, % Timeout
    Loop Parse, % "Timeout,OK,Cancel,Yes,No,Abort,Ignore,Retry,Continue,TryAgain", % ","
        IfMsgBox % Result := A_LoopField
            break
    return Result
}
OutputDebug(Text)
{
    OutputDebug %Text%
}
Pause(Mode:="", OperateOnUnderlyingThread:=0)
{
    if Mode in 1,0,-1 ; On,Off,Toggle
        Mode := Mode == -1 ? "Toggle" : Mode ? "On" : "Off"
    Pause %Mode%, %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%
    ErrorLevel := (ErrorLevel = "FAIL")
    ;PostMessage returns an empty string.
}
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(Params*) ;KeyName, ValueName
{
    ;MsgBox, % "REGDELETE"
    if (Params.Length() = 1)
        Params[2] := "AHK_DEFAULT"
    if Params.Length()
    {
        if InStr(Params[3], "\")
            RegDelete % Params[1], % Params[2]
        else
            RegDelete % Params[1],, % Params[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:="")
{
    ;MsgBox, % "REGDELETEKEY"
    if !(A_LoopRegSubkey = "")
        RegDelete %A_LoopRegKey%
    else if !(A_LoopRegKey = "")
        RegDelete %A_LoopRegKey%\%A_LoopRegSubkey%
    else
        RegDelete %KeyName%
    return !ErrorLevel
}
RegRead(Params*) ;KeyName, ValueName
{
    local OutputVar
    if Params.Length()
    {
        if InStr(Params[1], "\")
            RegRead OutputVar, % Params[1], % Params[2]
        else
            RegRead OutputVar, % Params[1],, % Params[2]
    }
    else
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegRead OutputVar, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%
    }
    if !ErrorLevel
        return OutputVar
}
RegWrite(Params*) ;Value, ValueType, KeyName, ValueName
{
    ;if !(Params.3 = "HKEY_CURRENT_USER\Software\Microsoft\Notepad")
        ;MsgBox, % "REGWRITE`r`n" JEE_ObjPreview(Params)
    if (Params.Length() > 2)
    {
        if InStr(Params[3], "\")
            RegWrite % Params[2], % Params[3], % Params[4], % Params[1]
        else
            RegWrite % Params[2], % Params[3],, % Params[4], % Params[1]
    }
    else if (Params.Length() = 1)
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, % Params[1]
    }
    else if (Params.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:="")
{
    local MsgReply
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    MsgReply := (ErrorLevel = "FAIL") ? "" : ErrorLevel
    ErrorLevel := (ErrorLevel = "FAIL")
    return MsgReply
}
SendMode(Mode)
{
    SendMode %Mode%
}
SendPlay(Keys)
{
    SendPlay %Keys%
}
SendRaw(Keys)
{
    SendRaw %Keys%
}
SetCapsLockState(State:="")
{
    if State in 1,0
        State := State ? "On" : "Off"
    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:="")
{
    if State in 1,0
        State := State ? "On" : "Off"
    SetNumLockState %State%
}
SetRegView(RegView)
{
    SetRegView %RegView%
}
SetScrollLockState(State:="")
{
    if State in 1,0
        State := State ? "On" : "Off"
    SetScrollLockState %State%
}
SetStoreCapsLockMode(OnOrOff)
{
    if OnOrOff in 1,0
        OnOrOff := OnOrOff ? "On" : "Off"
    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:="")
{
    local OutputVar
    SoundGet OutputVar, %ComponentType%, %ControlType%, %DeviceNumber%
    if !ErrorLevel
        return OutputVar
}
SoundPlay(Filename, Wait:="")
{
    SoundPlay %Filename%, %Wait%
    return !ErrorLevel
}
SoundSet(NewSetting, ComponentType:="", ControlType:="", DeviceNumber:="")
{
    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")
{
    if Mode in 1,0,-1 ; On,Off,Toggle
        Mode := Mode == -1 ? "Toggle" : Mode ? "On" : "Off"
    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%
}
TraySetIcon(FileName:="", IconNumber:="", Freeze:="")
{
    Menu Tray, Icon, %FileName%, %IconNumber%, %Freeze%
}
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
}
WinGetClientPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local hWnd, RECT
    hWnd := WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText)
    VarSetCapacity(RECT, 16, 0)
    DllCall("user32\GetClientRect", Ptr,hWnd, Ptr,&RECT)
    DllCall("user32\ClientToScreen", Ptr,hWnd, Ptr,&RECT)
    X := NumGet(&RECT, 0, "Int"), Y := NumGet(&RECT, 4, "Int")
    Width := NumGet(&RECT, 8, "Int"), Height := NumGet(&RECT, 12, "Int")
}
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*) ;X, Y [, Width, Height, WinTitle, WinText, ExcludeTitle, ExcludeText]
{
    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(Value:="Toggle", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

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

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

    WinSet AlwaysOnTop, %Value%, 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(NewTitle, Params*) ;NewTitle [, WinTitle, WinText, ExcludeTitle, ExcludeText]
{
    local WinTitle, WinText, ExcludeTitle, ExcludeText
    if (Params.Length())
    {
        WinTitle     := Params[1]
        WinText      := Params[2]
        ExcludeTitle := Params[3]
        ExcludeText  := Params[4]
        WinSetTitle %WinTitle%, %WinText%, %NewTitle%, %ExcludeTitle%, %ExcludeText%
    }
    else
        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 ? 0 : WinExist()
}
WinWaitActive(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWaitActive %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return ErrorLevel ? 0 : WinExist()
}
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
}

;A_TrayMenu.ClickCount
class A_TrayMenu
{
	static varClickCount := 2
	ClickCount[]
	{
		get
		{
			return this.varClickCount
		}
		set
		{
			Menu, Tray, Click, % value
			return this.varClickCount := value
		}
	}
}

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

;old version:
;CaretGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="")
;{
;    OutputVarX := A_CaretX, OutputVarY := A_CaretY
;}

;hoped-for version (with added Format parameter):
;DateAdd(DateTime, Time, TimeUnits, Format:="yyyyMMddHHmmss")
;{
;    EnvAdd DateTime, %Time%, %TimeUnits%
;    if !(Format == "yyyyMMddHHmmss")
;        FormatTime DateTime, %DateTime%, %Format%
;    return DateTime
;}

;==================================================
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

05 Apr 2018, 20:09

UPDATE. I've been running various tests on the library (details are in the post below), and have thus identified and resolved some issues.
Fixed (handle 1 and 0): BlockInput.
Fixed (return dec not hex): MouseGetPos.
Fixed (handle omitted parameters): InputBox, IniDelete, TrayTip.
Fixed: ControlDeleteItem, FileAppend, IniRead, MsgBox, RegDelete.

Code: Select all

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

;AHK v2 functions for AHK v1
;[first released: 2017-03-26]
;[updated: 2018-04-05]

;use at your own risk
;warning: the RegDelete/RegDeleteKey/RegWrite functions are untested

;link:
;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689

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

;known issues/limitations:
;CallbackCreate - less functionality than the AHK v2 function
;ClipboardAll - binary variable
;FileAppend - binary variable (RAW)
;FileInstall - will only perform a FileCopy
;FileRead - binary variable (RAW)
;(IniRead) - AHK v2 handles a default value of multiple spaces as a blank
;InputBox - password character
;InputEnd - doesn't fully match AHK v2 function
;ListVars - can only list global variables
;(PostMessage/SendMessage) - currently do not support Var to mean &Var
;Type - doesn't fully match AHK v2 function (and misidentifies a Float as a String)
;WinGetClientPos - not giving the same results as AHK v2
;(WinWait/WinWaitActive) - I've assumed that WinWait/WinWaitActive will return an hWnd in future

;see also (re. functions):
;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

;see also (re. GUIs):
;objects: backport AHK v2 Gui/Menu classes to AHK v1 - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=43530

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

BlockInput(Mode)
{
    if Mode in 1,0
        Mode := Mode ? "On" : "Off"
    BlockInput %Mode%
}
CallbackCreate(Function, Options:="", ParamCount:="")
{
    return RegisterCallback(Function, Options, ParamCount)
}
CallbackFree(Address)
{
    DllCall("kernel32\GlobalFree", Ptr,Address, Ptr)
}
CaretGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="")
{
    local GUITHREADINFO, hWnd, hWndC, Mode, OriginX, OriginY, POINT, RECT, TID
    ;this works but there was an issue regarding A_CaretX/A_CaretY not updating correctly:
    ;OutputVarX := A_CaretX, OutputVarY := A_CaretY
    hWnd := WinExist("A")
    VarSetCapacity(GUITHREADINFO, A_PtrSize=8?72:48, 0)
    NumPut(A_PtrSize=8?72:48, &GUITHREADINFO, 0, "UInt") ;cbSize
    TID := DllCall("user32\GetWindowThreadProcessId", Ptr,hWnd, UIntP,0, UInt)
    DllCall("user32\GetGUIThreadInfo", UInt,TID, Ptr,&GUITHREADINFO)
    hWndC := NumGet(&GUITHREADINFO, A_PtrSize=8?48:28, "Ptr") ;hwndCaret
    OutputVarX := NumGet(&GUITHREADINFO, A_PtrSize=8?56:32, "Int") ;rcCaret ;x
    OutputVarY := NumGet(&GUITHREADINFO, A_PtrSize=8?60:36, "Int") ;rcCaret ;y
    Mode := SubStr(A_CoordModeCaret, 1, 1)
    VarSetCapacity(POINT, 8)
    NumPut(OutputVarX, &POINT, 0, "Int")
    NumPut(OutputVarY, &POINT, 4, "Int")
    DllCall("user32\ClientToScreen", Ptr,hWndC, Ptr,&POINT)
    OutputVarX := NumGet(&POINT, 0, "Int")
    OutputVarY := NumGet(&POINT, 4, "Int")
    if (Mode = "S") ;screen
        return
    else if (Mode = "C") ;client
    {
        VarSetCapacity(POINT, 8, 0)
        DllCall("user32\ClientToScreen", Ptr,hWnd, Ptr,&POINT)
        OriginX := NumGet(&POINT, 0, "Int")
        OriginY := NumGet(&POINT, 4, "Int")
    }
    else if (Mode = "W") ;window
    {
        VarSetCapacity(RECT, 16, 0)
        DllCall("user32\GetWindowRect", Ptr,hWnd, Ptr,&RECT)
        OriginX := NumGet(&RECT, 0, "Int")
        OriginY := NumGet(&RECT, 4, "Int")
    }
    OutputVarX -= OriginX, OutputVarY -= OriginY
}
Click(Params*)
{
    local i, Param, Args
    for i, Param in Params
        Args .= " " . Param
    Click %Args%
}
ClipboardAll(Data:="", Size:="")
{
    ;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 InStr(Class, "ListBox")
        SendMessage 0x18B, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCOUNT
    else if InStr(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 InStr(Class, "ListBox")
        SendMessage 0x185, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_SETSEL
    else if InStr(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 InStr(Class, "ListBox")
        SendMessage 0x188, 0, -1, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;LB_GETCURSEL
    else InStr(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(String, 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(Keys, Control:="", 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 Style, %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 Show,, %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)
{
    if OnOrOff in 1,0
        OnOrOff := OnOrOff ? "On" : "Off"
    DetectHiddenText %OnOrOff%
}
DetectHiddenWindows(OnOrOff)
{
    if OnOrOff in 1,0
        OnOrOff := OnOrOff ? "On" : "Off"
    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)
{
    Drive Lock, %Drive%
}
DriveSetLabel(Drive, NewLabel:="")
{
    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
    Encoding := A_FileEncoding
    EOL := "*"
    Loop Parse, Options, % " `t"
    {
        if (A_LoopField = "`n")
            EOL := ""
        else if (A_LoopField ~= "i)^(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) " "
        else if (SubStr(A_LoopField, 1, 5) = "UTF-8")
            Options2 .= "*P65001 "
        else if (SubStr(A_LoopField, 1, 6) = "UTF-16")
            Options2 .= "*P1200 "
    }
    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(Params*) ;Filename, Section, Key
{
    local Filename, Key, Section
    Filename := Params.1
    Section := Params.2
    Key := Params.3
    if (Params.Length() = 3)
        IniDelete %Filename%, %Section%, %Key%
    else if (Params.Length() = 2)
        IniDelete %Filename%, %Section%
    return !ErrorLevel
}
IniRead(Filename, Section:="", Key:="", Default:="")
{
    local OutputVar
    if (Default = "")
        Default := " "
    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(Params*) ;Text, Title, Options, Default
{
    local _, _X, _Y, _W, _H, _T, _P, _Err, Default, Options, Text, Title
    Text := Params.1
    Title := !Params.HasKey(2) ? A_ScriptName : (Params.2 = "") ? " " : Params.2
    Options := Params.3
    Default := Params.4

    ; 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%, %Text%, % _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:="")
{
    if OnOrOff in 1,0
        OnOrOff := OnOrOff ? "On" : "Off"
    ListLines %OnOrOff%
}
ListVars()
{
    ; Limitation -> won't work if called from within a function
    global
    ListVars
}
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%
    OutputVarWin += 0
    if (Mode & 2)
        OutputVarControl += 0
}
MouseMove(X, Y, Speed:="", R:="")
{
    MouseMove %X%, %Y%, %Speed%, %R%
}
MsgBox(Params*) ;Text, Title, Options
{
    local Match, Options, Result, Temp, Text, Timeout, Title, Type
    static TypeArray := {"OK":0, "O":0, "OKCancel":1, "O/C":1, "OC":1, "AbortRetryIgnore":2, "A/R/I":2, "ARI":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}

    Text := !Params.Length() ? "Press OK to continue." : Params.HasKey(1) ? Params.1 : ""
    Title := !Params.HasKey(2) ? A_ScriptName : (Params.2 = "") ? " " : Params.2
    Options := Params.3, Timeout := "", Type := 0
    if (Options)
    {
        Loop, Parse, Options, % " `t"
            (Temp := Abs(A_LoopField)) || (Temp := TypeArray[A_LoopField]) ? (Type |= Temp)
                : RegExMatch(A_LoopField, "Oi)^T(\d+\.?\d*)$", Match) ? Timeout := Match.1
                : 0
    }
    MsgBox % Type, % Title, % Text, % Timeout
    Loop Parse, % "Timeout,OK,Cancel,Yes,No,Abort,Ignore,Retry,Continue,TryAgain", % ","
        IfMsgBox % Result := A_LoopField
            break
    return Result
}
OutputDebug(Text)
{
    OutputDebug %Text%
}
Pause(Mode:="", OperateOnUnderlyingThread:=0)
{
    if Mode in 1,0,-1 ; On,Off,Toggle
        Mode := Mode == -1 ? "Toggle" : Mode ? "On" : "Off"
    Pause %Mode%, %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%
    ErrorLevel := (ErrorLevel = "FAIL")
    ;PostMessage returns an empty string.
}
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(Params*) ;KeyName, ValueName
{
    ;MsgBox, % "REGDELETE"
    if (Params.Length() = 1)
        Params[2] := "AHK_DEFAULT"
    if Params.Length()
    {
        if InStr(Params[1], "\")
            RegDelete % Params[1], % Params[2]
        else
            RegDelete % Params[1],, % Params[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:="")
{
    ;MsgBox, % "REGDELETEKEY"
    if !(A_LoopRegSubkey = "")
        RegDelete %A_LoopRegKey%
    else if !(A_LoopRegKey = "")
        RegDelete %A_LoopRegKey%\%A_LoopRegSubkey%
    else
        RegDelete %KeyName%
    return !ErrorLevel
}
RegRead(Params*) ;KeyName, ValueName
{
    local OutputVar
    if Params.Length()
    {
        if InStr(Params[1], "\")
            RegRead OutputVar, % Params[1], % Params[2]
        else
            RegRead OutputVar, % Params[1],, % Params[2]
    }
    else
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegRead OutputVar, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%
    }
    if !ErrorLevel
        return OutputVar
}
RegWrite(Params*) ;Value, ValueType, KeyName, ValueName
{
    ;if !(Params.3 = "HKEY_CURRENT_USER\Software\Microsoft\Notepad")
        ;MsgBox, % "REGWRITE`r`n" JEE_ObjPreview(Params)
    if (Params.Length() > 2)
    {
        if InStr(Params[3], "\")
            RegWrite % Params[2], % Params[3], % Params[4], % Params[1]
        else
            RegWrite % Params[2], % Params[3],, % Params[4], % Params[1]
    }
    else if (Params.Length() = 1)
    {
        if (A_LoopRegType = "KEY")
            ErrorLevel := 1
        else
            RegWrite %A_LoopRegType%, %A_LoopRegKey%, %A_LoopRegSubkey%, %A_LoopRegName%, % Params[1]
    }
    else if (Params.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:="")
{
    local MsgReply
    SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
    MsgReply := (ErrorLevel = "FAIL") ? "" : ErrorLevel
    ErrorLevel := (ErrorLevel = "FAIL")
    return MsgReply
}
SendMode(Mode)
{
    SendMode %Mode%
}
SendPlay(Keys)
{
    SendPlay %Keys%
}
SendRaw(Keys)
{
    SendRaw %Keys%
}
SetCapsLockState(State:="")
{
    if State in 1,0
        State := State ? "On" : "Off"
    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:="")
{
    if State in 1,0
        State := State ? "On" : "Off"
    SetNumLockState %State%
}
SetRegView(RegView)
{
    SetRegView %RegView%
}
SetScrollLockState(State:="")
{
    if State in 1,0
        State := State ? "On" : "Off"
    SetScrollLockState %State%
}
SetStoreCapsLockMode(OnOrOff)
{
    if OnOrOff in 1,0
        OnOrOff := OnOrOff ? "On" : "Off"
    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:="")
{
    local OutputVar
    SoundGet OutputVar, %ComponentType%, %ControlType%, %DeviceNumber%
    if !ErrorLevel
        return OutputVar
}
SoundPlay(Filename, Wait:="")
{
    SoundPlay %Filename%, %Wait%
    return !ErrorLevel
}
SoundSet(NewSetting, ComponentType:="", ControlType:="", DeviceNumber:="")
{
    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")
{
    if Mode in 1,0,-1 ; On,Off,Toggle
        Mode := Mode == -1 ? "Toggle" : Mode ? "On" : "Off"
    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%
}
TraySetIcon(FileName:="", IconNumber:="", Freeze:="")
{
    Menu Tray, Icon, %FileName%, %IconNumber%, %Freeze%
}
TrayTip(Params*) ;Text, Title, Options
{
    local Num := 0, Options, Text, Title
    Text := !Params.HasKey(1) ? " " : (Params.1 = "") ? " " : Params.1
    Title := !Params.HasKey(2) ? "" : Params.2
    Options := Params.HasKey(3) ? Params.3 : 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
}
WinGetClientPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local hWnd, RECT
    hWnd := WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText)
    VarSetCapacity(RECT, 16, 0)
    DllCall("user32\GetClientRect", Ptr,hWnd, Ptr,&RECT)
    DllCall("user32\ClientToScreen", Ptr,hWnd, Ptr,&RECT)
    X := NumGet(&RECT, 0, "Int"), Y := NumGet(&RECT, 4, "Int")
    Width := NumGet(&RECT, 8, "Int"), Height := NumGet(&RECT, 12, "Int")
}
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*) ;X, Y [, Width, Height, WinTitle, WinText, ExcludeTitle, ExcludeText]
{
    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(Value:="Toggle", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
    local Hwnd
    WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
    if (!Hwnd)
        return 0

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

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

    WinSet AlwaysOnTop, %Value%, 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(NewTitle, Params*) ;NewTitle [, WinTitle, WinText, ExcludeTitle, ExcludeText]
{
    local WinTitle, WinText, ExcludeTitle, ExcludeText
    if (Params.Length())
    {
        WinTitle     := Params[1]
        WinText      := Params[2]
        ExcludeTitle := Params[3]
        ExcludeText  := Params[4]
        WinSetTitle %WinTitle%, %WinText%, %NewTitle%, %ExcludeTitle%, %ExcludeText%
    }
    else
        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 ? 0 : WinExist()
}
WinWaitActive(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
    WinWaitActive %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
    return ErrorLevel ? 0 : WinExist()
}
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
}

;A_TrayMenu.ClickCount
class A_TrayMenu
{
	static varClickCount := 2
	ClickCount[]
	{
		get
		{
			return this.varClickCount
		}
		set
		{
			Menu, Tray, Click, % value
			return this.varClickCount := value
		}
	}
}

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

;old version:
;CaretGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="")
;{
;    OutputVarX := A_CaretX, OutputVarY := A_CaretY
;}

;hoped-for version (with added Format parameter):
;DateAdd(DateTime, Time, TimeUnits, Format:="yyyyMMddHHmmss")
;{
;    EnvAdd DateTime, %Time%, %TimeUnits%
;    if !(Format == "yyyyMMddHHmmss")
;        FormatTime DateTime, %DateTime%, %Format%
;    return DateTime
;}

;==================================================
Last edited by jeeswg on 01 Aug 2018, 14:58, edited 1 time in total.
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

05 Apr 2018, 20:24

TEST SCRIPT. This script aims to test all of the functions in the library. I have used it to help identify issues, which led to some of the fixes in the update in the post above.

I would greatly appreciate it if anyone can help to resolve any of the issues.

there remain issues with:
- CallbackCreate / CallbackFree [the test causes an error in AHK v2][EDIT: Added fix at bottom. Fixed by adding a ParamCount parameter]
- InputEnd [the cloned function for AHK v1 does not match the AHK v2 function]
- Type [misidentifying Float as String][see details in the script below re. ObjGetCapacity, the trick used to identify Integer types]

some general points:
- IniRead [a default value of 1 or more spaces, still gives a blank in AHK v1/v2][EDIT: GetPrivateProfileString appears to trim trailing spaces]
- SetRegView [need a good example with different 64-bit/32-bit results]
- WinRedraw [need a good example][EDIT: Added example at bottom. The window will flash momentarily. But could do with a better example.]

minor points:
- BlockInput [I found that BlockInput doesn't work on Notepad on Windows 7, unless Admin is on, i.e. BlockInput has not been working in my scripts, but I didn't realise]
- RandomSeed [how does it work, how should it be used?]

Code: Select all

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

;test script for:
;AHK v2 functions for AHK v1
;[first released: 2018-04-05]

;use at your own risk

;the idea here is to select code,
;and run it in 'pseudo-AHK v2' (in AHK v1) and AHK v2,
;to ensure that both give the same results

;link:
;commands as functions (AHK v2 functions for AHK v1) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=29689

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

;prevent the script from doing anything
SoundBeep()
return

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

;note: this is script is meant to opened in Notepad,
;lines of code are selected, and then executed via a hotkey,
;they are run in both AHK v2 and 'pseudo-AHK v2' (AHK v2 functions for AHK v1),
;the results are then compared

;run selected code with 'pseudo-AHK v2' or AHK v2,
;requires AHK v1 exe, AHK v2 exe, JEEAhk1FC.ahk,
;and a test folder to store the temporary script

;F1::
;F2::
;^F1::
;^F2::
vDirAhk1 := "C:\Program Files\AutoHotkey\AHK v1"
vDirAhk2 := "C:\Program Files\AutoHotkey\AHK v2"
vDirAhk1FC := vDirAhk1
vDirAhkTest := A_Desktop "\ahk test"

vPathAhk1U32 := vDirAhk1 "\AutoHotkeyU32.exe"
vPathAhk1U64 := vDirAhk1 "\AutoHotkeyU64.exe"
vPathAhk2U32 := vDirAhk2 "\AutoHotkeyU32.exe"
vPathAhk2U64 := vDirAhk2 "\AutoHotkeyU64.exe"

vPathAhk1 := vPathAhk1U32
vPathAhk2 := vPathAhk2U32
vPathAhk1FC := vDirAhk1FC "\JEEAhk1FC.ahk"

if !FileExist(vPathAhk1)
|| !FileExist(vPathAhk2)
|| !FileExist(vPathAhk1FC)
{
	MsgBox("error")
	return
}

vHotkey := A_ThisHotkey

;vText := JEE_GetSelectedText()
Clipboard := ""
SendInput("^c")
ClipWait(3)
if ErrorLevel
{
	MsgBox("error: failed to retrieve clipboard text")
	return
}
vText := Clipboard

vText := RTrim(vText, "`r`n") "`r`n"
if InStr(vHotkey, "1")
	vText .= "#Include " vPathAhk1FC "`r`n"
if !DirExist(vDirAhkTest)
	DirCreate(vDirAhkTest)
if !DirExist(vDirAhkTest)
{
	MsgBox("error")
	return
}
vPath := vDirAhkTest "\z test " A_Now ".ahk"
FileAppend(vText, vPath, "UTF-8")
if InStr(vHotkey, "1")
	Run(Chr(34) vPathAhk1U32 Chr(34) " " Chr(34) vPath Chr(34))
else
	Run(Chr(34) vPathAhk2U32 Chr(34) " " Chr(34) vPath Chr(34))
return

#Include C:\Program Files\AutoHotkey\AHK v1\JEEAhk1FC.ahk

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

/*

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

;issues with:
;- CallbackCreate / CallbackFree [the test causes an error in AHK v2]
;- InputEnd [the cloned function for AHK v1 does not match the AHK v2 function]
;- Type [misidentifying Float as String]
;MsgBox, % ObjGetCapacity([1], 1) ;(blank) ;Integer
;MsgBox, % ObjGetCapacity([01], 1) ;(blank) ;Integer
;MsgBox, % ObjGetCapacity([0x1], 1) ;(blank) ;Integer
;MsgBox, % ObjGetCapacity([1.1], 1) ;30 ;Float
;MsgBox, % ObjGetCapacity(["1"], 1) ;30 ;String
;MsgBox, % ObjGetCapacity(["01"], 1) ;30 ;String
;MsgBox, % ObjGetCapacity(["0x1"], 1) ;30 ;String
;MsgBox, % ObjGetCapacity(["1.1"], 1) ;30 ;String

;general points:
;- IniRead [a default value of 1 or more spaces, still gives a blank in AHK v1/v2]
;- SetRegView [need a good example with different 64-bit/32-bit results]
;- WinRedraw [need a good example]

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

;text replacements: before|after
;, Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")|,, "ahk_id " hCtl)
;(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")|(, "ahk_id " hCtl)
;WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")|"ahk_id " hWnd)
;(WinTitle:="", WinText:="",|("ahk_id " hWnd,,
;, ExcludeTitle:="", ExcludeText:="")|)

;note: parameter name choices: Mode/State/Value

;list of functions based on 'AHK v2 functions for AHK v1'
;with some parameter tidying/renaming and with 'ByRef'/':=""' removed
;BlockInput(Mode)
;CallbackCreate(Function, Options, ParamCount)
;CallbackFree(Address)
;CaretGetPos(X, Y)
;Click(Params*)
;ClipboardAll(Data, Size)
;ClipWait(Seconds, Param:=1)
;ControlAddItem(String,, "ahk_id " hCtl)
;ControlChoose(N,, "ahk_id " hCtl)
;ControlChooseString(String,, "ahk_id " hCtl)
;ControlClick(ControlOrPos, "ahk_id " hWnd,, WhichButton, ClickCount, Options)
;ControlDeleteItem(N,, "ahk_id " hCtl)
;ControlEditPaste(String,, "ahk_id " hCtl)
;ControlFindItem(String,, "ahk_id " hCtl)
;ControlFocus(, "ahk_id " hCtl)
;ControlGetChecked(, "ahk_id " hCtl)
;ControlGetChoice(, "ahk_id " hCtl)
;ControlGetCurrentCol(, "ahk_id " hCtl)
;ControlGetCurrentLine(, "ahk_id " hCtl)
;ControlGetEnabled(, "ahk_id " hCtl)
;ControlGetExStyle(, "ahk_id " hCtl)
;ControlGetFocus("ahk_id " hWnd)
;ControlGetHwnd(, "ahk_id " hCtl)
;ControlGetLine(Index,, "ahk_id " hCtl)
;ControlGetLineCount(, "ahk_id " hCtl)
;ControlGetList(Options,, "ahk_id " hCtl)
;ControlGetPos(X, Y, Width, Height,, "ahk_id " hCtl)
;ControlGetSelected(, "ahk_id " hCtl)
;ControlGetStyle(, "ahk_id " hCtl)
;ControlGetTab(, "ahk_id " hCtl)
;ControlGetText(, "ahk_id " hCtl)
;ControlGetVisible(, "ahk_id " hCtl)
;ControlHide(, "ahk_id " hCtl)
;ControlHideDropDown(, "ahk_id " hCtl)
;ControlMove(X, Y, Width, Height,, "ahk_id " hCtl)
;ControlSend(Keys,, "ahk_id " hCtl)
;ControlSendRaw(Keys,, "ahk_id " hCtl)
;ControlSetChecked(Value,, "ahk_id " hCtl)
;ControlSetEnabled(Value,, "ahk_id " hCtl)
;ControlSetExStyle(Value,, "ahk_id " hCtl)
;ControlSetStyle(Value,, "ahk_id " hCtl)
;ControlSetTab(N,, "ahk_id " hCtl)
;ControlSetText(NewText,, "ahk_id " hCtl)
;ControlShow(, "ahk_id " hCtl)
;ControlShowDropDown(, "ahk_id " hCtl)
;CoordMode(Param1, Param2:="Screen")
;Critical(Param)
;DateAdd(DateTime, Time, TimeUnits)
;DateDiff(DateTime1, DateTime2, TimeUnits)
;DetectHiddenText(Mode)
;DetectHiddenWindows(Mode)
;DirCopy(Source, Dest, Flag:=0)
;DirCreate(DirName)
;DirDelete(DirName, Recurse:=0)
;DirExist(FilePattern)
;DirMove(Source, Dest, Flag:=0)
;DirSelect(StartingFolder, Options:=1, Prompt)
;Download(URL, FileName)
;DriveEject(Drive, Retract:=0)
;DriveGetCapacity(Path)
;DriveGetFilesystem(Drive)
;DriveGetLabel(Drive)
;DriveGetList(Type)
;DriveGetSerial(Drive)
;DriveGetSpaceFree(Path)
;DriveGetStatus(Drive)
;DriveGetStatusCD(Drive)
;DriveGetType(Drive)
;DriveLock(Drive)
;DriveSetLabel(Drive, NewLabel)
;DriveUnlock(Drive)
;Edit()
;EnvGet(EnvVarName)
;EnvSet(EnvVar, Value)
;Exit(ExitCode:=0)
;ExitApp(ExitCode:=0)
;FileAppend(Text, Filename, Options)
;FileCopy(Source, Dest, Flag:=0)
;FileCreateShortcut(Target, LinkFile, WorkingDir, Args, Description, IconFile, ShortcutKey, IconNumber, RunState:=1)
;FileDelete(FilePattern)
;FileEncoding(Encoding)
;FileGetAttrib(Filename)
;FileGetShortcut(LinkFile, Target, Dir, Args, Description, Icon, IconNum, RunState)
;FileGetSize(Filename, Units)
;FileGetTime(Filename, WhichTime:="M")
;FileGetVersion(Filename)
;FileInstall(Source, Dest, Flag:=0)
;FileMove(SourcePattern, DestPattern, Flag:=0)
;FileRead(Filename, Options)
;FileRecycle(FilePattern)
;FileRecycleEmpty(DriveLetter)
;FileSelect(Options:=0, RootDir_Filename, Prompt, Filter)
;FileSetAttrib(Attributes, FilePattern, Mode)
;FileSetTime(Date, FilePattern, WhichTime:="M", Mode)
;FormatTime(Date, Format)
;GroupActivate(GroupName, R)
;GroupAdd(GroupName, "ahk_id " hWnd)
;GroupClose(GroupName, AR)
;GroupDeactivate(GroupName, R)
;Hotkey(Param1, Param2, Param3)
;ImageSearch(X, Y, X1, Y1, X2, Y2, ImageFile)
;IniDelete(Filename, Section, Key)
;IniRead(Filename, Section, Key, Default)
;IniWrite(Value, Filename, Section, Key)
;Input(Options, EndKeys, MatchList)
;InputBox(Text, Title, Options, Default)
;InputEnd()
;KeyHistory()
;KeyWait(KeyName, Options)
;ListHotkeys()
;ListLines(Mode)
;ListVars()
;MenuSelect("ahk_id " hWnd,, Menu, SubMenu1, SubMenu2, SubMenu3, SubMenu4, SubMenu5, SubMenu6)
;MonitorGet(N, Left, Top, Right, Bottom)
;MonitorGetCount()
;MonitorGetName(N)
;MonitorGetPrimary()
;MonitorGetWorkArea(N, Left, Top, Right, Bottom)
;MouseClick(WhichButton:="Left", X, Y, ClickCount, Speed, DU, R)
;MouseClickDrag(WhichButton, X1, Y1, X2, Y2, Speed, R)
;MouseGetPos(X, Y, Win, Control, Mode:=0)
;MouseMove(X, Y, Speed, R)
;MsgBox(Text, Title, Options)
;OutputDebug(Text)
;Pause(Mode, OperateOnUnderlyingThread:=0)
;PixelGetColor(X, Y, AltSlow)
;PixelSearch(X, Y, X1, Y1, X2, Y2, ColorID, Variation:=0, Fast)
;PostMessage(Msg, wParam, lParam,, "ahk_id " hCtl)
;ProcessClose(PIDorName)
;ProcessExist(PIDorName)
;ProcessSetPriority(Priority, PIDorName)
;ProcessWait(PIDorName, Seconds)
;ProcessWaitClose(PIDorName, Seconds)
;Random(Min, Max)
;RandomSeed(NewSeed)
;RegDelete(KeyName, ValueName)
;RegDeleteKey(KeyName)
;RegRead(KeyName, ValueName)
;RegWrite(Value, ValueType, KeyName, ValueName)
;Reload()
;Run(Target, WorkingDir, Options, PID)
;RunAs(User, Password, Domain)
;RunWait(Target, WorkingDir, Options, PID)
;Send(Keys)
;SendEvent(Keys)
;SendInput(Keys)
;SendLevel(Level)
;SendMessage(Msg, wParam, lParam,, "ahk_id " hCtl,,,, Timeout)
;SendMode(Mode)
;SendPlay(Keys)
;SendRaw(Keys)
;SetCapsLockState(State)
;SetControlDelay(Delay)
;SetDefaultMouseSpeed(Speed)
;SetKeyDelay(Delay, PressDuration, Play)
;SetMouseDelay(Delay, Play)
;SetNumLockState(State)
;SetRegView(RegView)
;SetScrollLockState(State)
;SetStoreCapsLockMode(Mode)
;SetTimer(Label, Period, Priority:=0)
;SetTitleMatchMode(MatchModeOrSpeed)
;SetWinDelay(Delay)
;SetWorkingDir(DirName)
;Shutdown(Code)
;Sleep(Milliseconds)
;Sort(String, Options)
;SoundBeep(Frequency:=523, Duration:=150)
;SoundGet(ComponentType, ControlType, DeviceNumber)
;SoundPlay(Filename, Wait)
;SoundSet(NewSetting, ComponentType, ControlType, DeviceNumber)
;SplitPath(Path, FileName, Dir, Extension, NameNoExt, Drive)
;StatusBarGetText(PartNum:=1, "ahk_id " hWnd)
;StatusBarWait(BarText, Seconds, PartNum:=1, "ahk_id " hWnd,, Interval:=50)
;StringCaseSense(Mode)
;StrLower(String, T)
;StrUpper(String, T)
;Suspend(Mode)
;SysGet(SubCommand)
;Thread(Param1, Param2, Param3)
;ToolTip(Text, X, Y, WhichToolTip:=1)
;TraySetIcon(FileName, IconNumber, Freeze)
;TrayTip(Text, Title, Options:=0)
;Type(Value)
;WinActivate("ahk_id " hWnd)
;WinActivateBottom("ahk_id " hWnd)
;WinClose("ahk_id " hWnd,, Seconds)
;WinGetClass("ahk_id " hWnd)
;WinGetClientPos(X, Y, Width, Height, "ahk_id " hWnd)
;WinGetControls("ahk_id " hWnd)
;WinGetControlsHwnd("ahk_id " hWnd)
;WinGetCount("ahk_id " hWnd)
;WinGetExStyle("ahk_id " hWnd)
;WinGetID("ahk_id " hWnd)
;WinGetIDLast("ahk_id " hWnd)
;WinGetList("ahk_id " hWnd)
;WinGetMinMax("ahk_id " hWnd)
;WinGetPID("ahk_id " hWnd)
;WinGetPos(X, Y, Width, Height, "ahk_id " hWnd)
;WinGetProcessName("ahk_id " hWnd)
;WinGetProcessPath("ahk_id " hWnd)
;WinGetStyle("ahk_id " hWnd)
;WinGetText("ahk_id " hWnd)
;WinGetTitle("ahk_id " hWnd)
;WinGetTransColor("ahk_id " hWnd)
;WinGetTransparent("ahk_id " hWnd)
;WinHide("ahk_id " hWnd)
;WinKill("ahk_id " hWnd,, Seconds)
;WinMaximize("ahk_id " hWnd)
;WinMinimize("ahk_id " hWnd)
;WinMinimizeAll()
;WinMinimizeAllUndo()
;WinMove(X, Y, Width, Height, "ahk_id " hWnd)
;WinMoveBottom("ahk_id " hWnd)
;WinMoveTop("ahk_id " hWnd)
;WinRedraw("ahk_id " hWnd)
;WinRestore("ahk_id " hWnd)
;WinSetAlwaysOnTop(Value, "ahk_id " hWnd)
;WinSetEnabled(Value, "ahk_id " hWnd)
;WinSetExStyle(N, "ahk_id " hWnd)
;WinSetRegion(Options, "ahk_id " hWnd)
;WinSetStyle(N, "ahk_id " hWnd)
;WinSetTitle(NewTitle, "ahk_id " hWnd)
;WinSetTransColor(ColorN, "ahk_id " hWnd)
;WinSetTransparent(N, "ahk_id " hWnd)
;WinShow("ahk_id " hWnd)
;WinWait("ahk_id " hWnd,, Seconds)
;WinWaitActive("ahk_id " hWnd,, Seconds)
;WinWaitClose("ahk_id " hWnd,, Seconds)
;WinWaitNotActive("ahk_id " hWnd,, Seconds)
;A_TrayMenu.ClickCount := 1

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

;NOT TESTED
;FUNC - ClipboardAll, FileInstall
;also not tested: DriveLock, DriveSetLabel, DriveUnlock, RunAs, SetRegView, Shutdown, WinRedraw

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

;VAR - A_TrayMenu.ClickCount
A_TrayMenu.ClickCount := 1
Sleep(10000)
ExitApp()

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

;FUNC - InputBox, MsgBox, ToolTip, TrayTip
InputBox("text", "title")
InputBox("text", " ")
InputBox(" ", "title")
InputBox("text", "")
InputBox("", "title")
InputBox("text")
InputBox(, "title")
InputBox()

MsgBox("text", "title")
MsgBox("text", " ")
MsgBox(" ", "title")
MsgBox("text", "")
MsgBox("", "title")
MsgBox("text")
MsgBox(, "title")
MsgBox()

TrayTip("text", "title"), Sleep(1000)
TrayTip("text", " "), Sleep(1000)
TrayTip(" ", "title"), Sleep(1000)
TrayTip("text", ""), Sleep(1000)
TrayTip("", "title"), Sleep(1000)
TrayTip("text"), Sleep(1000)
TrayTip(, "title"), Sleep(1000)
TrayTip(), Sleep(1000)

Loop 5
	ToolTip(A_Index, A_Index*100, A_Index*100, A_Index)
Sleep(1000)
Loop 5
	ToolTip(,,, A_Index), Sleep(500)

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

;FUNC - Edit, KeyHistory, ListHotkeys, ListLines, ListVars
KeyHistory(), Sleep(1000)
ListHotkeys(), Sleep(1000)
ListLines(), Sleep(1000)
ListVars(), Sleep(1000)
Edit()

;FUNC - Pause, Suspend
;note: manually click 'Show hidden icons' in the taskbar
;note: manually select 'Pause' from the tray icon to unpause the script
Sleep(2000)
Suspend(1)
Sleep(2000)
Pause(1)
MsgBox()

;FUNC - Exit, ExitApp
ListVars(), Sleep(1000), Exit()
ListVars(), Sleep(1000), ExitApp()

;FUNC - Reload
;note: reloaded scripts contain '/restart' in the command-line arguments,
;this is used to exit the script after it reloads
vCmdLn := DllCall("kernel32\GetCommandLineW", Str)
MsgBox(vCmdLn)
if InStr(vCmdLn, "/restart")
	ExitApp()
Reload()

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

;FUNC - BlockInput
;note: I found that BlockInput doesn't work on Notepad on Windows 7, unless Admin is on
#SingleInstance force
if !A_IsAdmin
	Run("*RunAs " (A_IsCompiled ? "" : A_AhkPath " ") Chr(34) A_ScriptFullPath Chr(34))
else
{
	BlockInput(1), SoundBeep()
	Sleep(3000)
	BlockInput(0), SoundBeep()
}

;FUNC - CallbackCreate, CallbackFree
pFunc := CallbackCreate("MyCallbackFunc", "F")
MyCallbackFunc("MyCallbackFunc was called directly.")
DllCall(pFunc, Float,10.5, Int64,42)
DllCall(pFunc, Float,10.5, Int64,42)
CallbackFree(pFunc)
DllCall(pFunc, Float,10.5, Int64,42)
MyCallbackFunc(oParams*)
{
	if IsObject(oParams)
		MsgBox(oParams[1])
	else
		MsgBox(NumGet(oParams+0, "Float") ", " NumGet(oParams+A_PtrSize, "Int64"))
}

;FUNC - CaretGetPos, CoordMode
CoordMode("Caret", "Screen")
CaretGetPos(X, Y), vOutput .= X " " Y "`r`n"
CoordMode("Caret", "Window")
CaretGetPos(X, Y), vOutput .= X " " Y "`r`n"
CoordMode("Caret", "Client")
CaretGetPos(X, Y), vOutput .= X " " Y "`r`n"
MsgBox(vOutput)

;FUNC - Click
CoordMode("Mouse", "Screen")
;Click(Format("{:i} {:i}", A_ScreenWidth/2, A_ScreenHeight/2))
Click((A_ScreenWidth//2) " " (A_ScreenHeight//2))

;FUNC - MouseClick
CoordMode("Mouse", "Screen")
MouseClick("L", A_ScreenWidth/2, A_ScreenHeight/2)

;FUNC - MouseClickDrag
CoordMode("Mouse", "Screen")
Sleep(2000), MouseClickDrag("L", 300, 300, 400, 400)

;FUNC - ClipWait
Clipboard := "", Sleep(2000), Send("^c"), SoundBeep(500+500*ClipWait(2))
Clipboard := "", Sleep(2000), Send("^c"), SoundBeep(500+500*ClipWait(2, 1))

;FUNC - Critical
;note: q hotkey does not run until Critical is off
Critical("On")
Loop 200
	Sleep(10)
Critical("Off"), SoundBeep()
Loop 200
	Sleep(10)
SoundBeep()
ExitApp()
q::MsgBox()

;FUNC - DateAdd, DateDiff, FormatTime
vDate := FormatTime(DateAdd(A_Now, 7, "D"), "yyyy-MM-dd"), MsgBox(vDate)
vDate := A_Now, vDiff := DateDiff(vDate, SubStr(vDate, 1, 4), "D"), MsgBox(vDiff)

;FUNC - DetectHiddenText
;note: test on Notepad's Find dialog
Sleep(2000), DetectHiddenText(1), vCount := WinGetCount("", "Match &whole word"), MsgBox(vCount)
Sleep(2000), DetectHiddenText(0), vCount := WinGetCount("", "Match &whole word"), MsgBox(vCount)

;FUNC - DetectHiddenWindows
DetectHiddenWindows(1), vCount := WinGetCount("ahk_class AutoHotkey"), MsgBox(vCount)
DetectHiddenWindows(0), vCount := WinGetCount("ahk_class AutoHotkey"), MsgBox(vCount)

;FUNC - EnvGet
vAppData := EnvGet("AppData"), MsgBox(vAppData)

;FUNC - EnvSet
;note: temporarily creates an environment variable
EnvSet("MyEnvVar", "text")
vMyEnvVar := EnvGet("MyEnvVar"), MsgBox(vMyEnvVar)

;FUNC - GroupActivate, GroupAdd, GroupClose, GroupDeactivate
;note: RegRead and RegWrite are done to maintain the dimensions of Notepad windows
vWinX := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosX")
vWinY := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosY")
vWinW := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosDX")
vWinH := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosDY")
Loop 4
{
	Run("notepad",,, vPID)
	WinWait("ahk_class Notepad ahk_pid " vPID)
	hWnd := WinExist()
	WinMove(A_Index*100, A_Index*100, 100, 100, "ahk_id " hWnd)
	GroupAdd("MyWinGroup", "ahk_id " hWnd)
}
Sleep(2000)
GroupActivate("MyWinGroup")
Sleep(2000)
GroupDeactivate("MyWinGroup")
Sleep(2000)
GroupClose("MyWinGroup", "A") ;close all
vCoords := Format("x{} y{} w{} h{}", vWinX, vWinY, vWinW, vWinH)
;MsgBox(vCoords)
RegWrite(vWinX, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosX")
RegWrite(vWinY, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosY")
RegWrite(vWinW, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosDX")
RegWrite(vWinH, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosDY")
SoundBeep()

;FUNC - Hotkey
Hotkey("q", "MyHotkeyFunc")
Hotkey("w", "MyHotkeyFunc")
Hotkey("e", "MyExitFunc")
return
MyHotkeyFunc()
{
	MsgBox(A_ThisHotkey)
}
MyExitFunc()
{
	SoundBeep()
	ExitApp()
}

;FUNC - ImageSearch
ListVars()
WinWaitActive("ahk_class AutoHotkey")
hIcon := LoadPicture(A_AhkPath, "w16 h16", vImgType)
CoordMode("Pixel", "Screen")
CoordMode("Mouse", "Screen")
ImageSearch(X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, "*100 HICON:*" hIcon)
MouseMove(X, Y)
MsgBox(X " " Y)

;FUNC - PixelGetColor, PixelSearch
;note: it searches the screen for the AutoHotkey icon,
;it then searches for a specific dark green colour (or a near match),
;and sets the AutoHotkey icon to the colour it finds
ListVars()
WinWaitActive("ahk_class AutoHotkey")
CoordMode("Pixel", "Screen")
CoordMode("Mouse", "Screen")
PixelSearch(X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, 0x008000, 30)
MouseMove(X, Y)
vRGB := PixelGetColor(X, Y)
MsgBox(X " " Y "`r`n" vRGB)
vRGB := SubStr(vRGB, 3)
vBGR := SubStr(vRGB, 5, 2) SubStr(vRGB, 3, 2) SubStr(vRGB, 1, 2) "00"
vIconDataHex := ""
. "000001000100101010000100040028010000160000002800000010000000200000000100040000000000C000000000000000000000000000000000000000"
. vBGR "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
. "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
. "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
VarSetCapacity(vIconData, vSize := StrLen(vIconDataHex)//2)
Loop vSize
	NumPut("0x" SubStr(vIconDataHex,2*A_Index-1,2), &vIconData, A_Index-1, "Char")
hIcon := DllCall("user32\CreateIconFromResourceEx", Ptr,&vIconData+22, UInt,NumGet(&vIconData, 14, "UInt"), Int,1, UInt,0x30000, Int,16, Int,16, UInt,0, Ptr)
SendMessage(0x80, 0, hIcon,, "ahk_id " A_ScriptHwnd) ;WM_SETICON := 0x80 ;sets title bar icon + taskbar icon
SendMessage(0x80, 1, hIcon,, "ahk_id " A_ScriptHwnd) ;WM_SETICON := 0x80 ;sets alt+tab icon
MsgBox()

;FUNC - Input, InputEnd
vRet := InputEnd()
MsgBox(vRet " " ErrorLevel)
SetTimer("MyInputEndFunc", -2000)
vInput := Input("L3")
MsgBox(vInput "`r`n" ErrorLevel)
ExitApp()
MyInputEndFunc()
{
	vRet := InputEnd()
	MsgBox(vRet " " ErrorLevel)
}

;FUNC - KeyWait
KeyWait("q", "D") ;wait for key to be held down
KeyWait("q") ;wait for key to be released
MsgBox()

;FUNC - MenuSelect
hWnd := WinExist("ahk_class Notepad")
MenuSelect("ahk_id " hWnd,, "Help", "About Notepad")

;FUNC - MonitorGet, MonitorGetCount, MonitorGetName, MonitorGetPrimary, MonitorGetWorkArea
MonitorGet(1, Left, Top, Right, Bottom)
vMonPos := Format("x{} y{} r{} b{}", Left, Top, Right, Bottom)
vMonCount := MonitorGetCount()
vMonName := MonitorGetName(1)
vMonPrim := MonitorGetPrimary()
MonitorGetWorkArea(1, Left, Top, Right, Bottom)
vMonWorkArea := Format("x{} y{} r{} b{}", Left, Top, Right, Bottom)
MsgBox(vMonPos "`r`n" vMonCount "`r`n" vMonName "`r`n" vMonPrim "`r`n" vMonWorkArea)

;FUNC - MouseGetPos, MouseMove
CoordMode("Mouse", "Screen")
MouseMove(A_ScreenWidth/2, A_ScreenHeight/2)
MouseGetPos(X, Y, hWnd, ClassNN)
MouseGetPos(X, Y, hWnd, hCtl, 2)
MsgBox(X " " Y "`r`n" hWnd "`r`n" ClassNN "`r`n" hCtl)

;FUNC - OutputDebug
;note: download DebugView, run Dbgview.exe,
;any time an OutputDebug line is executed,
;the text appears in the DebugView window
OutputDebug("my text")

;FUNC - PostMessage, SendMessage
PostMessage(0xB1, 0, -1, "Edit1", "ahk_class Notepad") ;EM_SETSEL := 0xB1 ;select all
SendMessage(0xB1, 0, -1, "Edit1", "ahk_class Notepad") ;EM_SETSEL := 0xB1 ;select all

;FUNC - ProcessClose, ProcessExist, ProcessSetPriority, ProcessWait, ProcessWaitClose
Run("wordpad.exe")
ProcessWait("wordpad.exe")
vPID := ProcessExist("wordpad.exe")
SoundBeep()
ProcessSetPriority("High", vPID)
Run("taskmgr") ;check the process priority
MsgBox(vPID)
WinWaitClose("ahk_exe taskmgr.exe")
MsgBox()
ProcessClose(vPID)
ProcessWaitClose(vPID)
SoundBeep()

;FUNC - Random, RandomSeed
vOutput := ""
Loop 10
	vOutput .= Random(1, 6) " "
MsgBox(vOutput)
vOutput := ""
Loop 10
	vOutput .= Random(0.0, 1.0) "`r`n"
MsgBox(vOutput)
vRet := RandomSeed(0)
MsgBox(vRet " " ErrorLevel)

;FUNC - Run, RunWait
Run("notepad.exe",,, vPID1)
MsgBox(vPID1)
RunWait("notepad.exe",,, vPID2)
MsgBox(vPID2)

;NOT TESTED
;FUNC - RunAs

;FUNC - Send, SendEvent, SendInput, SendPlay, SendRaw
Sleep(1000)
Send("s")
SendEvent("e")
SendInput("i")
SendPlay("p") ;did nothing on my PC
SendRaw("r")

;FUNC - SendLevel
Sleep(1000)
SendLevel(1)
Send("btw{Space}")
::btw::by the way

;FUNC - SendMode
Run("cmd")
WinWaitActive("ahk_class ConsoleWindowClass")
SendMode("Event")
Send("abcdefghijklmnopqrstuvwxyz")
SendMode("Input")
Send("abcdefghijklmnopqrstuvwxyz")

;FUNC - SetCapsLockState
;note: try typing during/after the Sleep
SetCapsLockState(1)
SoundBeep()
Sleep(2000)
SetCapsLockState(0)
SoundBeep()

;FUNC - SetNumLockState
;note: try typing during/after the Sleep
SetNumLockState(1)
SoundBeep()
Sleep(2000)
SetNumLockState(0)
SoundBeep()

;FUNC - SetScrollLockState
;note: try typing during/after the Sleep
;note: test on Excel: it either moves the cell selection box (when off),
;or scrolls the scrollbars (when on)
SetScrollLockState(1)
SoundBeep()
Sleep(2000)
SetScrollLockState(0)
SoundBeep()

SetScrollLockState(1)
vState := GetKeyState("ScrollLock", "T")
MsgBox(vState)
SetScrollLockState(0)
vState := GetKeyState("ScrollLock", "T")
MsgBox(vState)

;FUNC - SetStoreCapsLockMode
;note: expected output: 'QWEqweQWEqweQWEqweqweQWE'
Sleep(1000)
Loop 2
{
	SetCapsLockState(A_Index-1)
	SetStoreCapsLockMode(1)
	Send("QWEqwe")
	SetStoreCapsLockMode(0)
	Send("QWEqwe")
}

;FUNC - SetControlDelay
Sleep(1000)
ControlGetPos(X,,,, "Edit1", "A")
Loop 10
{
	X += 10
	ControlMove(X,,,, "Edit1", "A")
}
SetControlDelay(250)
Loop 10
{
	X -= 10
	ControlMove(X,,,, "Edit1", "A")
}

;FUNC - SetWinDelay
Sleep(1000)
SetWinDelay(25)
WinGetPos(X,,,, "A")
Loop 10
{
	X += 10
	WinMove(X,,,, "A")
}
SetWinDelay(250)
Loop 10
{
	X -= 10
	WinMove(X,,,, "A")
}

;FUNC - SetDefaultMouseSpeed
CoordMode("Screen", "Mouse")
MouseGetPos(X, Y)
SetDefaultMouseSpeed(20)
Loop 11
	MouseMove(A_Index*100, A_ScreenHeight/2)
SetDefaultMouseSpeed(5)
Loop 11
	MouseMove(A_Index*100, A_ScreenHeight/2)
MouseMove(X, Y)

;FUNC - SetMouseDelay
CoordMode("Screen", "Mouse")
MouseGetPos(X, Y)
SetMouseDelay(50)
Loop 11
	MouseMove(A_Index*100, A_ScreenHeight/2)
SetMouseDelay(5)
Loop 11
	MouseMove(A_Index*100, A_ScreenHeight/2)
MouseMove(X, Y)

;FUNC - SetKeyDelay
;note: check that CapsLock blinks slowly/quickly
SendMode("Event")
SetStoreCapsLockMode(0)
SetKeyDelay(500)
Loop 10
	Send("{CapsLock}")
SoundBeep()
SetKeyDelay(50)
Loop 10
	Send("{CapsLock}")
SoundBeep()

;NOT TESTED
;FUNC - SetRegView

;FUNC - SetTimer
#Persistent ;necessary for 'AHK v2 functions for AHK v1' but for AHK v2
SetTimer("MyTimerSoundBeepFunc", 500)
MyTimerSoundBeepFunc()
{
	static vCount := 0
	vCount++
	SoundBeep()
	if (vCount = 5)
		SetTimer("MyTimerSoundBeepFunc", "Off")
}

;FUNC - SetTitleMatchMode
SetTitleMatchMode(1) ;starts
vCount := WinGetCount("Notepad")
MsgBox(vCount)
SetTitleMatchMode(2) ;contains
vCount := WinGetCount("Notepad")
MsgBox(vCount)

;FUNC - SetWorkingDir
;note: the Command Prompt windows should show different starting folders
Run("cmd")
SetWorkingDir(A_AppData)
Run("cmd")

;NOT TESTED
;FUNC - Shutdown

;FUNC - Sleep
MsgBox(1)
Sleep(1000)
MsgBox(2)
Sleep(2000)
MsgBox(3)
Sleep(3000)
MsgBox(4)

;FUNC - Sort
vText := Sort("c`nb`na")
MsgBox(vText)

;FUNC - SoundBeep
SoundBeep(392, 500) ;G4
SoundBeep(392, 500) ;G4
SoundBeep(392, 500) ;G4
SoundBeep(311, 1000) ;Eb4
SoundBeep(349, 500) ;F4
SoundBeep(349, 500) ;F4
SoundBeep(349, 500) ;F4
SoundBeep(294, 1000) ;D4

;FUNC - SoundGet, SoundSet
vNum := SoundGet()
MsgBox(vNum)
Loop 11
{
	SoundSet(A_Index*10-10)
	SoundBeep()
}

;FUNC - SoundPlay
SoundPlay(A_WinDir "\Media\ding.wav")
MsgBox()
SoundPlay(A_WinDir "\Media\tada.wav")
MsgBox()
SoundPlay("*-1")
MsgBox()

;FUNC - SplitPath
vPath := A_AhkPath
SplitPath(vPath, vName, vDir, vExt, vNameNoExt, vDrive)
vOutput := Format("{}`r`n`r`n{}`r`n`r`n{}`r`n`r`n{}`r`n`r`n{}`r`n`r`n{}", vPath, vName, vDir, vExt, vNameNoExt, vDrive)
MsgBox(vOutput)

;FUNC - StatusBarGetText, StatusBarWait
;note: test on Notepad, it will wait for the caret to be at the start of the document
Sleep(1000)
vText := StatusBarGetText(2, "A")
Clipboard := vText
MsgBox(vText)
vText := A_Space A_Space " Ln 1, Col 1 " A_Space
StatusBarWait(vText,, 2, "A")
SoundBeep()

;FUNC - StringCaseSense
StringCaseSense("On")
MsgBox(!("A" != "a"))
StringCaseSense("Off")
MsgBox(!("A" != "a"))

;FUNC - StrLower, StrUpper
vText := "HeLLo"
vTextL := StrLower(vText)
vTextT := StrLower(vText, "T")
vTextU := StrUpper(vText)
MsgBox(vTextL "`r`n" vTextT "`r`n" vTextU)

;FUNC - SysGet
vAreSwapped := SysGet(23) ;SM_SWAPBUTTON := 23
MsgBox(vAreSwapped)

;FUNC - Thread (NoTimers)
SetTimer("MyTestThreadFunc1", 100)
vDelay := 10, vCount := 0, vStage := 0
Loop 210
{
	ToolTip(vCount)
	vCount++
	Sleep(vDelay)
	if (10 <= vCount) && (vCount <= 200) && (vStage = 0)
		Thread("NoTimers"), vStage := 1
	if (200 <= vCount) && (vStage = 1)
		Thread("NoTimers", 0)
}
ExitApp()
MyTestThreadFunc1()
{
	SoundBeep()
}

;FUNC - Thread (Priority)
;note: while the q subroutine is running,
;the loop cannot be interrupted
q::
Thread("Priority", 1)
w::
Loop 300
	Sleep(10)
SoundBeep()
SoundBeep()
return
e::MsgBox(A_ThisHotkey)
r::ExitApp()

;FUNC - Thread (Interrupt)
;note: this code may not be testing the function correctly
Thread("Interrupt", 3000, 500)
SetTimer("MyTestThreadFunc3", 250)
return
q::
Loop 200
{
	ToolTip(A_Index)
	Sleep(10)
}
ExitApp()
MyTestThreadFunc3()
{
	SoundBeep()
}

;FUNC - TraySetIcon
;note: check the systray for the AHK file icon
TraySetIcon(A_AhkPath, -160)
Sleep(6000)
ExitApp()

;FUNC - Type
MsgBox(Type("1")) ;String
MsgBox(Type(1)) ;Integer
MsgBox(Type(1.0)) ;Float
MsgBox(Type(["a"])) ;Object

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

;FUNC - DriveGetCapacity, DriveGetFilesystem, DriveGetLabel, DriveGetList, DriveGetSerial, DriveGetSpaceFree, DriveGetStatus, DriveGetStatusCD, DriveGetType
vDrive := "C:"
vList := DriveGetList()
vStatusCD := DriveGetStatusCD()
vCapacityMB := DriveGetCapacity(vDrive)
vCapacityGB := DriveGetCapacity(vDrive) // 1024
vFileSystem := DriveGetFilesystem(vDrive)
vLabel := DriveGetLabel(vDrive)
vSerial := DriveGetSerial(vDrive)
vFreeMB := DriveGetSpaceFree(vDrive)
vFreeGB := DriveGetSpaceFree(vDrive) // 1024
vStatus := DriveGetStatus(vDrive)
vType := DriveGetType(vDrive)

vOutput := ""
vOutput .= "`r`n" "drive list: " vList
vOutput .= "`r`n" "CD drive status: " vStatusCD
vOutput .= "`r`n"
vOutput .= "`r`n" "drive: " vDrive
vOutput .= "`r`n" "capacity: " vCapacityMB " MB (" vCapacityGB " GB)"
vOutput .= "`r`n" "file system: " vFileSystem
vOutput .= "`r`n" "label: " vLabel
vOutput .= "`r`n" "serial: " vSerial
vOutput .= "`r`n" "free: " vFreeMB " MB (" vFreeGB " GB)"
vOutput .= "`r`n" "status: " vStatus
vOutput .= "`r`n" "type: " vType
MsgBox(SubStr(vOutput, 3))

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

;FUNC - DriveEject
DriveEject(Drive) ;open CD drive
Sleep(4000)
DriveEject(Drive, 1) ;close CD drive (didn't work on my PC)

;NOT TESTED
;FUNC - DriveLock

;NOT TESTED
;FUNC - DriveSetLabel

;NOT TESTED
;FUNC - DriveUnlock

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

;FUNC - WinGetClass, WinGetClientPos, WinGetExStyle, WinGetID, WinGetIDLast, WinGetMinMax, WinGetPID, WinGetPos, WinGetProcessName, WinGetProcessPath, WinGetStyle, WinGetText, WinGetTitle, WinGetTransColor, WinGetTransparent, WinMove, WinSetAlwaysOnTop, WinSetEnabled, WinSetExStyle, WinSetStyle, WinSetTitle, WinSetTransColor, WinSetTransparent
vWinX := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosX")
vWinY := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosY")
vWinW := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosDX")
vWinH := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosDY")
hWnd := WinGetID("Untitled - Notepad ahk_class Notepad")
hWnd2 := WinGetIDLast("ahk_class Notepad")
MsgBox(hWnd "`r`n" hWnd2)

X := Y := Width := Height := 300
WinSetTitle("New Title", "ahk_id " hWnd)
WinMove(X, Y, Width, Height, "ahk_id " hWnd)
WinSetStyle(-0xC00000, "ahk_id " hWnd) ;WS_CAPTION := 0xC00000
WinSetExStyle(-0x100, "ahk_id " hWnd) ;WS_EX_WINDOWEDGE := 0x100
WinSetAlwaysOnTop(1, "ahk_id " hWnd)
ControlSetText("abc", "Edit1", "ahk_id " hWnd)
;WinSetTransparent(128, "ahk_id " hWnd)
;WinSetTransColor("000000", "ahk_id " hWnd)
;note: to set WinSetTransparent *and* WinSetTransColor, combine the two:
WinSetTransColor("000000 128", "ahk_id " hWnd)
WinSetEnabled(0, "ahk_id " hWnd)

vWinTitle := WinGetTitle("ahk_id " hWnd)
vWinClass := WinGetClass("ahk_id " hWnd)
vPID := WinGetPID("ahk_id " hWnd)
vPName := WinGetProcessName("ahk_id " hWnd)
vPPath := WinGetProcessPath("ahk_id " hWnd)
vWinStyle := Format("0x{:08X}", WinGetStyle("ahk_id " hWnd))
vWinExStyle := Format("0x{:08X}", WinGetExStyle("ahk_id " hWnd))
WinGetClientPos(X, Y, Width, Height, "ahk_id " hWnd)
vWinCPos := Format("x{} y{} w{} h{}", X, Y, Width, Height)
WinGetPos(X, Y, Width, Height, "ahk_id " hWnd)
vWinPos := Format("x{} y{} w{} h{}", X, Y, Width, Height)
vMinMax := WinGetMinMax("ahk_id " hWnd)
vText := WinGetText("ahk_id " hWnd)
vCol := WinGetTransColor("ahk_id " hWnd)
vTrans := WinGetTransparent("ahk_id " hWnd)

vOutput := hWnd
vOutput .= "`r`n" vWinTitle
vOutput .= "`r`n" vWinClass
vOutput .= "`r`n" vPID
vOutput .= "`r`n" vPName
vOutput .= "`r`n" vPPath
vOutput .= "`r`n" vWinStyle
vOutput .= "`r`n" vWinExStyle
vOutput .= "`r`n" vWinCPos
vOutput .= "`r`n" vWinPos
vOutput .= "`r`n" vMinMax
vOutput .= "`r`n" RegExReplace(vText, "[`r`n]", " ")
vOutput .= "`r`n" vCol
vOutput .= "`r`n" vTrans

;reset window
DetectHiddenWindows(1)
WinSetEnabled(1, "ahk_id " hWnd)
WinSetAlwaysOnTop(0, "ahk_id " hWnd)
WinSetTransColor("Off", "ahk_id " hWnd)
WinSetTransparent("Off", "ahk_id " hWnd)
WinRedraw("ahk_id " hWnd)

MsgBox("[" vOutput "]")

WinClose("ahk_id " hWnd)
vWinPos1 := Format("x{} y{} w{} h{}", vWinX, vWinY, vWinW, vWinH)
vWinPos2 := Format("x{} y{} w{} h{}", X, Y, Width, Height)
if !(vWinPos1 = vWinPos2)
{
	RegWrite(vWinX, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosX")
	RegWrite(vWinY, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosY")
	RegWrite(vWinW, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosDX")
	RegWrite(vWinH, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iWindowPosDY")
}

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

;FUNC - WinGetCount, WinGetControls, WinGetControlsHwnd, WinGetList
hWnd := WinExist("ahk_class Notepad")
vCount := WinGetCount("ahk_class Notepad")
oList1 := WinGetControls("ahk_id " hWnd)
oList2 := WinGetControlsHwnd("ahk_id " hWnd)
oList3 := WinGetList("ahk_class Notepad")
vOutput := vCount "`r`n"
Loop 3
{
	vOutput .= "`r`n"
	for vKey, vValue in oList%A_Index%
		vOutput .= vKey " " vValue "`r`n"
}
MsgBox(vOutput)

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

;FUNC - WinActivate, WinActivateBottom, WinClose, WinHide, WinKill, WinMaximize, WinMinimize, WinMinimizeAll, WinMinimizeAllUndo, WinMoveBottom, WinMoveTop, WinRedraw, WinRestore, WinSetRegion, WinShow, WinWait, WinWaitActive, WinWaitClose, WinWaitNotActive
;note: try each block of code separately
WinActivate("ahk_class WordPadClass")

WinActivateBottom("ahk_class WordPadClass")

WinClose("ahk_class WordPadClass")

hWnd := WinExist("ahk_class Notepad")
WinHide("ahk_id " hWnd)
Sleep(2000)
WinShow("ahk_id " hWnd)

WinKill("ahk_class WordPadClass")

hWnd := WinExist("A")
WinMaximize("ahk_class Notepad")
Sleep(1000)
WinMinimize("ahk_class Notepad")
Sleep(1000)
WinMaximize("ahk_class Notepad")
WinRestore("ahk_class Notepad")
WinActivate("ahk_id " hWnd)

hWnd := WinExist("A")
WinMinimizeAll()
Sleep(1000)
WinMinimizeAllUndo()
WinActivate("ahk_id " hWnd)

hWnd := WinExist("ahk_class Notepad")
Sleep(2000)
SoundBeep()
WinMoveBottom("ahk_id " hWnd)
Sleep(1000)
SoundBeep()
WinMoveTop("ahk_id " hWnd)
Sleep(2000)
WinActivate("ahk_id " hWnd)

;NOT TESTED
WinRedraw("ahk_class Notepad")

WinSetRegion("50-0 W200 H250", "ahk_class Notepad")
Sleep(1000)
WinSetRegion(, "ahk_class Notepad")

Run("wordpad")
WinWait("ahk_class WordPadClass")
hWnd := WinExist()
SoundBeep()
WinWaitClose("ahk_id " hWnd)
SoundBeep()

Run("wordpad")
WinWaitActive("ahk_class WordPadClass")
hWnd := WinExist()
SoundBeep()
WinWaitNotActive("ahk_class WordPadClass")
SoundBeep()
WinClose("ahk_id " hWnd)

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

;FUNC - ControlGetEnabled, ControlGetExStyle, ControlGetHwnd, ControlGetPos, ControlGetStyle, ControlGetText, ControlMove, ControlSetEnabled, ControlSetExStyle, ControlSetStyle, ControlSetText
hCtl := ControlGetHwnd("Edit1", "A")
ControlSetStyle(Value,, "ahk_id " hCtl)
ControlSetExStyle(Value,, "ahk_id " hCtl)
ControlMove(300, 300, 300, 300,, "ahk_id " hCtl)
if (ControlGetText(, "ahk_id " hCtl) = "")
	ControlSetText("New Text",, "ahk_id " hCtl)
ControlSetEnabled(Value,, "ahk_id " hCtl)
vState := ControlGetEnabled(, "ahk_id " hCtl)
vCtlStyle := Format("0x{:08X}", ControlGetStyle(, "ahk_id " hCtl))
vCtlExStyle := Format("0x{:08X}", ControlGetExStyle(, "ahk_id " hCtl))
ControlGetPos(X, Y, Width, Height,, "ahk_id " hCtl)
vCtlPos := Format("x{} y{} w{} h{}", X, Y, Width, Height)
vText := ControlGetText(, "ahk_id " hCtl)

vOutput := hCtl
vOutput .= "`r`n" vCtlStyle
vOutput .= "`r`n" vCtlExStyle
vOutput .= "`r`n" vCtlPos
vOutput .= "`r`n" RegExReplace(vText, "[`r`n]", " ")

;FUNC - ControlGetVisible, ControlHide, ControlShow
hCtl := ControlGetHwnd("Edit1", "A")
vState := ControlGetVisible(, "ahk_id " hCtl)
MsgBox(vState)
ControlHide(, "ahk_id " hCtl)
Sleep(1000)
ControlShow(, "ahk_id " hCtl)

;FUNC - ControlAddItem, ControlChoose, ControlChooseString, ControlDeleteItem, ControlFindItem, ControlGetChoice, ControlGetList, ControlHideDropDown, ControlShowDropDown
;note: run on Notepad, this shows the Open dialog
if !WinActive("ahk_class Notepad")
	return
hWnd := WinExist()
PostMessage(0x111, 2,,, "ahk_id " hWnd) ;WM_COMMAND := 0x111 ;Open...
WinWaitActive("ahk_class #32770")
hWnd2 := WinExist()
hCtl := ControlGetHwnd("ComboBox3", "ahk_id " hWnd2)
vChoice := ControlGetChoice(, "ahk_id " hCtl)
vIndex := ControlFindItem("UTF-8",, "ahk_id " hCtl)
vList := ControlGetList(,, "ahk_id " hCtl)
MsgBox(vChoice "`r`n`r`n" vIndex "`r`n`r`n" vList)
Sleep(1000)
ControlChoose(2,, "ahk_id " hCtl)
Sleep(1000)
ControlChooseString("Unic",, "ahk_id " hCtl)
Loop 4
	ControlDeleteItem(1,, "ahk_id " hCtl)
ControlAddItem("My Encoding 1",, "ahk_id " hCtl)
ControlAddItem("My Encoding 2",, "ahk_id " hCtl)
ControlShowDropDown(, "ahk_id " hCtl)
Sleep(1000)
ControlHideDropDown(, "ahk_id " hCtl)

;FUNC - ControlGetCurrentCol, ControlGetCurrentLine, ControlGetLine, ControlGetLineCount, ControlGetSelected
hCtl := ControlGetHwnd("Edit1", "A")
vLineCount := ControlGetLineCount(, "ahk_id " hCtl)
vCol := ControlGetCurrentCol(, "ahk_id " hCtl)
vLine := ControlGetCurrentLine(, "ahk_id " hCtl)
vLineText := ControlGetLine(vLine,, "ahk_id " hCtl)
vTextSel := ControlGetSelected(, "ahk_id " hCtl)
MsgBox(vLineCount "`r`n" vCol "`r`n" vLine "`r`n" vLineText "`r`n`r`n" vTextSel)

;FUNC - ControlEditPaste, ControlSend, ControlSendRaw
hCtl := ControlGetHwnd("Edit1", "A")
Sleep(1000)
ControlEditPaste("abc",, "ahk_id " hCtl)
ControlSend("def",, "ahk_id " hCtl)
ControlSendRaw("ghi",, "ahk_id " hCtl)

;FUNC - ControlGetTab, ControlSetTab
;this test makes use of the Folder Options dialog
Run("rundll32 shell32.dll,Options_RunDLL") ;Folder Options, General tab
WinWaitActive("ahk_class #32770")
hWnd := WinExist()
hCtl := ControlGetHwnd("SysTabControl321", "ahk_id " hWnd)
vIndex := ControlGetTab(, "ahk_id " hCtl)
MsgBox(vIndex)
ControlSetTab(2,, "ahk_id " hCtl)

;FUNC - ControlClick, ControlFocus, ControlGetChecked, ControlGetFocus, ControlSetChecked
;note: run on Notepad, this shows the Find dialog
if !WinActive("ahk_class Notepad")
	return
hWnd := WinExist()
PostMessage(0x111, 21,,, "ahk_id " hWnd) ;WM_COMMAND := 0x111 ;Find...
WinWaitActive("ahk_class #32770")
hWnd2 := WinExist()
ControlSetChecked(1, "Button2", "ahk_id " hWnd2)
ControlClick("Button4", "ahk_id " hWnd2)
ControlFocus("Button2", "ahk_id " hWnd2)
vState := ControlGetChecked("Button2", "ahk_id " hWnd2)
vCtlClassNN := ControlGetFocus("ahk_id " hWnd2)
MsgBox(vState "`r`n" vCtlClassNN)

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

;FUNC - IniDelete, IniRead, IniWrite
vDir := A_Desktop "\z ahk test files"
Loop 2
{
	vEnc := (A_Index = 1) ? "CP0" : "UTF-16"
	if !DirExist(vDir)
		DirCreate(vDir)
	vPath := vDir "\z ini " vEnc " " A_AhkVersion ".txt"
	if FileExist(vPath)
		continue
	FileAppend("", vPath, vEnc)
	if !FileExist(vPath)
		continue
	Loop 3
	{
		vSection := "Section" A_Index
		Loop 3
			IniWrite("Value" A_Index, vPath, vSection, "Key" A_Index)
	}
	IniDelete(vPath, "Section2")
	IniDelete(vPath, "Section3", "Key2")
	vText1 := IniRead(vPath, "Section1")
	vText2 := IniRead(vPath, "Section2")
	vText3 := IniRead(vPath, "Section3", "Key1")
	vText4 := IniRead(vPath, "Section3", "Key2")
	MsgBox(vText1 "`r`n=====`r`n" vText2 "`r`n=====`r`n" vText3 "`r`n=====`r`n" vText4)
}
MsgBox("done")

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

;FUNC - RegRead, RegWrite
;note: write down the current font size if you want to reset it later
vFontSize := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iPointSize") // 10
MsgBox(vFontSize)
vFontSize := 36
RegWrite(vFontSize*10, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iPointSize")
vFontSize := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad", "iPointSize") // 10
MsgBox(vFontSize)
Run("notepad.exe")

;FUNC - RegDelete, RegDeleteKey
RegWrite(123, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Notepad\MyTempKey", "MyValue")
vMyValue := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad\MyTempKey", "MyValue")
MsgBox(vMyValue)
RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Notepad\MyTempKey", "MyValue")
vMyValue := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Notepad\MyTempKey", "MyValue")
MsgBox(vMyValue)
RegDeleteKey("HKEY_CURRENT_USER\Software\Microsoft\Notepad\MyTempKey")
MsgBox("done")

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

;FUNC - DirSelect, FileSelect
MsgBox(DirSelect())
MsgBox(FileSelect())

;FUNC - Download
vDir := A_Desktop "\z ahk test files"
if !DirExist(vDir)
	DirCreate(vDir)
;vUrl := "https://autohotkey.com/download/1.1/version.txt"
vUrl := "http://autohotkey.com/download/2.0/version.txt"
;SplitPath(vUrl, vName)
;vName := "AutoHotkey Latest Version.txt"
vName := "z dl " A_AhkVersion ".txt"
vPath := vDir "\" vName
Download(vUrl, vPath)
Run(vDir)

;FUNC - DirCopy, DirCreate, DirDelete, DirExist, DirMove
vDir := A_Desktop "\z ahk test files"
vDir1 := vDir "\z " A_AhkVersion
vDir2 := vDir "\z " A_AhkVersion " COPY"
vDir1New := vDir "\z " A_AhkVersion " MOVE"
DirCreate(vDir1)
DirCopy(vDir1, vDir2)
MsgBox(DirExist(vDir1))
DirMove(vDir1, vDir1New)
MsgBox(DirExist(vDir1))
DirDelete(vDir1New)
DirDelete(vDir2)

;FUNC - FileAppend, FileCopy, FileDelete, FileMove
vDir := A_Desktop "\z ahk test files"
if !DirExist(vDir)
	DirCreate(vDir)
vPath1 := vDir "\z file " A_AhkVersion ".txt"
vPath2 := vDir "\z file " A_AhkVersion " COPY.txt"
vPath1New := vDir "\z file " A_AhkVersion " MOVE.txt"
FileAppend("", vPath1) ;create file 'FileCreate'
FileCopy(vPath1, vPath2)
MsgBox(FileExist(vPath1))
FileMove(vPath1, vPath1New)
MsgBox(FileExist(vPath1))
FileDelete(vPath1New)
FileDelete(vPath2)

;FUNC - FileRecycle, FileRecycleEmpty
;warning: you may not want to empty the recycle bin
vDir := A_Desktop "\z ahk test files"
if !DirExist(vDir)
	DirCreate(vDir)
vPath := vDir "\z rec " A_AhkVersion ".txt"
FileAppend("", vPath)
FileRecycle(vPath)
Run("::{645ff040-5081-101b-9f08-00aa002f954e}") ;open Recycle Bin
MsgBox()
;FileRecycleEmpty("C:")

;FUNC - FileCreateShortcut, FileGetShortcut
vDir := A_Desktop "\z ahk test files"
if !DirExist(vDir)
	DirCreate(vDir)
Run(vDir)
vPathLnk := vDir "\z ahk " A_AhkVersion ".lnk"
vTarget := A_AhkPath
FileCreateShortcut(vTarget, vPathLnk)
FileGetShortcut(vPathLnk, vTarget)
MsgBox(vTarget)

;FUNC - FileGetVersion
vText := FileGetVersion(A_AhkPath) "`r`n" A_AhkVersion
MsgBox(vText)

;FUNC - FileEncoding, FileGetAttrib, FileGetSize, FileGetTime, FileRead, FileSetAttrib, FileSetTime
vDir := A_Desktop "\z ahk test files"
if !DirExist(vDir)
	DirCreate(vDir)
vEnc1 := "CP0"
vEnc2 := "UTF-8"
Loop 2
{
	if (A_Index = 1)
		continue
	vEnc := vEnc%A_Index%
	vPath := vDir "\z attrib " vEnc " " A_AhkVersion ".txt"
	FileEncoding(vEnc)
	MsgBox(A_FileEncoding)
	FileAppend("abcde", vPath)
	FileSetTime(20060504, vPath)
	FileSetTime(20030201, vPath, "C")
	FileSetAttrib("+R", vPath)
	vText := FileRead(vPath)
	vAttrib := FileGetAttrib(vPath)
	vSize := FileGetSize(vPath)
	vDateM := FileGetTime(vPath)
	vDateC := FileGetTime(vPath, "C")
	FileSetAttrib("-R", vPath)
	vOutput := vText "`r`n" vAttrib "`r`n" vSize "`r`n" vDateM "`r`n" vDateC
	MsgBox(vOutput)
}

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

*/

;==================================================
[EDIT:] Fixes/additional tests:

Code: Select all

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

;FIXES

;FUNC (fix) - CallbackCreate
;before:
pFunc := CallbackCreate("MyCallbackFunc", "F")
;after:
pFunc := CallbackCreate("MyCallbackFunc", "F", 3)

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

;IMPROVED TESTS

;FUNC - Thread (Interrupt)
;Thread: Interrupt - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=46811&p=210977#p210977
ListLines(0)
;Thread("Interrupt", 5000, -1) ;uninterruptible for 5 seconds
Thread("Interrupt", -1, 1000000) ;uninterruptible for 1000000 lines
vCount := 0
SoundBeep()
q::
vTickCount := A_TickCount, vCount += 1
Loop
	vCount += 1, Sleep(-1) ;note: Sleep(-1) slows down the script but ensures a vCount value that it is closer to the limit
return
q up::
MsgBox(vCount "`r`n" (A_TickCount-vTickCount))
ExitApp()

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

;NEW TESTS

;FUNC - Float
MsgBox(Float(1) " " Float(-1))
MsgBox(Float("a")) ;error

;FUNC - Integer
MsgBox(Integer(1.5) " " Integer(-1.5) "`r`n" Floor(1.5) " " Floor(-1.5))
MsgBox(Integer("a")) ;error

;FUNC - String
class MyToStringClass
{
	ToString()
	{
		return "str"
	}
}
MsgBox(String(new MyToStringClass))
MsgBox(String({ToString:"str"})) ;error

;FUNC - SysGetIPAddresses
MsgBox(SysGetIPAddresses().Length() "`r`n" SysGetIPAddresses().1)

;FUNC - WinRedraw
WinActivate("ahk_class Notepad")
Sleep(1000)
WinRedraw("ahk_class Notepad")

;==================================================
Last edited by jeeswg on 09 Oct 2018, 18:26, edited 3 times in total.
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

31 Jul 2018, 10:16

- Some new code for the next update: DirExist fix, Float/Integer/String backport attempts.
- As ever please notify of any issues or of any solutions for queries mentioned in the previous post. Thanks.

Code: Select all

DirExist(FilePattern)
{
    Loop Files, %FilePattern%, D
        return A_LoopFileAttrib
}

Float(Value)
{
    if Value is number
        return Value + 0.0
}
Integer(Value)
{
    if Value is number
        return Value < 0 ? Ceil(Value) : Floor(Value)
}
String(Value)
{
    if !IsObject(Value)
        return "" Value
    try
        return Value.ToString()
}
Helgef
Posts: 3303
Joined: 17 Jul 2016, 01:02
Contact:

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

01 Aug 2018, 02:15

Code: Select all

String(Value)
{
    if !IsObject(Value)
        return "" Value
    try
        return Value.ToString()
}
Why do you use try? Calling a non-existent method in v1 does not throw an exception*, if there is an exception thrown in the tostring method it should not be suppressed by your function. If the object does not have a toString method, your function should throw. Additionally, the integer and float functions should both do else throw ...

edit: *Except for comobjs I guess.
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

01 Aug 2018, 08:52

- @Helgef: Thanks, but is it possible to reliably check if a method exists?
- Another issue for perfect reproduction is identifying whether a number is a Float or not, the same problem with recreating Type. These functions work almost identically apart from formatting numbers.
- Here is a test script, with updated Float/Integer/String functions.

Code: Select all

class MyClass1
{
	ToString()
	{
		return "str"
	}
}
class MyClass2
{
	ToString()
	{
		return {}
	}
}

var1 := "a"
var2 := "1"
var3 := "1.1"
var4 := 1
var5 := 1.1
var6 := {}
var7 := {ToString:"str"}
var8 := new MyClass1
var9 := new MyClass2

;vTemp := String(var6) ;Unknown method.
;vTemp := String(var7) ;Call to nonexistent function.
;vTemp := Integer(var1) ;Type mismatch.
;vTemp := Integer(var6) ;Type mismatch.
;vTemp := Integer(var7) ;Type mismatch.
;vTemp := Integer(var8) ;Type mismatch.
;vTemp := Float(var1) ;Type mismatch.
;vTemp := Float(var6) ;Type mismatch.
;vTemp := Float(var7) ;Type mismatch.
;vTemp := Float(var8) ;Type mismatch.

vFunc1 := "String"
vFunc2 := "Integer"
vFunc3 := "Float"

Loop 3
{
	vFunc := vFunc%A_Index%
	vOutput := ""
	Loop 9
		try vOutput .= A_Index " " %vFunc%(var%A_Index%) "`r`n"
		catch
			vOutput .= A_Index "`r`n"
	Clipboard := vOutput
	MsgBox(vOutput)
}
return

MsgBox(Text) ;simplified version of MsgBox function
{
    MsgBox %Text%
}
Float(Value)
{
    if Value is number
        return Value + 0.0
    else
        throw "Type mismatch."
}
Integer(Value)
{
    if Value is number
        return Value < 0 ? Ceil(Value) : Floor(Value)
    else
        throw "Type mismatch."
}
String(Value)
{
    if !IsObject(Value)
        return "" Value
    else if !Value.HasKey("ToString")
    && !IsFunc(Value.ToString)
        throw "Unknown method."
    else if !IsFunc(Value.ToString)
        throw "Call to nonexistent function."
    else
        return Value.ToString()
}
Last edited by jeeswg on 01 Aug 2018, 14:14, edited 1 time in total.
User avatar
nnnik
Posts: 3539
Joined: 30 Sep 2013, 01:01
Location: Germany

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

01 Aug 2018, 10:45

Yes there is a reliable way of checking whether a specific method exists inside an object. However there is not a single reliable way of checking whether calling a specific method will or will not result in correct handling.
Recommends AHK Studio
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

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

01 Aug 2018, 11:53

- I've started a new thread here, if anyone wants to talk more about method/property existence.
objects: check if a method/property exists - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=53157
- Re. checking if a method exists, you can see what I tried to in the example above. If you have other ideas please post them in the link I just mentioned.
- Re.
checking whether calling a specific method will or will not result in correct handling
Yes, AFAICS you could end up with an error when doing Value.ToString(). The user would have to handle that error via 'try' or OnError or whatever.
Helgef
Posts: 3303
Joined: 17 Jul 2016, 01:02
Contact:

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

01 Aug 2018, 13:51

Code: Select all

Float(Value)
{
    if Value is number
        return Value + 0.0
    else if !Value.HasKey("ToString")
        throw "Type mismatch."
}
Why Value.HasKey? It should be

Code: Select all

Float(Value)
{
    if Value is number
        return Value + 0.0
	throw exception("Type mismatch.", -1)
}

Code: Select all

String(Value)
{
    if !IsObject(Value)
        return "" Value
    else if !Value.HasKey("ToString")
    && !IsFunc(Value.ToString)
        throw "Unknown method."
    else if !IsFunc(Value.ToString)
        throw "Call to nonexistent function."
    else
        return Value.ToString()
}
haskey makes no sense here, most often the method is stored in a base object. I'd do something like this instead, I think it is good enough in most common cases, it is not hard to find flaws in it though,

Code: Select all

String(Value)
{
	local 
	if !IsObject(Value)
        return "" Value
	if (m := Value.ToString) == ""
		throw exception("Unknown method.", -1, "ToString")
	if !isobject(m) && !isfunc(m)
		throw exception("Call to nonexistent function.", -1, m)
	return %m%(Value)
}
}
You cannot recreate the function perfectly for v1, you cannot know if __call will handle a call to a method for example.
User avatar
nnnik
Posts: 3539
Joined: 30 Sep 2013, 01:01
Location: Germany

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

01 Aug 2018, 14:08

I was not refering to throw I was refering to __Call COM Objects and other object types which implement the ToString method without returning it when you try to get it. Or in other words you cannot know for sure whether it is safe to call ToString without doing an infinite amount of work.
Recommends AHK Studio

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 4 guests