commands as functions (AHK v2 functions for AHK v1) - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 18#p210818
==================================================
[Changelog:]
Code: Select all
;AHK v2 functions for AHK v1 changelog
;[created: 2017-03-26]
;[updated: 2017-08-25]
;added - ClipboardAll placeholder, ControlXXX, DriveXXX, InputEnd, RandomSeed
;corrected - SoundPlay, StrLower, StrUpper, Type
;modified - FileAppend, FileRead, FileSetAttrib, FileSetTime, MsgBox, RegDelete, RegRead, RegWrite, TrayTip, WinMove, WinSetEnabled, WinSetTitle
;removed - Deref, GuiXXX
;tidied - EnvSet, PixelSearch, RegDeleteKey, WinGetPos
;[updated: 2017-08-25]
;modified - InputBox, MsgBox
;tidied - Download
;[updated: 2018-01-29]
;added - CaretGetPos, TraySetIcon, WinGetClientPos
;modified - ClipboardAll (placeholder), ControlAddItem, ControlChoose, ControlChooseString, FileRead, PostMessage, RegDeleteKey, SendMessage, SoundGet, SoundSet
;corrected - ControlSendRaw, DriveLock, DriveSetLabel, MsgBox
;modified+ - changed optional parameters: ControlGetList, ControlSend, ControlSendRaw, ControlSetText, DriveEject, DriveGetList, DriveGetStatusCD, FileAppend
;removed - Menu
;tidied - MsgBox, RegDelete, RegRead, RegWrite, WinSetTitle
At the time of writing (March 2017), AHK v2 alpha introduces 139+50=189 new functions.
- 139 are function versions of AHK v1 commands (with the same name as existing AHK v1 commands).
- 50 are variants of AHK v1 commands (with names different from any existing AHK v1 commands) or are functions that introduce new functionality.
List of functions (needed for the library):
Code: Select all
;based on:
;list of every command/function/variable from across all versions - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=27321&p=131642#p131642
;function versions of commands present in both AHK v1/v2 (139)
BlockInput
Click
ClipWait
Control
ControlClick
ControlFocus
ControlGet
ControlGetFocus
ControlGetPos
ControlGetText
ControlMove
ControlSend
ControlSendRaw
ControlSetText
CoordMode
Critical
DetectHiddenText
DetectHiddenWindows
Drive
DriveGet
Edit
EnvGet
EnvSet
Exit
ExitApp
FileAppend
FileCopy
FileCreateShortcut
FileDelete
FileEncoding
FileGetAttrib
FileGetShortcut
FileGetSize
FileGetTime
FileGetVersion
FileInstall
FileMove
FileRead
FileRecycle
FileRecycleEmpty
FileSetAttrib
FileSetTime
FormatTime
GroupActivate
GroupAdd
GroupClose
GroupDeactivate
Gui
GuiControl
GuiControlGet
Hotkey
ImageSearch
IniDelete
IniRead
IniWrite
Input
InputBox
KeyHistory
KeyWait
ListHotkeys
ListLines
ListVars
Menu
MouseClick
MouseClickDrag
MouseGetPos
MouseMove
MsgBox
OutputDebug
Pause
PixelGetColor
PixelSearch
PostMessage
Random
RegDelete
RegRead
RegWrite
Reload
Run
RunAs
RunWait
Send
SendEvent
SendInput
SendLevel
SendMessage
SendMode
SendPlay
SendRaw
SetCapsLockState
SetControlDelay
SetDefaultMouseSpeed
SetKeyDelay
SetMouseDelay
SetNumLockState
SetRegView
SetScrollLockState
SetStoreCapslockMode
SetTimer
SetTitleMatchMode
SetWinDelay
SetWorkingDir
Shutdown
Sleep
Sort
SoundBeep
SoundGet
SoundPlay
SoundSet
SplitPath
StatusBarGetText
StatusBarWait
StringCaseSense
Suspend
SysGet
Thread
ToolTip
TrayTip
WinActivate
WinActivateBottom
WinClose
WinGetClass
WinGetPos
WinGetText
WinGetTitle
WinHide
WinKill
WinMaximize
WinMinimize
WinMinimizeAll
WinMinimizeAllUndo
WinMove
WinRestore
WinSetTitle
WinShow
WinWait
WinWaitActive
WinWaitClose
WinWaitNotActive
;commands added from AHK v2 (50)
DateAdd
DateDiff
Deref
DirCopy
DirCreate
DirDelete
DirExist
DirMove
DirSelect
Download
FileSelect
MenuSelect
MonitorGet
MonitorGetCount
MonitorGetName
MonitorGetPrimary
MonitorGetWorkArea
ProcessClose
ProcessExist
ProcessSetPriority
ProcessWait
ProcessWaitClose
RegDeleteKey
StrLower
StrUpper
Type
WinGetControls
WinGetControlsHwnd
WinGetCount
WinGetExStyle
WinGetID
WinGetIDLast
WinGetList
WinGetMinMax
WinGetPID
WinGetProcessName
WinGetProcessPath
WinGetStyle
WinGetTransColor
WinGetTransparent
WinMoveBottom
WinMoveTop
WinRedraw
WinSetAlwaysOnTop
WinSetEnabled
WinSetExStyle
WinSetRegion
WinSetStyle
WinSetTransColor
WinSetTransparent
Code: Select all
;old AHK v1 functions (7)
Asc
ComObjEnwrap
ComObjMissing
ComObjParameter
ComObjUnwrap
ObjInsert
ObjRemove
;old AHK v1 commands (57)
AutoTrim
DriveSpaceFree
EnvAdd
EnvDiv
EnvMult
EnvSub
EnvUpdate
FileCopyDir
FileCreateDir
FileMoveDir
FileReadLine
FileRemoveDir
FileSelectFile
FileSelectFolder
IfEqual
IfExist
IfGreater
IfGreaterOrEqual
IfInString
IfLess
IfLessOrEqual
IfMsgBox
IfNotEqual
IfNotExist
IfNotInString
IfWinActive
IfWinExist
IfWinNotActive
IfWinNotExist
Process
Progress
SetBatchLines
SetEnv
SetFormat
SoundGetWaveVolume
SoundSetWaveVolume
SplashImage
SplashTextOff
SplashTextOn
StringGetPos
StringLeft
StringLen
StringLower
StringMid
StringReplace
StringRight
StringSplit
StringTrimLeft
StringTrimRight
StringUpper
Transform
UrlDownloadToFile
WinGet
WinGetActiveStats
WinGetActiveTitle
WinMenuSelectItem
WinSet
==================================================
I recently found out that Coco has been working on a similar project.
- I would say that his code is 98% the same as mine, plus he has some nice RegEx for the 'InputBox' function, and has recreated the 'Type' function, which is the one function I was yet to write.
- So reluctantly I think it would be better to support his effort, rather than cause massive confusion, with two independent sets of almost identical code.
Example functions:
Code: Select all
IniWrite(Value, Filename, Section, Key:="") ;Coco
{
IniWrite %Value%, %Filename%, %Section%, %Key%
return !ErrorLevel
}
IniWrite(Value, Filename, Section, Key:="") ;jeeswg
{
IniWrite, % Value, % Filename, % Section, % Key
return !ErrorLevel
}
https://github.com/cocobelgica/AutoHotkey-Future
The last work there was done in March 2016, MsgBox/InputBox/TrayTip for example, may need to be updated.
Useful comments regarding the functions (and potential issues/problems) are available here:
Default/Portable installation StdLib - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 13&t=10434
AutoHotkey-Future/Lib at master · cocobelgica/AutoHotkey-Future · GitHub
https://github.com/cocobelgica/AutoHotk ... master/Lib
The code from Mar 2016 has:
- 136 'AHK v1' functions (missing Edit/FileAppend/PostMessage/SendMessage) (EnvUpdate is there but shouldn't be).
- 49 'AHK v2' functions (missing RegDeleteKey).
Some code I wrote in Coco's style for the missing functions:
Code: Select all
Edit()
{
Edit
}
FileAppend(Text:="", Filename:="", Encoding:="")
{
FileAppend %Text%, %Filename%, %Encoding%
return !ErrorLevel
}
PostMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
PostMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if (ErrorLevel = "FAIL")
ErrorLevel := "ERROR"
}
RegDeleteKey(RootKeySubKey)
{
RegDelete %RootKeySubKey%
return !ErrorLevel
}
SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")
{
SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
if (ErrorLevel = "FAIL")
ErrorLevel := "ERROR"
}
Code: Select all
;w:: ;convert multiline text to one-liners for variable assignment
;vText := JEE_GetSelectedText()
ControlGet, vText, Selected, , Edit1, A
vText := StrReplace(vText, "``", "````")
vText := StrReplace(vText, "`r`n", "``n") ;for LF
;vText := StrReplace(vText, "`r`n", "``r``n") ;for CRLF
vText := StrReplace(vText, "%", "```%")
vText := StrReplace(vText, ";", "```;")
Clipboard := "vText = " vText
;SendInput ^v
return
q:: ;collect code from individual small ahk files and put onto clipboard
vTextEdit = Edit()`n{`n Edit`n}
vTextFileAppend = FileAppend(Text:="", Filename:="", Encoding:="")`n{`n FileAppend `%Text`%, `%Filename`%, `%Encoding`%`n return !ErrorLevel`n}
vTextPostMessage = PostMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")`n{`n PostMessage `%Msg`%, `%wParam`%, `%lParam`%, `%Control`%, `%WinTitle`%, `%WinText`%, `%ExcludeTitle`%, `%ExcludeText`%`n if (ErrorLevel = "FAIL")`n ErrorLevel := "ERROR"`n}
vTextRegDeleteKey = RegDeleteKey(RootKeySubKey)`n{`n RegDelete `%RootKeySubKey`%`n return !ErrorLevel`n}
vTextSendMessage = SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")`n{`n SendMessage `%Msg`%, `%wParam`%, `%lParam`%, `%Control`%, `%WinTitle`%, `%WinText`%, `%ExcludeTitle`%, `%ExcludeText`%, `%Timeout`%`n if (ErrorLevel = "FAIL")`n ErrorLevel := "ERROR"`n}
;functions to add to final text
vListA := "Edit,FileAppend,PostMessage,RegDeleteKey,SendMessage"
;functions to remove from final text
vListR := "EnvUpdate"
vDir = %A_Desktop%\AutoHotkey-Future-master\Lib
if !InStr(FileExist(vDir), "D")
return
vList := "`n"
Loop, Files, % vDir "\*.ahk", F
{
vPath := A_LoopFileFullPath
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
vList .= vNameNoExt "`n"
}
Loop, Parse, vListA, `,
if !InStr(vList, "`n" A_LoopField "`n")
vList .= A_LoopField "`n"
vList := Trim(vList, "`n")
Sort, vList
vOutput := ""
VarSetCapacity(vOutput, 100000*2)
Loop, Parse, vList, `n
{
if A_LoopField in % vListR
continue
vPath := vDir "\" A_LoopField ".ahk"
if FileExist(vPath)
FileRead, vText, % vPath
else
vText := vText%A_LoopField%
vText := StrReplace(vText, "`n", "`r`n")
vOutput .= vText "`r`n"
}
;trim trailing spaces
vOutput := RegExReplace(vOutput, "m) +$")
Clipboard := vOutput
MsgBox % "done"
return
A beta demonstration of what an 'AHK v2 functions for AHK v1' library might look like, based on Coco's code.
Note: FileInstall cannot be completely recreated as a function. [EDIT:][Actually, the post below mentions some workarounds.]
Note: The Gui command would make any script that uses such a library #Persistent, so I would advise commenting out that function. [EDIT:][You could have just the Gui function in a separate file if you wanted it some times but not other times.]
Code: Select all
;AHK v2 functions for AHK v1
BlockInput(Mode)
{
BlockInput %Mode%
}
Click(Params*)
{
local i, Param, Args
for i, Param in Params
Args .= " " . Param
Click %Args%
}
ClipWait(SecondsToWait:="", Param:=1)
{
ClipWait %SecondsToWait%, %Param%
return !ErrorLevel
}
Control(Cmd, Value:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
Control %Cmd%, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
ControlClick(ControlOrPos:="", WinTitle:="", WinText:="", WhichButton:="", ClickCount:="", Options:="", ExcludeTitle:="", ExcludeText:="")
{
ControlClick %ControlOrPos%, %WinTitle%, %WinText%, %WhichButton%, %ClickCount%, %Options%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
ControlFocus(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
ControlFocus %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
ControlGet(Cmd, Value:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
ControlGet OutputVar, %Cmd%, %Value%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if !ErrorLevel
return OutputVar
}
ControlGetFocus(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
ControlGetFocus OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if !ErrorLevel
return OutputVar
}
ControlGetPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
ControlGetPos X, Y, Width, Height, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
ControlGetText(Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
ControlGetText OutputVar, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if !ErrorLevel
return OutputVar
}
ControlMove(Control:="", X:="", Y:="", Width:="", Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
ControlMove %Control%, %X%, %Y%, %Width%, %Height%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
ControlSend(Control:="", Keys:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
ControlSend %Control%, %Keys%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
ControlSendRaw(Control:="", Keys:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
ControlSendRaw %Control%, %Keys%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
ControlSetText(Control:="", NewText:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
ControlSetText %Control%, %NewText%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
CoordMode(Param1, Param2:="Screen")
{
CoordMode %Param1%, %Param2%
}
Critical(Param:="")
{
Critical %Param%
}
DateAdd(DateTime, Time, TimeUnits)
{
EnvAdd DateTime, %Time%, %TimeUnits%
return DateTime
}
DateDiff(DateTime1, DateTime2, TimeUnits)
{
EnvSub DateTime1, %DateTime2%, %TimeUnits%
return DateTime1
}
Deref(String)
{
local OutputVar
Transform OutputVar, Deref, %String%
return OutputVar
}
DetectHiddenText(OnOrOff)
{
DetectHiddenText %OnOrOff%
}
DetectHiddenWindows(OnOrOff)
{
DetectHiddenWindows %OnOrOff%
}
DirCopy(Source, Dest, Flag:=0)
{
FileCopyDir %Source%, %Dest%, %Flag%
return !ErrorLevel
}
DirCreate(DirName)
{
FileCreateDir %DirName%
return !ErrorLevel
}
DirDelete(DirName, Recurse:=0)
{
FileRemoveDir %DirName%, %Recurse%
return !ErrorLevel
}
DirExist(FilePattern)
{
local AttributeString := FileExist(FilePattern)
return InStr(AttributeString, "D") ? AttributeString : ""
}
DirMove(Source, Dest, Flag:=0)
{
FileMoveDir %Source%, %Dest%, %Flag%
return !ErrorLevel
}
DirSelect(StartingFolder:="", Options:=1, Prompt:="")
{
local OutputVar
FileSelectFolder OutputVar, %StartingFolder%, %Options%, %Prompt%
if !ErrorLevel
return OutputVar
}
Download(URL, FileName)
{
URLDownloadToFile %URL%, %FileName%
return !ErrorLevel
}
Drive(SubCommand, Drive:="", Value:="")
{
Drive %SubCommand%, %Drive%, %Value%
return !ErrorLevel
}
DriveGet(Cmd, Value:="")
{
local OutputVar
if (Cmd != "SpaceFree")
DriveGet OutputVar, %Cmd%, %Value%
else
DriveSpaceFree, OutputVar, %Value%
if !ErrorLevel
return OutputVar
}
Edit()
{
Edit
}
EnvGet(EnvVarName)
{
local OutputVar
EnvGet OutputVar, %EnvVarName%
return OutputVar
}
EnvSet(EnvVar, Value:="")
{
EnvSet, %EnvVar%, %Value%
return !ErrorLevel
}
Exit(ExitCode:=0)
{
Exit %ExitCode%
}
ExitApp(ExitCode:=0)
{
ExitApp %ExitCode%
}
FileAppend(Text:="", Filename:="", Encoding:="")
{
FileAppend %Text%, %Filename%, %Encoding%
return !ErrorLevel
}
FileCopy(Source, Dest, Flag:=0)
{
FileCopy %Source%, %Dest%, %Flag%
return !ErrorLevel
}
FileCreateShortcut(Target, LinkFile, WorkingDir:="", Args:="", Description:="", IconFile:="", ShortcutKey:="", IconNumber:="", RunState:=1)
{
FileCreateShortcut %Target%, %LinkFile%, %WorkingDir%, %Args%, %Description%, %IconFile%, %ShortcutKey%, %IconNumber%, %RunState%
return !ErrorLevel
}
FileDelete(FilePattern)
{
FileDelete %FilePattern%
return !ErrorLevel
}
FileEncoding(Encoding:="")
{
FileEncoding %Encoding%
}
FileGetAttrib(Filename:="")
{
local OutputVar
FileGetAttrib OutputVar, %Filename%
if !ErrorLevel
return OutputVar
}
FileGetShortcut(LinkFile, ByRef OutTarget:="", ByRef OutDir:="", ByRef OutArgs:="", ByRef OutDescription:="", ByRef OutIcon:="", ByRef OutIconNum:="", ByRef OutRunState:="")
{
FileGetShortcut %LinkFile%, OutTarget, OutDir, OutArgs, OutDescription, OutIcon, OutIconNum, OutRunState
return !ErrorLevel
}
FileGetSize(Filename:="", Units:="")
{
local OutputVar
FileGetSize OutputVar, %Filename%, %Units%
if !ErrorLevel
return OutputVar
}
FileGetTime(Filename:="", WhichTime:="M")
{
local OutputVar
FileGetTime OutputVar, %Filename%, %WhichTime%
if !ErrorLevel
return OutputVar
}
FileGetVersion(Filename:="")
{
local OutputVar
FileGetVersion OutputVar, %Filename%
if !ErrorLevel
return OutputVar
}
FileInstall(Source, Dest, Flag:=0)
{
FileCopy %Source%, %Dest%, %Flag%
return !ErrorLevel
}
FileMove(SourcePattern, DestPattern, Flag:=0)
{
FileMove %SourcePattern%, %DestPattern%, %Flag%
return !ErrorLevel
}
FileRead(Filename)
{
local OutputVar
FileRead OutputVar, %Filename%
if !ErrorLevel
return OutputVar
}
FileRecycle(FilePattern)
{
FileRecycle %FilePattern%
return !ErrorLevel
}
FileRecycleEmpty(DriveLetter:="")
{
FileRecycleEmpty %DriveLetter%
return !ErrorLevel
}
FileSelect(Options:=0, RootDir_Filename:="", Prompt:="", Filter:="")
{
local OutputVar
FileSelectFile OutputVar, %Options%, %RootDir_Filename%, %Prompt%, %Filter%
if !ErrorLevel
return OutputVar
}
FileSetAttrib(Attributes, FilePattern:="", OperateOnFolders:=0, Recurse:=0)
{
FileSetAttrib %Attributes%, %FilePattern%, %OperateOnFolders%, %Recurse%
return !ErrorLevel
}
FileSetTime(YYYYMMDDHH24MISS:="", FilePattern:="", WhichTime:="M", OperateOnFolders:=0, Recurse:=0)
{
FileSetTime %YYYYMMDDHH24MISS%, %FilePattern%, %WhichTime%, %OperateOnFolders%, %Recurse%
return !ErrorLevel
}
FormatTime(YYYYMMDDHH24MISS:="", Format:="")
{
local OutputVar
FormatTime OutputVar, %YYYYMMDDHH24MISS%, %Format%
return OutputVar
}
GroupActivate(GroupName, R:="")
{
GroupActivate %GroupName%, %R%
return !ErrorLevel
}
GroupAdd(GroupName, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
GroupAdd %GroupName%, %WinTitle%, %WinText%,, %ExcludeTitle%, %ExcludeText%
}
GroupClose(GroupName, AR:="")
{
GroupClose %GroupName%, %AR%
}
GroupDeactivate(GroupName, R:="")
{
GroupDeactivate %GroupName%, %R%
}
Gui(SubCommand, Param1:="", Param2:="", Param3:="", Param4:="")
{
global ; assume global for vControlVars
Gui %SubCommand%, %Param1%, %Param2%, %Param3%, %Param4%
}
GuiControl(SubCommand:="", ControlID:="", Param3:="")
{
global
GuiControl %SubCommand%, %ControlID%, %Param3%
return !ErrorLevel
}
GuiControlGet(SubCommand:="", ControlID:="", Param4:="")
{
global
local OutputVar
GuiControlGet OutputVar, %SubCommand%, %ControlID%, %Param4%
if !ErrorLevel
return OutputVar
}
Hotkey(Param1, Param2:="", Param3:="")
{
Hotkey %Param1%, %Param2%, %Param3%
if (InStr(Param1, "IfWin") || InStr(Param3, "UseErrorLevel"))
return !ErrorLevel
}
ImageSearch(ByRef OutputVarX:="", ByRef OutputVarY:="", X1:="", Y1:="", X2:="", Y2:="", ImageFile:="")
{
ImageSearch OutputVarX, OutputVarY, %X1%, %Y1%, %X2%, %Y2%, %ImageFile%
return !ErrorLevel
}
IniDelete(Filename, Section, Key:="")
{
IniDelete %Filename%, %Section%, %Key%
return !ErrorLevel
}
IniRead(Filename, Section:="", Key:="", Default:="")
{
local OutputVar
IniRead OutputVar, %Filename%, %Section%, %Key%, %Default%
if !ErrorLevel
return OutputVar
}
IniWrite(Value, Filename, Section, Key:="")
{
IniWrite %Value%, %Filename%, %Section%, %Key%
return !ErrorLevel
}
Input(Options:="", EndKeys:="", MatchList:="")
{
local OutputVar
Input OutputVar, %Options%, %EndKeys%, %MatchList%
return OutputVar
}
InputBox(Title:="", Prompt:="", Options:="", Default:="")
{
local _, _X, _Y, _W, _H, _T, _P, _Err
; v2 validates the value of a particular option:
; X and Y = integer (can be negative)
; W and H = postive integer only
; T = postive integer/float
; Credits to Lexikos [https://goo.gl/VjMTYu , https://goo.gl/ebEjon]
RegExMatch(Options, "i)^[ \t]*(?:(?:X(?<X>-?\d+)|Y(?<Y>-?\d+)|W(?<W>\d+)"
. "|H(?<H>\d+)|T(?<T>\d+(?:\.\d+)?)|(?<P>Password\S?)"
. "|(?<Err>\S+)(*ACCEPT)"
. ")(?=[ \t]|$)[ \t]*)*$", _)
if (_Err != "")
throw Exception("Invalid option.", -1, _Err)
local OutputVar
InputBox, OutputVar, %Title%, %Prompt%, % _P ? "HIDE" : "", %_W%, %_H%, %_X%, %_Y%,, %_T%, %Default%
return OutputVar
}
KeyHistory()
{
KeyHistory
}
KeyWait(KeyName, Options:="")
{
KeyWait %KeyName%, %Options%
return !ErrorLevel
}
ListHotkeys()
{
ListHotkeys
}
ListLines(OnOrOff:="")
{
ListLines %OnOrOff%
}
ListVars()
{
; Limitation -> won't work if called from within a function
global
ListVars
}
Menu(MenuName, Cmd, P3:="", P4:="", P5:="")
{
Menu %MenuName%, %Cmd%, %P3%, %P4%, %P5%
}
MenuSelect(WinTitle:="", WinText:="", Menu:="", SubMenu1:="", SubMenu2:="", SubMenu3:="", SubMenu4:="", SubMenu5:="", SubMenu6:="", ExcludeTitle:="", ExcludeText:="")
{
WinMenuSelectItem %WinTitle%, %WinText%, %Menu%, %SubMenu1%, %SubMenu2%, %SubMenu3%, %SubMenu4%, %SubMenu5%, %SubMenu6%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
MonitorGet(N:="", ByRef OutLeft:="", ByRef OutTop:="", ByRef OutRight:="", ByRef OutBottom:="")
{
local Out
SysGet Out, Monitor, %N%
return (OutLeft != "" && OutTop != "" && OutRight != "" && OutBottom != "")
}
MonitorGetCount()
{
local OutputVar
SysGet OutputVar, MonitorCount
return OutputVar
}
MonitorGetName(N:="")
{
local OutputVar
SysGet OutputVar, MonitorName
return OutputVar
}
MonitorGetPrimary()
{
local OutputVar
SysGet OutputVar, MonitorPrimary
return OutputVar
}
MonitorGetWorkArea(N:="", ByRef OutLeft:="", ByRef OutTop:="", ByRef OutRight:="", ByRef OutBottom:="")
{
local Out
SysGet Out, MonitorWorkArea, %N%
return (OutLeft != "" && OutTop != "" && OutRight != "" && OutBottom != "")
}
MouseClick(WhichButton:="Left", X:="", Y:="", ClickCount:="", Speed:="", DU:="", R:="")
{
MouseClick %WhichButton%, %X%, %Y%, %ClickCount%, %Speed%, %DU%, %R%
}
MouseClickDrag(WhichButton, X1:="", Y1:="", X2:="", Y2:="", Speed:="", R:="")
{
MouseClickDrag %WhichButton%, %X1%, %Y1%, %X2%, %Y2%, %Speed%, %R%
}
MouseGetPos(ByRef OutputVarX:="", ByRef OutputVarY:="", ByRef OutputVarWin:="", ByRef OutputVarControl:="", Mode:=0)
{
MouseGetPos OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, %Mode%
}
MouseMove(X, Y, Speed:="", R:="")
{
MouseMove %X%, %Y%, %Speed%, %R%
}
MsgBox(Params*)
{
local Len
if (Len := Params.Length())
{
if (Len == 1)
MsgBox % Params[1]
else
MsgBox % Params[1], % Params[2], % Params[3], % Params[4]
}
else
MsgBox
}
OutputDebug(Text)
{
OutputDebug %Text%
}
Pause(OnOffToggle:="", OperateOnUnderlyingThread:=0)
{
Pause %OnOffToggle%, %OperateOnUnderlyingThread%
}
PixelGetColor(X, Y, AltSlow:="")
{
local OutputVar
PixelGetColor OutputVar, %X%, %Y%, %AltSlow% RGB ; v2 uses RGB
if !ErrorLevel
return OutputVar
}
PixelSearch(ByRef OutputVarX:="", ByRef OutputVarY:="", X1:="", Y1:="", X2:="", Y2:="", ColorID:="", Variation:=0, Fast:="")
{
PixelSearch, OutputVarX, OutputVarY, %X1%, %Y1%, %X2%, %Y2%, %ColorID%, %Variation%, %Fast% RGB
return !ErrorLevel
}
PostMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
PostMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if (ErrorLevel = "FAIL")
ErrorLevel := "ERROR"
}
ProcessClose(PIDorName)
{
Process Close, %PIDorName%
return ErrorLevel
}
ProcessExist(PIDorName:="")
{
Process Exist, %PIDorName%
return ErrorLevel
}
ProcessSetPriority(Priority, PIDorName:="")
{
Process Priority, %PIDorName%, %Priority%
return ErrorLevel
}
ProcessWait(PIDorName, SecondsToWait:="")
{
Process Wait, %PIDorName%, %SecondsToWait%
return ErrorLevel
}
ProcessWaitClose(PIDorName, SecondsToWait:="")
{
Process WaitClose, %PIDorName%, %SecondsToWait%
return ErrorLevel
}
Random(Min:="", Max:="")
{
local OutputVar
Random OutputVar, %Min%, %Max%
return OutputVar
}
RegDelete(RootKeySubKey:="", ValueName:="")
{
RegDelete %RootKeySubKey%, %ValueName%
return !ErrorLevel
}
RegDeleteKey(RootKeySubKey)
{
RegDelete %RootKeySubKey%
return !ErrorLevel
}
RegRead(RootKeySubKey:="", ValueName:="")
{
local OutputVar
RegRead OutputVar, %RootKeySubKey%, %ValueName%
if !ErrorLevel
return OutputVar
}
RegWrite(ValueType:="", RootKeySubKey:="", ValueName:="", Value:="")
{
RegWrite %ValueType%, %RootKeySubKey%, %ValueName%, %Value%
return !ErrorLevel
}
Reload()
{
Reload
}
Run(Target, WorkingDir:="", Options:="", ByRef OutputVarPID:="")
{
Run %Target%, %WorkingDir%, %Options%, OutputVarPID
if InStr(Options, "UseErrorLevel")
return !ErrorLevel
}
RunAs(User:="", Password:="", Domain:="")
{
RunAs %User%, %Password%, %Domain%
}
RunWait(Target, WorkingDir:="", Options:="", ByRef OutputVarPID:="")
{
RunWait %Target%, %WorkingDir%, %Options%, OutputVarPID
return ErrorLevel
}
Send(Keys)
{
Send %Keys%
}
SendEvent(Keys)
{
SendEvent %keys%
}
SendInput(Keys)
{
SendInput %Keys%
}
SendLevel(Level)
{
SendLevel %Level%
}
SendMessage(Msg, wParam:="", lParam:="", Control:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="", Timeout:="")
{
SendMessage %Msg%, %wParam%, %lParam%, %Control%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%, %Timeout%
if (ErrorLevel = "FAIL")
ErrorLevel := "ERROR"
}
SendMode(Mode)
{
SendMode %Mode%
}
SendPlay(Keys)
{
SendPlay %Keys%
}
SendRaw(Keys)
{
SendRaw %Keys%
}
SetCapsLockState(State:="")
{
SetCapsLockState %State%
}
SetControlDelay(Delay)
{
SetControlDelay %Delay%
}
SetDefaultMouseSpeed(Speed)
{
SetDefaultMouseSpeed %Speed%
}
SetKeyDelay(Delay:="", PressDuration:="", Play:="")
{
SetKeyDelay %Delay%, %PressDuration%, %Play%
}
SetMouseDelay(Delay, Play:="")
{
SetMouseDelay %Delay%, %Play%
}
SetNumLockState(State:="")
{
SetNumLockState %State%
}
SetRegView(RegView)
{
SetRegView %RegView%
}
SetScrollLockState(State:="")
{
SetScrollLockState %State%
}
SetStoreCapslockMode(OnOrOff)
{
SetStoreCapslockMode %OnOrOff%
}
SetTimer(Label:="", Period:="", Priority:=0)
{
SetTimer %Label%, %Period%, %Priority%
}
SetTitleMatchMode(MatchModeOrSpeed)
{
SetTitleMatchMode %MatchModeOrSpeed%
}
SetWinDelay(Delay)
{
SetWinDelay %Delay%
}
SetWorkingDir(DirName)
{
SetWorkingDir %DirName%
return !ErrorLevel
}
Shutdown(Code)
{
Shutdown %Code%
}
Sleep(DelayInMilliseconds)
{
Sleep %DelayInMilliseconds%
}
Sort(String, Options:="")
{
Sort String, %Options%
return String
}
SoundBeep(Frequency:=523, Duration:=150)
{
SoundBeep %Frequency%, %Duration%
}
SoundGet(ComponentType:="", ControlType:="", DeviceNumber:=1)
{
local OutputVar
SoundGet OutputVar, %ComponentType%, %ControlType%, %DeviceNumber%
if !ErrorLevel
return OutputVar
}
SoundPlay(Filename, Wait:="")
{
SoundPlay %Filenam%, %Wait%
return !ErrorLevel
}
SoundSet(NewSetting, ComponentType:="", ControlType:="", DeviceNumber:=1)
{
SoundSet %NewSetting%, %ComponentType%, %ControlType%, %DeviceNumber%
return !ErrorLevel
}
SplitPath(Path, ByRef OutFileName:="", ByRef OutDir:="", ByRef OutExtension:="", ByRef OutNameNoExt:="", ByRef OutDrive:="")
{
SplitPath % Path, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
}
StatusBarGetText(PartNum:=1, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
StatusBarGetText OutputVar, %PartNum%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if !ErrorLevel
return OutputVar
}
StatusBarWait(BarText:="", Seconds:="", PartNum:=1, WinTitle:="", WinText:="", Interval:=50, ExcludeTitle:="", ExcludeText:="")
{
StatusBarWait %BarText%, %Seconds%, %PartNum%, %WinTitle%, %WinText%, %Interval%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
StringCaseSense(OnOffLocale)
{
StringCaseSense %OnOffLocale%
}
StrLower(String, T:="")
{
local OutputVar
StringLower OutputVar, %String%, %T%
return OutputVar
}
StrUpper(String, T:="")
{
local OutputVar
StringUpper OutputVar, %String%, %T%
return OutputVar
}
Suspend(Mode:="Toggle")
{
Suspend %Mode%
}
SysGet(SubCommand)
{
local OutputVar
SysGet OutputVar, %SubCommand%
return OutputVar
}
Thread(Param1, Param2:="", Param3:="")
{
Thread %Param1%, %Param2%, %Param3%
}
ToolTip(Text:="", X:="", Y:="", WhichToolTip:=1)
{
ToolTip %Text%, %X%, %Y%, %WhichToolTip%
}
TrayTip(Title:="", Text:="", Seconds:="", Options:=0)
{
TrayTip, %Title%, %Text%, %Seconds%, %Options%
}
Type(Value)
{
local m, f, e
if IsObject(Value)
{
static nMatchObj := NumGet(&(m, RegExMatch("", "O)", m)))
static nBoundFunc := NumGet(&(f := Func("Func").Bind()))
static nFileObj := NumGet(&(f := FileOpen("*", "w")))
static nEnumObj := NumGet(&(e := ObjNewEnum({})))
return ObjGetCapacity(Value) != "" ? "Object"
: IsFunc(Value) ? "Func"
: ComObjType(Value) != "" ? "ComObject"
: NumGet(&Value) == nBoundFunc ? "BoundFunc"
: NumGet(&Value) == nMatchObj ? "RegExMatchObject"
: NumGet(&Value) == nFileObj ? "FileObject"
: NumGet(&Value) == nEnumObj ? "Object::Enumerator"
: "Property"
}
else if (ObjGetCapacity([Value]) != "")
return "String"
else
return InStr(Value, ".") ? "Float" : "Integer"
}
WinActivate(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinActivate %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinActivateBottom(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinActivateBottom %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinClose(WinTitle:="", WinText:="", SecondsToWait:="", ExcludeTitle:="", ExcludeText:="")
{
WinClose %WinTitle%, %WinText%, %SecondsToWait%, %ExcludeTitle%, %ExcludeText%
}
WinGetClass(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGetClass OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinGetControls(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, ControlList, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return StrSplit(OutputVar, "`n")
}
WinGetControlsHwnd(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar, ControlsHwnd, i
WinGet OutputVar, ControlListHwnd, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
ControlsHwnd := StrSplit(OutputVar, "`n")
for i in ControlsHwnd
ControlsHwnd[i] += 0
return ControlsHwnd
}
WinGetCount(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, Count, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinGetExStyle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, ExStyle, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar + 0
}
WinGetID(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar + 0
}
WinGetIDLast(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, IDLast, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar + 0
}
WinGetList(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar, List
WinGet OutputVar, List, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
List := []
Loop % OutputVar
List.Push(OutputVar%A_Index% + 0)
return List
}
WinGetMinMax(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, MinMax, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinGetPID(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, PID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinGetPos(ByRef X:="", ByRef Y:="", ByRef Width:="", ByRef Height:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinGetPos, X, Y, Width, Height, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinGetProcessName(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, ProcessName, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinGetProcessPath(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, ProcessPath, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinGetStyle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, Style, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar + 0
}
WinGetText(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGetText OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if !ErrorLevel
return OutputVar
}
WinGetTitle(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGetTitle OutputVar, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinGetTransColor(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, TransColor, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinGetTransparent(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local OutputVar
WinGet OutputVar, Transparent, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return OutputVar
}
WinHide(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinHide %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinKill(WinTitle:="", WinText:="", SecondsToWait:="", ExcludeTitle:="", ExcludeText:="")
{
WinKill %WinTitle%, %WinText%, %SecondsToWait%, %ExcludeTitle%, %ExcludeText%
}
WinMaximize(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinMaximize %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMinimize(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinMinimize %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMinimizeAll()
{
WinMinimizeAll
}
WinMinimizeAllUndo()
{
WinMinimizeAllUndo
}
WinMove(Params*)
{
local WinTitle, WinText, X, Y, Width, Height, ExcludeTitle, ExcludeText
local Len
if (Len := Params.Length())
{
if (Len > 2)
{
WinTitle := Params[1]
WinText := Params[2]
X := Params[3]
Y := Params[4]
Width := Params[5]
Height := Params[6]
ExcludeTitle := Params[7]
ExcludeText := Params[8]
WinMove %WinTitle%, %WinText%, %X%, %Y%, %Width%, %Height%, %ExcludeTitle%, %ExcludeText%
}
else
{
X := Params[1]
Y := Params[2]
WinMove %X%, %y%
}
}
else
WinMove
}
WinMoveBottom(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinSet Bottom,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinMoveTop(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinSet Top,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinRedraw(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinSet Redraw,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinRestore(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinRestore %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinSetAlwaysOnTop(OnOffToggle:="Toggle", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local Hwnd
WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if (!Hwnd)
return 0
if OnOffToggle in 1,0,-1 ; On,Off,Toggle
OnOffToggle := OnOffToggle == -1 ? "Toggle" : OnOffToggle ? "On" : "Off"
if OnOffToggle not in On,Off,Toggle
throw Exception("Parameter #1 invalid.", -1) ; v2 raises an error
WinSet AlwaysOnTop, %OnOffToggle%, ahk_id %Hwnd%
return 1
}
WinSetEnabled(Value, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local Hwnd
WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if (!Hwnd)
return 0
; 1, 0 and -1 are compared as strings, non-integer values(e.g.: 1.0) are not allowed
local Style
if (Value = "Toggle" || value == "-1")
{
WinGet Style, Style, ahk_id %Hwnd%
Value := (Style & 0x8000000) ? "On" : "Off" ; WS_DISABLED = 0x8000000
}
if (Value = "On" || Value == "1")
WinSet Enable, ahk_id %Hwnd%
else if (Value = "Off" || Value == "0")
WinSet Disable, ahk_id %Hwnd%
else
throw Exception("Paramter #1 invalid.", -1) ; v2 raises an error
return 1
}
WinSetExStyle(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinSet ExStyle, %N%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
WinSetRegion(Options:="", WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinSet Region, %Options%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
WinSetStyle(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinSet Style, %N%, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
WinSetTitle(Param:="", Params*)
{
local WinTitle, WinText, NewTitle, ExcludeTitle, ExcludeText
if (Params.Length())
{
WinTitle := Param
WinText := Params[1]
NewTitle := Params[2]
ExcludeTitle := Params[3]
ExcludeText := Params[4]
WinSetTitle %WinTitle%, %WinText%, %NewTitle%, %ExcludeTitle%, %ExcludeText%
}
else
WinSetTitle %Param% ; WinSetTitle, NewTitle
}
WinSetTransColor(ColorN, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local Hwnd
WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if (!Hwnd)
return 0
WinSet TransColor, %ColorN%, ahk_id %Hwnd%
return 1
}
WinSetTransparent(N, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local Hwnd
WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if (!Hwnd)
return 0
WinSet Transparent, %N%, ahk_id %Hwnd%
return 1
}
WinShow(WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
WinShow %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
}
WinWait(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
WinWait %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
WinWaitActive(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
WinWaitActive %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
WinWaitClose(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
WinWaitClose %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
WinWaitNotActive(WinTitle:="", WinText:="", Seconds:="", ExcludeTitle:="", ExcludeText:="")
{
WinWaitNotActive %WinTitle%, %WinText%, %Seconds%, %ExcludeTitle%, %ExcludeText%
return !ErrorLevel
}
Amended versions of functions, *not* changed in the full list of functions above:
FileSetAttrib, FileSetTime, SoundPlay, StrLower, StrUpper, WinSetEnabled
[still require amending: MsgBox, TrayTip]
Code: Select all
FileSetAttrib(Attributes, FilePattern:="", Mode:="")
{
FileSetAttrib %Attributes%, %FilePattern%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
return !ErrorLevel
}
FileSetTime(YYYYMMDDHH24MISS:="", FilePattern:="", WhichTime:="M", Mode:="")
{
FileSetTime %YYYYMMDDHH24MISS%, %FilePattern%, %WhichTime%, % InStr(Mode, "D") ? (InStr(Mode, "F") ? 1 : 2) : 0, % !!InStr(Mode, "R")
return !ErrorLevel
}
SoundPlay(Filename, Wait:="")
{
SoundPlay %Filename%, %Wait%
return !ErrorLevel
}
StrLower(String, T:="")
{
local OutputVar
StringLower OutputVar, String, %T%
return OutputVar
}
StrUpper(String, T:="")
{
local OutputVar
StringUpper OutputVar, String, %T%
return OutputVar
}
WinSetEnabled(Value, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="")
{
local Hwnd
WinGet Hwnd, ID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if (!Hwnd)
return 0
; 1, 0 and -1 are compared as strings, non-integer values(e.g.: 1.0) are not allowed
local Style
if (Value = "Toggle" || value == "-1")
{
WinGet Style, Style, ahk_id %Hwnd%
Value := (Style & 0x8000000) ? "On" : "Off" ; WS_DISABLED = 0x8000000
}
if (Value = "On" || Value == "1")
WinSet Enable,, ahk_id %Hwnd%
else if (Value = "Off" || Value == "0")
WinSet Disable,, ahk_id %Hwnd%
else
throw Exception("Paramter #1 invalid.", -1) ; v2 raises an error
return 1
}