View Single Post
  #18  
Old 10-07-2007, 07:34 PM
happyhour456 happyhour456 is offline
Senior Member
 
Join Date: May 2006
Location: window shopping in amsterdam
Posts: 669
Default Re: ipoker skins and scripts?

die functions.ahk ist quasi eine bibliothek mit bereits geschriebenen funktionen. die muss in dem gleichen ordner sein, wie das script, was ausgeführt wird und auf die functions.ahk zu greifen will. die muss also nicht extra ausgeführt werden.

functions.ahk:

; ##### RolandsFunctions #####

; date: 9:00 PM Tuesday, July 24, 2007
; version: 2.15
; authors: Roland & many others

; ### Overview ###

/*
;----- Miscellanious -----

IsCompiled()
CheckAHKVersion(req)
Tip(text,timeout="",x="",y="")
IsIn(var,matchlist)
Contains(var,matchlist)
Web()
iif(_boolExpr, _exprTrue, _exprFalse)
JoyExist()
CleanHotkey(k)
Random(min,max,newSeed="")
IsBetween(var, lower, upper)
FontList()
CreateDFCFile(file)
DrawFrame(frame=0, x=0, y=0, w=0, h=0, t=0, c=0)
Gradient(File, RGB1, RGB2, Vertical=1)
Eval(x)
ExitMsg()
DigitSearch(startX,startY,endX,endY,win,dir,ex="", shades=100)
PostLeftClick(x, y, table_id, activate=1)
osd(msg="", options="", font="", gui=92)
osdEx(msg="", options="", font="", x=0, y=0, gui=91)
SectionToTheme( ini, section )
ThemeToSection( ini, section )
ProcessCreationTime(pid)
GetPriority(process="")
psql(sql, database="", debug=0, host="", username="")
CaptureScreen(aRect, bCursor = False, sFile = "")
toggleCursor()

;----- Mouse -----

mouseGetX()
mouseGetY()
mouseGetWin()
mouseGetCtrl()
toggleCursor()

;----- Gui -----

SetParent(win, gui)
LV_GetTxt(row,column)
TV_GetTxt(id)
FreeGui()
ForceOS(x, y, title, NA=0, offSetX=0, offSetY=0)
SetGuiPos(owner, x="",y="")
SetOwner(options="")
MouseOver()
AddCustomFrame(iPaths, title="", toolwindow=0, resize=0, pIcon="")
InsertIntegerAtAddress(pInteger, pAddress, pOffset = 0, pSize = 4)

;----- Strings -----

StrRep(str,char,rep_char="",all=1)
StrMid(str,str1,str2,startPos1=1,startPos2=1,caseS ense=0)
StrLeft(str,count)
StrSlice(str,len,del="")
TrimWhiteSpace(str)
TabsToSpaces(c, spaces=2)
ExtractNum(str,start=0)
StrEnd(O,str)
StrUpper(str)
StrLower(str)
varize(var, autofix = true)
InStrX(h, n, LR# = "", of = 0)
SymbolsToKeys(s)

;----- Lists -----

AddToList(list,item,del="")
ExFromList(list,pos=1,del="")
RemoveFromList(list,item=1,del="")
RemoveItemNFromList(list,n,del="")
GetItemPos(list,item,del="")
InsertItem(list,item,pos,del="")
CleanList(list, del="")
List_longest(list, del="")
min(list, del="")
max(list, del="")

;----- Controls -----

CtrlGetTxt(ctrl,win,matchMode=1)
IsVisCtrl(ctrl,win,matchMode=1)
IsDisabledCtrl(ctrl,win,matchMode=1)
CtrlGetHwnd(ctrl,win,matchMode=1)
CtrlGetStyle(ctrl,win,matchMode=1)
CtrlGetExStyle(ctrl,win,matchMode=1)
ToggleCheckbox(ctrl, win, matchMode=1)
IsCheckedCtrl(ctrl, win, matchMode=1)
FocusedCtrl()
CtrlWaitVis(ctrl,win="",timeout="")
CtrlClick(ctrl,win,matchMode=1)
CtrlCheck(ctrl, win, matchMode=1)
CtrlUncheck(ctrl, win, matchMode=1)
FrameAroundCtrl(ctrl,win,frame="",width=5,color="" )

;----- Files -----

FileRead(file)
FileReadLine(file,line)
FileSelectFile(Options="",RootDir="",Prompt="",Fil ter="")
IniRead(file,section,key,def="")
CreateCustomFile(file,dir)
SplitCustomFile(file,dir)
WriteFile(file,data)
FileSave(str, file)

;----- Pixel -----

PixelGetColor(x,y,options="")
GetPixelCount(x1,y1,x2,y2,color,options="")
GetPredominateColor(x1,y1,x2,y2,options="")
BGRToRGB(c)

;----- Windows -----

WinMinMax(id)
WinWaitStatic(win,int=1000,timeout="")
FrameAroundWin(win, t=10)
ConfirmDialogue(title,txt="",timeout=5,extitle="", exTxt="")
IsWinInTray(title)
RemoveMinimizedTables(list)
WinGetTitle(win)
WindowFromPoint(x, y)
Border()
Caption()
getClientRect(byRef x, byRef y, byRef w, byRef h, hwnd="")

;----- Poker - General -----

LobbyIdParty()
LobbyIdStars()
LobbyIDFullTilt()
LobbyIDAbsolute()
LobbyIDPacific()
LobbyIDParadise()
LobbyIDBetfair()
LobbyIDPokerRoom()
TableIDListParty(lobbyID)
TableIDListStars(lobbyID)
TableIDListFullTilt(LobbyID)
TableIDListAbsolute(LobbyID)
TableIDListPacific(lobbyID)
TableIDListParadise(lobbyID)
TableIDListBetfair(lobbyID)
TableIDListPokerRoom(lobbyID)
tablesParty()
tablesStars()
tablesFullTilt()
tablesAbsolute()
tablesPacific()
tablesParadise()
tablesBetfair()
tablesPokerRoom()
GetBBParty(id, game_type)
GetBBStars(id)
GetBBFullTilt(id)
GetBBParadise(id)
GetBBPacific(id)
GetBBBetfair(id)
GetBBPokerRoom(id)
GameTypeParty(title)
GameTypeStars(title)
GameTypeFullTilt(title)
GameTypeParadise(title)
GameTypePacific(title)
GameTypeBetfair(title)
GameTypePokerRoom(title)
PotParadise(id)
PotFullTilt(id)
PotBetfair(id)
PotPokerRoom(id)
sb(bb)
StartImport(stud=false)
ToggleImport(stud=false)
ForceImport(seconds=10, stud=false)
KillToolbar()
PTNotesExport(stud=false)
tableNav()
PostAbsClick(x, y, win)

;----- Poker - Stars -----

HHFileStars(win, dir)
SeatsStacksNamesStars(hh, win)
StackStars(hh, sn)
DollarsWonStars(hh, sn)
GetKnownHandsStars(hh)
PotStars(win, frac=1, round=2, openAd=""
, openAdblinds="", autoBet=0, maxRake=3)
LimpersStars(pot, bb)
IAmBlindsStars(call, bb)
IsRaisedStars(win, call)
IsPreflopStars(win)
SetTextStars(id, dir, frac=1, unit="")
IsStudHHStars(hh)
Is6maxHHStars(hh)
Is9maxHHStars(hh)
instantHHStars(hh, x, y, dir, dirStud="", theme="", font="", bgColor=""
, 4color=1, colorStreet=0, colorPlayers=0, colorAction=0, colorCards=0)
LastHHStars(win, dir)
RebuyMaxStars(win)
RebuyStars(win, bb)
bbStars(win)
IdHHStars(hh)
SizeStarsTable(w, win)
IsPlayerOnlineStars(player)
PostStarsClick(x, y, win)

;----- Poker - Party -----

HH(file, id)
HHFile(win, exe, format="")
GetPartyDate(exe, screenName)
HandID(win)
LastHandID(win)
MyScreenName(win)
SeatsStacksNames(hh, win)
GetKnownHands(hh)
Is6max(win)
GetChatParty(id)
GetChatByID(id, hand)
InvestedLastHand(hh, player)
InvestedLastHandSNG(hh, player)
IsButtonCheckedParty(ctrl,win,matchMode=1)
PotParty(id, frac=1, round=2, openAd=0
, openAdblinds="", autoBet=0, maxrake=3)
IsPreflop(hh)
IsRaised(hh)
Limpers(hh)
IAmBlinds(hh, win)
SetTextParty(id, dir, frac=1, unit="")
NavToGame(game)
NavToLimit(limit)
SetFilter(button)
TogglePlanner()
relX(x, ww)
relY(y, wh)
relW(w, ww)
relH(h, wh)
instantHH(hh, x, y, gui, dir, theme="", font=""
, bgColor="", 4ColorDeck=1, showPot=1, showdown=1, rows=10)
IsStudHH(hh)
LastHH(win, exe)
CurrentHand(hh, win, x, y, gui, theme="", font="", bgColor="")
OpenBuddyList()
OpenPlayerSearch()
AddPlayerToBuddyList(player)
ToggleSitoutParty()
SitOutParty(win)
SitInParty(win)
SitOutPartyEx()
SitInPartyEx()
PositionActed(hh, player, ByRef action)
PositionActedStud(hh, player, ByRef action)

;----- Dialogues ------

Msgbox(msg="", options="", title="", font="", gui=66)
InputBox(prompt="", options="", title="", default="", font="", gui=67)
Hotkey(Options="",Prompt="",Title="",GuiNumber=77)
ColorPicker(HEXString="",Title="",owner="",Gui=97)
Font(ini, section, options="", owner="", gui=93)

;----- ExtractFunctions&Subroutines ------

ExLabelList(file)
ExSub(sub,file)
ExFunct(function, file)
*/

; comment

; ### Miscellanious ###

;don't allow compiled scripts
IsCompiled()
{ ; by Roland
If A_IsCompiled {
msg =
(LTrim Join`s
Sorry, but it is not possible to run this script correctly if it
is compiled. The program will exit.
)
Msgbox(msg, "IconX w250 bold -Owner",version)
ExitApp
}
}

CheckAHKVersion(req) {
If (A_AhkVersion < req) {
msg =
(LTrim Join`s
This script needs AutoHotkey version %req% or newer
to run correctly (you are using version %A_AhkVersion%).
`nGo to web page to download new version now?
)
If (Msgbox(msg, "ButtonsYes|No IconI c8B0000 Default1 bold s10 w320 -Owner", version) = "Yes")
Run, % Web() "http://www.autohotkey.com/download/"
ExitApp
}
}

Tip(text,timeout="",x="",y="") {
CoordMode, ToolTip, Screen
If ( x )
Tooltip,%text%, %x%, %y%
else
Tooltip %text%
If timeout
SetTimer,RemoveTooltip,% timeout*1000
CoordMode, ToolTip, Relative
return

RemoveTooltip:
Tooltip
SetTimer, RemoveTooltip, Off
return
}

;"If var in..."
IsIn(var,matchlist) {
strSense = %a_stringCaseSense%
StringCaseSense Off
If var in %matchlist%
{
return 1
StringCaseSense %strSense%
}
StringCaseSense %strSense%
return 0
}

;"If var in %matchlist%" as a function
Contains(var,matchlist) {
If var contains %matchlist%
return 1
return 0
}

;thanks to Titan for this handy little funtion
;it returns the path of the systems default browser, so
;that web pages can be opened in a new window
Web() { ; by Titan, modified by Roland
RegRead, p, HKCR, HTTP\shell\open\command
Return SubStr(p, 1, InStr(p, ".exe")+4)
}

; no longer neccessary since we have the
; ternary operator now...
; but have to keep it for old scripts
iif(_boolExpr, _exprTrue, _exprFalse) {
If _boolExpr
Return _exprTrue
else
return _exprFalse
}

; checks if a joystick exists and returns its
; number if yes, else 0
JoyExist() {
Loop 32 {
GetKeyState, joy_name, %A_Index%JoyName
If joy_name <>
return a_index
}
return 0
}

; removes modifiers and special
; operators... forgot where I needed this
CleanHotkey(k) {
k := StrRep(k, "^")
k := StrRep(k, "<^")
k := StrRep(k, ">^")
k := StrRep(k, "!")
k := StrRep(k, "<!")
k := StrRep(k, ">!")
k := StrRep(k, "+")
k := StrRep(k, "<+")
k := StrRep(k, ">+")
k := StrRep(k, "#")
k := StrRep(k, "<#")
k := StrRep(k, ">#")
k := StrRep(k, "*")
k := StrRep(k, "~")
k := StrRep(k, " UP")
return k
}

Random(min,max,newSeed="") {
If ( newSeed ) {
Random,,newSeed
return
}
Random, var, min, max
return var
}

IsBetween(var, lower, upper) {
If var between %lower% and %upper%
return 1
return 0
}

; returns a pipe-seperated list with
; all available fonts
fontList() {
Loop, HKEY_LOCAL_MACHINE
, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
{ StringLeft, f, a_loopRegName, InStr(a_loopRegName, "(")-1
if regExMatch(f, "[\w\s]+\s(\d+,)+\d")
f:=regExReplace(f, "\d+(,| )")
listAdd(fonts, f, "|")
} return fonts
}

; used for TableNavigator...
CreateDFCFile(file) {
functions := ExLabelList(file)
num_params_prev = 0
Loop, Parse, functions, |
{
IfNotInString, a_loopfield, (
continue
IfInString, a_loopfield, /
continue
IfInString, a_loopfield, dfc
continue
info := GetdfcInfo(a_loopfield,num_params)
If info =
continue
dfc = %dfc%`n%info%
If num_params > %num_params_prev%
num_params_prev = %num_params%
}
Loop %num_params_prev%
params = %params%,p%a_index%=""
StringTrimLeft, params, params, 1
dfc = dfc(f,%params%) {`nglobal A_LastDFCError`n%dfc%`nA_LastDFCError = `%f`%`n}
return dfc
}

GetDFCInfo(f, ByRef num_params) {
num_params = 0
StringLeft, func, f, InStr(f, "(") - 1
dfc = %a_space%If (f = "%func%")
params := StrMid(a_loopfield,"(",")")
Loop, Parse, params, `,
{
num_params++
IfInString, a_loopfield, =
{
num++
StringTrimLeft,p, a_loopfield, InStr(a_loopfield, "=")
IfInString, p, ByRef
return
If p = ""
; p =
continue
cond = %cond%`nIf (p%a_index% = "")`n%a_space%%a_space%p%a_index% = %p%
}
ps = %ps%,p%a_index%
}
StringTrimLeft, params, ps, 1
If cond
thisF = %dfc%%a_space%%a_space%{%a_space%%a_space%%cond%`n return %func%(%params%)`n}
else
thisF = %dfc%`n%a_space%%a_space%return %func%(%params%)
return thisF
}

; not sure how well this actually works\performs...
; probably best to use simpler methods in most cases
DrawFrame(frame=0, x=0, y=0, w=0, h=0, t=0, c=0) {
local h_brush
static _gui,SRCCOPY,frames
,hdc_frame,hdc_buffer
,h_region,hbm_buffer
c := BGRToRGB(c)
If ( frame = "*" ) {
StringSplit, f, frames, `,
Loop {
If ( f%a_index% )
continue
frame = %a_index%
break
} }
If ( ! frames ) { ;no frames means this is the first call (or first call after a clean-up)
_gui = 50
Gui %_gui%: +Lastfound +AlwaysOnTop +Toolwindow
Gui %_gui%: Color, 0x000001 ;this color cannot be used as a frame color obviously
WinSet, TransColor, 0x000001
Gui %_gui%: -Caption
Gui %_gui%: Show, x0 y0 w%a_screenwidth% h%a_screenheight% NoActivate
hdc_frame := DllCall( "GetDC", "uint", WinExist() )
hdc_buffer := DllCall( "gdi32.dll\CreateCompatibleDC", "uint", hdc_frame )
hbm_buffer := DllCall( "gdi32.dll\CreateCompatibleBitmap", "uint", hdc_frame
, "int", a_screenwidth, "int", a_screenwidth )
DllCall( "gdi32.dll\SelectObject", "uint", hdc_buffer, "uint", hbm_buffer )
DllCall( "gdi32.dll\SelectObject", "uint", hdc_buffer, "uint", hbm_buffer )
h_region := DllCall( "gdi32.dll\CreateRectRgn", "int", 0, "int", 0, "int", 0, "int", 0 )
SRCCOPY = 0x00CC0020
}
;if this frame already exists, remove previously drawn
;rectangle (restore previoulsy buffered color data):
If IsIn(frame,frames) {
DllCall( "gdi32.dll\BitBlt", "uint", hdc_frame, "int", old_x_%frame%, "int", old_y_%frame%
, "int", old_w_%frame%, "int", old_h_%frame%, "uint", hdc_buffer, "int", 0, "int", 0
, "uint", SRCCOPY )
If ( !x && !y && !w && !h) ;just erase it (there must be a better way to do this?)
frames := RemoveFromList(frames,frame)
} else
frames := AddToList(frames,frame)
If ( ! frame || ! frames ) { ;clean up
DllCall( "gdi32.dll\DeleteObject", "uint", h_region )
DllCall( "gdi32.dll\DeleteObject", "uint", hbm_buffer )
DllCall( "gdi32.dll\DeleteDC", "uint", hdc_frame )
DllCall( "gdi32.dll\DeleteDC", "uint", hdc_buffer )
frames =
Gui %_gui%: Destroy
return
}
If ( !x && !y && !w && !h)
return
;add last position to global array:
old_x_%frame% = %x%
old_y_%frame% = %y%
old_w_%frame% = %w%
old_h_%frame% = %h%
;Store current color data of new ractangle in buffer:
DllCall( "gdi32.dll\BitBlt", "uint", hdc_buffer, "int", 0, "int", 0
, "int", w, "int", h, "uint", hdc_frame, "int", x, "int", y
, "uint", SRCCOPY )
DllCall( "gdi32.dll\SetRectRgn", "uint", h_region, "int", x, "int", y, "int", x+w, "int", y+h )
h_brush := DllCall( "gdi32.dll\CreateSolidBrush", "uint", c )
DllCall( "gdi32.dll\FrameRgn", "uint", hdc_frame, "uint", h_region, "uint", h_brush, "int", t, "int", t )
DllCall( "gdi32.dll\DeleteObject", "uint", h_brush )
return frame
}

; Creates a Two Pixel Bitmap (Horizontal/Vertical)
; see http://www.autohotkey.com/forum/view...?p=61081#61081
; Param1: File name to be created
; Param2: A Valid Hex Color code for the Bottom (or) Left pixel.
; Param3: A Valid Hex Color code for the Top (or) Right pixel.
; Param4: 0 (or) 1 . Vertical=1 / Horizontal=0
Gradient(File, RGB1, RGB2, Vertical=1) {
If (BGR(RGB1)="" OR BGR(RGB2)="")
Return Null
Hs1:="424d3e00000000000000360000002800000"
Hs3:="00100180000000000080000000000000000000000000 0000000000000"
If Vertical {
Hs2:="0010000000200000"
HexString:= Hs1 Hs2 Hs3 BGR(RGB1) "00" BGR(RGB2) "00"
}
Else {
Hs2:="0020000000100000"
HexString:= Hs1 Hs2 Hs3 BGR(RGB1) BGR(RGB2) "0000"
}
Handle:= DllCall("CreateFile","str",file,"Uint",0x40000000
,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
Loop 62 {
StringLeft, Hex, HexString, 2
StringTrimLeft, HexString, HexString, 2
Hex = 0x%Hex%
DllCall("WriteFile","UInt", Handle,"UChar *", Hex
,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
}
DllCall("CloseHandle", "Uint", Handle)
Return File
}

BGR(RGB) {
If (StrLen(RGB)<>6)
Return Null
Loop, Parse, RGB
If A_LoopField not in 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Return Null
StringMid,R,RGB,1,2
StringMid,G,RGB,3,2
StringMid,B,RGB,5,2
Return B G R
}

RandomHexColor(Range1=0,Range2=255) {
Random, _RGB1, %Range1%, %Range2%
Random, _RGB2, %Range1%, %Range2%
Random, _RGB3, %Range1%, %Range2%
SetFormat, Integer, Hex
_RGB1+=0
_RGB2+=0
_RGB3+=0
If StrLen(_RGB1) = 3
_RGB1= 0%_RGB1%
If StrLen(_RGB2) = 3
_RGB2= 0%_RGB2%
If StrLen(_RGB3) = 3
_RGB3= 0%_RGB3%
SetFormat, Integer, D
HEXString = % _RGB1 _RGB2 _RGB3
StringReplace, HEXString, HEXString,0x,,All
StringUpper, HEXString, HEXString
Return HexString
}

; see http://www.autohotkey.com/forum/view...highlight=eval
Eval(x) { ; by Laszlo
pi = 3.141592653589793
e = 2.718281828459045 ; add below your constants

StringReplace x, x, %A_Space%,, All ; remove white space
StringReplace x, x, %A_Tab%,, All
StringReplace x, x, -, #, All ; # = subtraction
StringReplace x, x, (#, (0#, All ; (-x -> (0-x
If (Asc(x) = Asc("#"))
x = 0%x% ; leading -x -> 0-x
StringReplace x, x, (+, (, All ; (+x -> (x
If (Asc(x) = Asc("+"))
StringTrimLeft x, x, 1 ; leading +x -> x
StringReplace x, x, **, @, All ; ** -> @ for easier process
Loop { ; replace constants
StringGetPos i, x, [ ; find [
IfLess i,0, Break
StringGetPos j, x, ], L, i+1 ; closest ]
StringMid y, x, i+2, j-i-1 ; variable in []
StringLeft L, x, i
StringTrimLeft R, x, j+1
x := L . %y% . R ; replace [var] with value of var
}
Loop { ; finding an innermost (..)
StringGetPos i, x, (, R ; rightmost (
IfLess i,0, Break
StringGetPos j, x, ), L, i+1 ; closest )
StringMid y, x, i+2, j-i-1 ; expression in ()
StringLeft L, x, i
StringTrimLeft R, x, j+1
x := L . Eval@(y) . R ; replace (x) with value of x
}
Return Eval@(x)
}

Eval@(x) {
StringGetPos i, x, +, R ; i = -1 if no + is found
StringGetPos j, x, #, R
If (i > j)
Return Left(x,i)+Right(x,i)
If (j > i) ; i = j only if no + or - found
Return Left(x,j)-Right(x,j)
StringGetPos i, x, *, R
StringGetPos j, x, /, R
StringGetPos k, x,`%, R
If (i > j && i > k)
Return Left(x,i)*Right(x,i)
If (j > i && j > k)
Return Left(x,j)/Right(x,j)
If (k > i && k > j)
Return Mod(Left(x,k),Right(x,k))
StringGetPos i, x, @, R ; power
If (i >= 0)
Return Left(x,i)**Right(x,i)
StringGetPos i1, x, abs, R ; no more operators
StringGetPos i2, x, sqrt, R ; look for functions
StringGetPos i3, x, floor, R ; insert further functions below
m := Max1(i1,i2,i3)
If (m = i1) ; apply the rightmost function
Return abs(Right(x,i1+2)) ; only one function is applied
Else If (m = i2) ; in one recursion
Return sqrt(Right(x,i2+3))
Else If (m = i3)
Return floor(Right(x,i3+4)) ; offset j + StrLen(func) - 2
Return x
}

Left(x,i) {
StringLeft x, x, i
Return Eval@(x)
}

Right(x,i) {
StringTrimLeft x, x, i+1
Return Eval@(x)
}

Max1(x0,x1="",x2="",x3="",x4="",x5="",x6="",x7=""
,x8="",x9="",x10="",x11="",x12="",x13="",x14=""
,x15="",x16="",x17="",x18="",x19="",x20="") {
x := x0
Loop 20 {
IfEqual x%A_Index%,, Break
IfGreater x%A_Index%, %x%
x := x%A_Index%
}
IfLess x,0, Return -2 ; prevent match with -1
Return %x%
}

; used for OnMessage('someMsg', "ExitMsg")...
ExitMsg() {
exitApp
}

;searches a reagion of the screen for digits 0-9 (and the decimal point)
; and puts them together to the correct number
;used for image matching in PotStars()
; dir: directory of images; ex: e.g. 'bmp' (no point)
; shades: shades of variation
DigitSearch(startX,startY,endX,endY,win,dir,ex="", shades=100) {
If ex =
ex = bmp
batchlines = %A_BatchLines%
SetBatchLines -1
WinGetPos,Xwin,Ywin,,,ahk_id%win%
CoordMode, Pixel, Screen
Loop, 11 {
i = %a_index%
If i = 10
i = 0
else if i = 11
i = -1
lastXpos := startX + winX
Loop {
ImageSearch, lastXpos,, lastXpos + 1
, startY + Ywin, endX + Xwin, endY + Ywin
, *%shades% %dir%\%i%.%ex%
If ( errorLevel )
break
p++
p%p% = %lastXpos%
If i = -1
t = .
else
t = %i%
c%lastXpos% = %t%
}
}
Loop, %p%
p_all := p_all "," p%a_index%
Sort, p_all, N D, U
Loop, Parse, p_all, `,
amount := amount "" c%a_loopfield%
CoordMode, Pixel, Relative
SetBatchLines %batchlines%
return amount
}

;comment
;Juks rocks
PostLeftClick(x, y, table_id, activate=1) {
; ### JUK: Send the down left click, then the mouse-up messages.
; NOTE: This is relative to the top left of the client area and NOT the top left of the
; window (ie: It *doesn't* include the title-bar like AHK's MouseClick does!!!).
If activate
WinActivate, ahk_id%table_id%
PostMessage, 0x201, 0x0001, ((y<<16)^x), , ahk_id%table_id%
PostMessage, 0x202 , 0, ((y<<16)^x), , ahk_id%table_id%
}

; a elegant way of communicating with your users [img]/images/graemlins/smile.gif[/img]
; ( 'osd'= on screen display )
; to destroy the gui/message, call the function without
; any parameters
osd(msg="", options="", font="", gui=92) {
options := options ? options : "s30 bold cWhite"
font := font ? font : "Comic Sans MS"
Gui, %gui%: Default
Gui, Destroy
If ( msg="" )
return
Gui, +Lastfound +Toolwindow +AlwaysOnTop
Gui, Color, Black
WinSet, TransColor, Black
Gui -Caption
Gui, Margin, 0, 0
Gui, Font, %options%, %font%
Gui, Add, Text,, %msg%
SysGet, wa, MonitorWorkArea
Gui, Show, Hide
WinGetPos,,,w, h
x := a_screenwidth/2-w/2
y := waBottom-h-20
Gui, Show, x%x% y%y% NoActivate
}

; similar to osd(), but the position is meant to be spedified here
; to destroy the gui/message, call the function without
; any parameters
osdEx(msg="", options="", font="", x=0, y=0, gui=91) {
global osdEx_msg
options := a_space . options . a_space
size := StrEnd(options, "s")
size := size ? size : 30
bold := InStr(options, " bold ") ? "bold" : ""
italic := InStr(options, " italic ") ? "italic" : ""
color := StrEnd(options, "c")
color := color ? color : "white"
theme = s%size% c%color% %bold% %italic%
font := font ? font : "Comic Sans MS"
width := StrEnd(options, "w")
width := width ? width : a_screenwidth
center := InStr(options, " center ") ? "center" : ""
Gui, %gui%: Default
If ( msg="" ) {
Gui, Destroy
return
}
Gui +LastfoundExist
If WinExist() {
Gui, Show, x%x% y%y% NoActivate
GuiControl,, osdEx_msg, %msg%
return
}
Gui, +Lastfound +Toolwindow +AlwaysOnTop
Gui, Color, Black
WinSet, TransColor, Black
Gui -Caption
Gui, Margin, 0, 0
Gui, Font, %theme%, %font%
Gui, Add, Text, vosdEx_msg w%width% %center%, %msg%
Gui, Show, x%x% y%y% NoActivate
}

; see http://www.autohotkey.com/forum/view...tegerataddress
InsertIntegerAtAddress(pInteger, pAddress, pOffset = 0, pSize = 4) {
mask := 0xFF ; This serves to isolate each byte, one by one.
Loop %pSize% { ; Copy each byte in the integer into the structure as raw binary data.
DllCall("RtlFillMemory", UInt, pAddress + pOffset + A_Index - 1, UInt, 1
, UChar, (pInteger & mask) >> 8 * (A_Index - 1))
mask := mask << 8 ; Set it up for isolation of the next byte.
}
}

; the idea is to merge text color, text size
; as well as 'bold' and 'italic' to a single 'theme' (e.g. 'cFFFFFF s10 italic')
; and store theme, background color & font in a new section
; the section to convert is usually created by the Font() function
; and is typically only converted if the user hits Submit in a configuration gui
SectionToTheme( ini, section ) {
name := StrRep(section, "Font")
IniRead, bgColor, %ini%, %section%, bgColor, %a_space%
IniRead, txtColor, %ini%, %section%, txtColor, 000000
IniRead, size, %ini%, %section%, size, 8
IniRead, bold, %ini%, %section%, bold, 0
IniRead, italic, %ini%, %section%, italic, 0
IniRead, font, %ini%, %section%, font, %a_space%
bold := bold ? "bold" : ""
italic := italic ? "italic" : ""
theme = s%size% c%txtColor% %bold% %italic%
IniWrite, % font, %ini%, %name%, font%name%
IniWrite, % bgColor, %ini%, %name%, bgColor%name%
IniWrite, % theme, %ini%, %name%, theme%name%
}

; the opposite of the above...
ThemeToSection( ini, section ) {
IniRead, font, %ini%, %section%, font%section%
IniRead, bgColor, %ini%, %section%, bgColor%section%
IniRead, theme, %ini%, %section%, theme%section%
theme := " " theme " "
size := StrEnd(theme, "s")
txtcolor := StrEnd(theme, "c")
bold := InStr(theme, " bold ") ? 1 : 0
italic := InStr(theme, " italic ") ? 1 : 0
section = Font%section%
IniWrite, % bgColor, %ini%, %section%, bgColor
IniWrite, % txtColor, %ini%, %section%, txtColor
IniWrite, % size, %ini%, %section%, size
IniWrite, % bold, %ini%, %section%, bold
IniWrite, % italic, %ini%, %section%, italic
IniWrite, % font, %ini%, %section%, font
}


; see http://www.autohotkey.com/forum/viewtopi...me&start=60
ProcessCreationTime( PID ) { ; by Skan
VarSetCapacity(PrCT,16) , VarSetCapacity(Dummy,16) , VarSetCapacity(SysT,16)
AccessRights := 1040 ; PROCESS_QUERY_INFORMATION = 1024, PROCESS_VM_READ = 16
hPr:=DllCall( "OpenProcess", Int,AccessRights, Int,0, Int,PID )
DllCall( "GetProcessTimes" , Int,hPr, Int,&PrCT, Int,&Dummy, Int,&Dummy, Int,&Dummy)
DllCall("CloseHandle" , Int,hPr)
DllCall( "FileTimeToLocalFileTime" , Int,&PrCT, Int,&PrCT ) ; PrCT is Creation time
DllCall( "FileTimeToSystemTime" , Int,&PrCt, Int,&SysT ) ; SysT is System Time
Loop 16 { ; Extracting and concatenating 8 words from a SYSTEMTIME structure
Word := Mod(A_Index-1,2) ? "" : *( &SysT +A_Index-1 ) + ( *(&SysT +A_Index) << 8 )
Time .= StrLen(Word) = 1 ? ( "0" . Word ) : Word ; Prefixing "0" for single digits
}
Return SubStr(Time,1,6) . SubStr(Time,9,8) ; YYYYMMDD24MISS
}

; see http://www.autohotkey.com/forum/viewtopi...me&start=30
; if no param is passed, the scripts own priority is retrieved
GetPriority(process="") { ;by Skan
Process, Exist, %process%
PID := ErrorLevel
IfLessOrEqual, PID, 0, Return, "Error!"
hProcess := DllCall("OpenProcess", Int,1024, Int,0, Int,PID)
Priority := DllCall("GetPriorityClass", Int,hProcess)
DllCall("CloseHandle", Int,hProcess)
IfEqual, Priority, 64 , Return, "Low"
IfEqual, Priority, 16384, Return, "BelowNormal"
IfEqual, Priority, 32 , Return, "Normal"
IfEqual, Priority, 32768, Return, "AboveNormal"
IfEqual, Priority, 128 , Return, "High"
IfEqual, Priority, 256 , Return, "Realtime"
Return ""
}

; WARNING: CAN CAUSE SERIOUS DAMAGE TO DATABASE!
; Please refer to http://www.overcards.com/wiki/moin.c...tgresFunctions
; for instructions
psql(sql, database="", debug=0, host="", username="") { ; by _dave_
database := database ? database : "PTPGSQL1"
host := host ? host : "localhost"
username := username ? username : "postgres"
stamp = %A_Now%
Random, r, 1000, 9999
file1 := stamp . "_" . A_ScriptName . "_" . r . "_in.txt"
file2 := stamp . "_" . A_ScriptName . "_" . r . "_out.txt"
file3 := stamp . "_" . A_ScriptName . "_" . r . "_error.txt"
command := "psql.exe -A -t -h " . host . " -p 5432 -U "
. username . " -d """ . database . """ -f " . file1 . " -o "
. file2 . " 2> " . file3 ; . " 2>&1"
Loop 3
FileDelete, % file%a_index%
FileAppend, \f '\t'`n, %file1%
FileAppend, %sql%`n, %file1%
FileAppend, \q`n, %file1%
RunWait, %comspec% /c %command%, , Hide
FileGetSize, errorsize, %file3%
If ( errorsize > 0 ) {
FileRead, errortext, %File3%
FileRead, errorcause, %File1%
Loop 3
FileDelete, % file%a_index%
if (debug) {
Msgbox, %errorcause%`n`n`n%errortext%
ExitApp
} else {
FileAppend,
( join
%A_Now% - An Error Occured:`n`nInput:`n%errorcause%`n
`nOutput:`n%errortext%`n`n`n`n
), %A_Scriptname%_Error_Log.txt
}
}
FileRead, sqlout, %File2%
Loop 3
FileDelete, % file%a_index%
StringTrimRight, sqlout, sqlout, 2
return %sqlout%
}

/* CaptureScreen(aRect, bCursor, sFileTo)
1) If the optional parameter bCursor is True, captures the cursor too.
2) If the optional parameter sFileTo is empty, saves to screen.bmp in the script folder,
otherwise to sFileTo which can be BMP/JPG/PNG/GIF/TIF.
3) If aRect is 0/1/2, captures the screen/active window/client area of active window.
4) aRect can be comma delimited sequence of coordinates, e.g., "Left, Top, Right, Bottom" or "Left, Top, Right, Bottom, Width_Zoomed, Height_Zoomed".
In this case, only that portion of the rectangle will be captured. Additionally, in the latter case, zoomed to the new width/height, Width_Zoomed/Height_Zoomed.

Example:
CaptureScreen(0)
CaptureScreen(1)
CaptureScreen(2)
CaptureScreen("100, 100, 200, 200")
CaptureScreen("100, 100, 200, 200, 400, 400") ; Zoomed
*/

/* Convert(sFileFr, sFileTo)
Convert("C:\image.bmp", "C:\image.jpg")
Convert(0, "C:\clip.png") ; Save the bitmap in the clipboard to sFileTo if sFileFr is "" or 0.
*/
; http://www.autohotkey.com/forum/viewtopic.php?t=18146
CaptureScreen(aRect, bCursor = False, sFile = "")
{
If !sFile
sFile := A_ScriptDir . "\screen.bmp"

If !aRect
{
SysGet, Mon, Monitor, 1
nL := MonLeft
nT := MonTop
nW := MonRight - MonLeft
nH := MonBottom - MonTop
}
Else If aRect = 1
WinGetPos, nL, nT, nW, nH, A
Else If aRect = 2
{
WinGet, hWnd, ID, A
VarSetCapacity(rt, 16)
DllCall("GetClientRect" , "Uint", hWnd, "Uint", &rt)
DllCall("ClientToScreen", "Uint", hWnd, "int64P", pt)
nL := pt & 0xFFFFFFFF
nT := pt >> 32 & 0xFFFFFFFF
nW := DecodeInteger(&rt + 8)
nH := DecodeInteger(&rt +12)
}
Else
{
StringSplit, rt, aRect, `,
nL := rt1
nT := rt2
nW := rt3 - rt1
nH := rt4 - rt2
znW := rt5
znH := rt6
}

hDC := DllCall("GetDC", "Uint", 0)
mDC := DllCall("CreateCompatibleDC", "Uint", hDC)
hBM := DllCall("CreateCompatibleBitmap", "Uint", hDC, "int", nW, "int", nH)
DllCall("SelectObject", "Uint", mDC, "Uint", hBM)

DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH
, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020) ; CAPTUREBLT = 0x40000000

If bCursor
CaptureCursor(mDC, nL, nT)

If znW && znH
{
Zoomed := Zoomer(hDC, mDC, hBM, nW, nH, znW, znH)
StringSplit, Mag, Zoomed, `,
hBM := Mag1
mDC := Mag2
}

Convert(hBM, sFile)

DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
DllCall("DeleteDC", "Uint", mDC)
DllCall("DeleteObject", "Uint", hBM)
}

CaptureCursor(hDC, nL, nT)
{
VarSetCapacity(mi, 20, 0)
mi := Chr(20)
DllCall("GetCursorInfo", "Uint", &mi)

bShow := DecodeInteger(&mi + 4)
hCursor := DecodeInteger(&mi + 8)
xCursor := DecodeInteger(&mi +12)
yCursor := DecodeInteger(&mi +16)

VarSetCapacity(ni, 20, 0)
DllCall("GetIconInfo", "Uint", hCursor, "Uint", &ni)

xHotspot := DecodeInteger(&ni + 4)
yHotspot := DecodeInteger(&ni + 8)
hBMMask := DecodeInteger(&ni +12)
hBMColor := DecodeInteger(&ni +16)

If bShow
DllCall("DrawIcon", "Uint", hDC, "int", xCursor - xHotspot - nL
, "int", yCursor - yHotspot - nT, "Uint", hCursor)

If hBMMask
DllCall("DeleteObject", "Uint", hBMMask)
If hBMColor
DllCall("DeleteObject", "Uint", hBMColor)
}

Zoomer(hDC, mDC, hBM, nW, nH, znW, znH)
{
zmDC := DllCall("CreateCompatibleDC", "Uint", hDC)
zhBM := DllCall("CreateCompatibleBitmap", "Uint", hDC, "int", znW, "int", znH)
DllCall("SelectObject", "Uint", zmDC, "Uint", zhBM)

DllCall("SetStretchBltMode", "Uint", zmDC, "int", 4)
DllCall("StretchBlt", "Uint", zmDC, "int", 0, "int", 0, "int", znW, "int", znH
, "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", 0x00CC0020)

DllCall("DeleteDC", "Uint", mDC)
DllCall("DeleteObject", "Uint", hBM)
Return zhBM . "," . zmDC
}

Convert(sFileFr, sFileTo)
{
SplitPath, sFileTo, , , sExtTo

hGdiPlus := DllCall("LoadLibrary", "str", "gdiplus.dll")

VarSetCapacity(si, 16, 0)
si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)

DllCall("gdiplus\GdipGetImageEncodersSize", "UintP", nCount, "UintP", nSize)
VarSetCapacity(ci, nSize)
DllCall("gdiplus\GdipGetImageEncoders", "Uint", nCount, "Uint", nSize, "Uint", &ci)

Loop, %nCount%
{
pTypes := DecodeInteger(&ci + 76 * (A_Index - 1) + 44)
Unicode2Ansi(pTypes, sTypes)
If !InStr(sTypes, "." . sExtTo)
Continue
pCodec := &ci + 76 * (A_Index - 1)
Break
}

If !sFileFr
{
DllCall("OpenClipboard", "Uint", 0)
hBM := DllCall("GetClipboardData", "Uint", 2)
DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", hBM, "Uint", 0, "UintP", pImage)
DllCall("CloseClipboard")
}
Else If sFileFr Is Integer
DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", sFileFr, "Uint", 0, "UintP", pImage)
Else
{
Ansi2Unicode(sFileFr, wFileFr)
DllCall("gdiplus\GdipLoadImageFromFile", "Uint", &wFileFr, "UintP", pImage)
}

Ansi2Unicode(sFileTo, wFileTo)
DllCall("gdiplus\GdipSaveImageToFile", "Uint", pImage
, "Uint", &wFileTo, "Uint", pCodec, "Uint", 0)

DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)
DllCall("gdiplus\GdiplusShutdown" , "Uint", pToken)

DllCall("FreeLibrary", "Uint", hGdiPlus)
}

DecodeInteger(ptr)
{
Return *ptr | *++ptr << 8 | *++ptr << 16 | *++ptr << 24
}

Ansi2Unicode(ByRef sString, ByRef wString, nSize = 0)
{
nSize .= !nSize ? DllCall("MultiByteToWideChar", "Uint", 0
, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0):
VarSetCapacity(wString, nSize * 2 + 1)
DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0
, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize)
}

Unicode2Ansi(ByRef wString, ByRef sString, nSize = 0)
{
pString := wString + 0 > 65535 ? wString : &wString

nSize .= !nSize ? DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0
, "Uint", pString, "int", -1, "Uint", 0, "int", 0, "Uint", 0, "Uint", 0):
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString
, "int", -1, "str", sString, "int", nSize, "Uint", 0, "Uint", 0)
}

; ### Mouse ###

mouseGetX() {
MouseGetPos, x
return x
}

mouseGetY() {
MouseGetPos,, y
return y
}

mouseGetWin() {
MouseGetPos,,,win
return win
}

mouseGetCtrl() {
MouseGetPos,,,,ctrl
return ctrl
}

; returns 0 if hidden, 1 if visible
toggleCursor() {
static show:=1
show:=!show
return DllCall("user32.dll\ShowCursor", "Int", show)+1
}

; ### Gui ###

; turns Gui #'gui' into a child window of 'win'
SetParent(win, gui) {
Gui, %gui%: +LastFound
return DllCall("SetParent", "uint", WinExist(), "uint", win)
}

LV_GetTxt(row,column=1) {
LV_GetText(var, row, column)
return var
}

TV_GetTxt(id) {
TV_GetText(var,id)
return var
}

; finds the next free gui
FreeGui() {
Loop 99 {
Gui, %a_index%: +LastfoundExist
If ! WinExist()
return a_index
}
}

; forces a Gui to be shown completely on screen
; Note: this function operates on the default window number (a_gui)!
ForceOS(x="", y="", title="", NA=0, offsetX=0, offsetY=0, hide=0) {
Gui +Lastfound
WinGetPos, wx, wy
x := x!="" ? x : wx
y := y!="" ? y : wy
title := title ? title : WinGetTitle(WinExist())
Gui, Show, x%x% y%y% Hide, %title%
WinGetPos, x, y, w, h
SysGet, sw, 78 ;SM_CXVIRTUALSCREEN
SysGet, sh, 79 ;SM_CYVIRTUALSCREEN
If ( x+w > sw )
x := sw-w-offSetX
If ( y+h > sh )
y := sh-h-offSetY
noActivate := NA ? "NoActivate" : ""
hide := hide ? "hide" : ""
Gui, Show, x%x% y%y% %hide% %noActivate%, %title%
return WinExist()
}

; shows the default gui relative to 'owner'
; omit x and y to center it on it's owner
; note: operates on default gui
SetGuiPos(owner, x="",y="", hide=0) {
If ( ! owner ) {
Gui, Show
return
}
Gui, %owner%: +Lastfound
WinGetPos, ox, oy, ow, oh
Gui, +Lastfound
Gui, Show, hide
WinGetPos,,, w, h
If (x!="" && y!="" ) {
px := ox+x
py := oy+y
} else {
Gui, %owner%: +Lastfound
WinGetPos, ox, oy, ow, oh
Gui, +Lastfound
WinGetPos,,, w, h
px := ox + ( ow/2 - w/2 )
py := oy + ( oh/2 - h/2 )
}
hide := hide ? "hide" : ""
Gui, Show, x%px% y%py% %hide%
}

; handles setting the owner for the Msgbox() funcion etc.
; has to be called BEFORE the gui is created
; note: operates on the default Gui
; options can be one or more of the following:
; -owner: the gui will not be owned
; ownerN: sets GuiN as the owner
; -modal: the gui will be owned, but it's owner will not be disabled
; if an owner is not specified, A_Gui, or, if A_Gui, is blank, 1 will be used,
; unless the owner does not exist
SetOwner(options="") {
If InStr(options, "-owner")
return 0
owner := StrEnd(options, "owner")
owner := owner ? owner : ( a_gui ? a_gui : 1 )
Gui, %owner%: +LastfoundExist
If ! WinExist()
return 0
If ! InStr(options, "-modal")
Gui, %owner%: +disabled
Gui, +Owner%owner%
return owner
}

; used when imitating a button control
; with two images - returns true
; if the user released the left mouse button while
; still over the control, false if he moved he mouse away before
; releasing - see http://www.autohotkey.com/forum/view...?p=59899#59899
MouseOver() { ; by Skan (formerly known as Goyya)
ctrl := MouseGetCtrl()
Loop {
If ! GetKeyState("LButton", "p")
break
If ( MouseGetCtrl() != ctrl )
return 0
}
return ( MouseGetCtrl()=ctrl ? 1 : 0 )
}

; adds a custom frame to a gui
; see http://www.autohotkey.com/forum/view...?p=64185#64185
; and http://www.autohotkey.com/forum/view...?p=61081#61081
; for techniques involved. Thanks to Skan @AHK forums.
; iPaths: 'caption.bmp|border.bmp'
AddCustomFrame(iPaths, title="", toolwindow=0, resize=0, pIcon="") {
global borderL,borderR,borderB,Icon
,Close0,Close1,Min0,Min1,caption
,title0,title1
StringLeft, caption, iPaths, InStr(iPaths, "|")-1
StringTrimLeft, border, iPaths, InStr(iPaths, "|")
c_h := toolwindow ? 20 : 27
b_w := resize ? 4 : 3
f_s := toolwindow ? 8 : 10
closeY := toolwindow ? 2 : 4
closeH := toolwindow ? 14 : 16
title0X := toolwindow ? 10 : 35
title1X := title0X - ( toolwindow ? 1 : 2 )
title0Y := toolwindow ? 3 : 5
title1Y := title0Y - ( toolwindow ? 1 : 2 )
Gui, Add, Pic, vborderL x0 y%c_h% w%b_w% h30, %border%
Gui, Add, Pic, vborderR y%c_h% w%b_w% h30, %border%
Gui, Add, Pic, vborderB x%b_w% h%b_w% w30, %border%
Gui, Add, Pic, vClose0 y%closeY% h%closeH% w-1 gClose, Images\Close0.ico
Gui, Add, Pic, vClose1 y%closeY% h%closeH% w-1 gClose, Images\Close1.ico
If ( ! toolwindow ) {
Gui, Add, Pic, vIcon x5 y5 w16 h-1 gSysMenu, %pIcon%
Gui, Add, Pic, vMin0 y%closeY% h%closeH% w-1 gMinimize, Images\Minimize0.ico
Gui, Add, Pic, vMin1 y%closeY% h%closeH% w-1 gMinimize, Images\Minimize1.ico
}
Gui, Add, Pic, vcaption x0 y0 w30 h%c_h% 0x4000000 gGuiMove, %caption%
Gui, Font, s%f_s%
Gui, Add, Text, vtitle0 x%title0X% y%title0Y% backgroundTrans cDEDEDE, %title%
Gui, Add, Text, vtitle1 x%title1X% y%title1Y% backgroundTrans, %title%
}

; ### Strings ###

StrRep(str,char,rep_char="",all=1) {
StringReplace,str,str,%char%,%rep_char%,% all ? "useErrorLevel" : 0
return str
}

; extracts a substring from between str1 and str2
; I find this function to be convenient and quite powerful
; take a close look at it to see how it works
StrMid(str, str1, str2, sP1=1, sP2=1, cS=0) {
sP1 := ( sP1="" ) ? 1 : sP1
sP2 := ( sP2="" ) ? 1 : sP2
StringTrimLeft, s, str, InStr(str, str1, cS, sP1) + StrLen(str1)-1
StringLeft, s, s, InStr(s, str2, cS, sP2)-1
return s
}

;StringLeft as a function
StrLeft(str, count) {
If count = 0
return str
StringLeft, s, str, % count
return s
}

; supposed to slice up text into blocks of maximum lenght %len%
; seems buggy
StrSlice(str, len, del="") {
del := ( del ) ? del : "|"
StringReplace, str, str, %a_space%, |, 1
Loop % StrLen(str)/len {
newStr =
num = 0
Loop, Parse, str, |
{
num += StrLen(a_loopfield) + 1
If num > %len%
break
newStr = %newStr%%a_space%%a_loopfield%
}
returnStr = %returnStr%%del%%newStr%
StringTrimLeft, str, str, StrLen(newStr) + 1
}
StringReplace, str, str, |, %a_space%, 1
returnStr = %returnStr%%del%%str%
StringTrimLeft, returnStr, returnStr, 1
return returnStr
}

; trims any whitespace off the beginning and
; end of %str%
TrimWhiteSpace(str) {
Loop {
StringLeft, isSpace, str, 1
If isSpace is not space
break
If ( isSpace = "" )
return
StringTrimLeft, str, str, 1
}
Loop {
StringRight, isSpace, str, 1
If isSpace is not space
break
If ( isSpace = "" )
return
StringTrimRight, str, str, 1
}
return str
}

;turns tabs at the beginning of a line into a_space each
TabsToSpaces(c, spaces=2) {
Loop % spaces
rep := AddToList(rep, a_space, " ")
Loop, Parse, c, `n
{
a := a_loopfield
Loop {
If ( InStr(a, a_tab) = 1 )
StringReplace, a, a, %a_tab%, %rep%
else
break
}
code = %code%`n%a%
}
StringTrimLeft, code, code, 1
return code
}

;extracts the numeric part of a string, starting at %start%
;it can handle floating point numbers such as 1.25 etc.
ExtractNum(str,start=0) {
StringTrimLeft, str, str, start - 1
Loop, Parse, str
{
If a_loopfield is not integer
{
If check = 1
return num "0"
else if count {
check = 1
num = %num%.
continue
} else
continue
}
count = 1
num = %num%%a_loopfield%
}
return num
}

;this function extracts the trailing characters of a string
;(for instance "White" from BackgroundWhite etc.)
StrEnd(O,str) {
IfNotInString, O, %a_space%%str%
return
StringMid, e, O, InStr(O, " " str) + StrLen(str) + 1
, InStr(O, a_space, "", InStr(O, " " str) + 1) - InStr(O, " " str) - StrLen(str) - 1
return e
}

; converts str to uppercase
StrUpper(str) {
StringUpper, str, str
return str
}

; converts str to lower case
StrLower(str) {
StringLower, str, str
return str
}

; see http://www.autohotkey.com/forum/view...ghlight=varize
varize(var, autofix = true) { ; by Titan
Loop, Parse, var
{ c = %A_LoopField%
x := Asc(c)
If (x > 47 and x < 58) or (x > 64 and x < 91) or (x > 96 and x < 123)
or c = "#" or c = "_" or c = "@" or c = "$" or c = "?" or c = "[" or c = "]"
IfEqual, autofix, 1, SetEnv, nv, %nv%%c%
Else er++
} If StrLen(var) > 254
IfEqual, autofix, 1, StringLeft, var, var, 254
Else er++
IfEqual, autofix, 1, Return, nv
Else Return, er
}

; see http://www.autohotkey.com/forum/view...ghlight=instrx
InStrX(h, n, LR# = "", of = 0) { ; by Titan
AutoTrim, Off
If InStr(LR#, "R") {
StringReplace, LR#x, LR#, R, L, All
Loop, Parse, h
hx = %A_LoopField%%hx%
h = %hx%
Loop, Parse, n
nx = %A_LoopField%%nx%
n = %nx%
} Else LR#x = %LR#%
StringReplace, nx, n, ?, *, All
ofx = %of%
Loop, Parse, nx, *
If (A_Index > 1) {
y = %A_LoopField%
StringGetPos, cx, nx, *, % "L" . A_Index - 1
StringMid, c, n, cx + 1, 1
StringGetPos, prex, h, %x%, %LR#x%, %ofx%
StringLeft, pre, h, StrLen(x) + prex
StringTrimLeft, hx, h, StrLen(x) + prex
Loop {
StringMid, t, hx, A_Index, 1, L
If (t != y) {
t := A_Index - 2
Break
} }
StringGetPos, postx, hx, %y%, , %t%
StringLeft, post, hx, %postx%
StringGetPos, ix, h, %x%%post%%y%, %LR#x%, %of%
If ErrorLevel or (c = "?" and StrLen(post) != 1)
i = -1
Else l += StrLen(x) + StrLen(post)
If (i = "" or ix < i) and i != -1
i = %ix%
ofx += StrLen(post) + StrLen(pre)
x = %y%
} Else x = %A_LoopField%
If !InStr(nx, "*") {
StringGetPos, i, h, %n%, %LR#x%, %of%
If ErrorLevel
i = -1
l := StrLen(n)
}
ErrorLevel := l + StrLen(y)
If InStr(LR#, "R")
Return, StrLen(h) - ErrorLevel - i + 1
Else Return, i + 1
}

; converts the AHK hotkey symbols to
; regular abbreviations...
SymbolsToKeys(s) {
If s not contains <^,>^,^,<^!,>!,!,<+,>+,+,<#,& gt;#,#
return StrRep(s, " & ", "+")
StringRight, isPlus, s, 1
If ( isPlus = "+" ) {
StringTrimRight, s, s, 1
s := s "PLUS"
}
StringReplace, s, s, <^, LControl_
StringReplace, s, s, >^, RControl_
StringReplace, s, s, ^, Control_
StringReplace, s, s, <!, LAlt_
StringReplace, s, s, >!, RAlt_
StringReplace, s, s, !, Alt_
StringReplace, s, s, <+, LShift_
StringReplace, s, s, >+, RShift_
StringReplace, s, s, +, Shift_
StringReplace, s, s, <#, LWin_
StringReplace, s, s, >#, RWin_
StringReplace, s, s, #, Win_
StringReplace, s, s, _, +, 1
StringReplace, s, s, PLUS, +
return s
}

; ### Lists ###

;adds said item to the end of said list
addToList(list,item,del="") {
del := del="" ? "," : del
return ( list ? ( list . del . item ) : item )
}

listAdd(byRef list, item, del=",") {
list := ( list!="" ? ( list . del . item ) : item )
return list
}

;return item at said position in said list
exFromList(list,pos=1,del="") {
del := del="" ? "," : del
StringSplit, item, list, %del%
return item%pos%
}

;removes said item from said list
removeFromList(list,item=1,del="") {
del := del="" ? "," : del
If InStr(list, item . del)
return StrRep(list, item . del, "", 0)
else if InStr(list, del . item, "", 0)
return StrRep(list, del . item, "", 0)
else if (item = list)
return ""
else
return list
}

;removes the nth item from said list
RemoveItemNFromList(list,n,del="") {
del := del="" ? "," : del
return RemoveFromList(list, ExFromList(list,n,del))
}

;returns the position of said item in said list
;(0 if not in list)
GetItemPos(list,item,del="") {
del := del="" ? "," : del
StringSplit, array, list, %del%
Loop %array0% {
If array%a_index% = %item%
return a_index
}
return 0
}

;inserts said item at said position in said list
InsertItem(list,item,pos,del="") {
del := del="" ? "," : del
StringSplit,array,list,%del%
Loop % IIf( ( pos < array0 ), array0, pos ) {
thisItem := array%a_index%
If ( a_index != pos )
newList = %newList%%del%%thisItem%
else
newList = %newList%%del%%item%%del%%thisItem%
}
If ( InStr(newList, ",",0,0) = StrLen(newList) )
StringTrimRight, newList, newList, 1
StringTrimLeft, newList, newList, 1
return newList
}

;removes empty items (and trailing delimiters)
CleanList(list, del="") {
del := del="" ? "," : del
Loop {
StringReplace, list, list, %del%%del%, %del%, UseErrorLevel
If ! ErrorLevel
break
}
If InStr(list, del) = 1
StringTrimLeft, list, list, 1
If InStr(list, del,0,0) = StrLen(list)
StringTrimRight, list, list, 1
return list
}

List_longest(list, del="") {
del := del="" ? "," : del
longest = 0
Loop, Parse, list, %del%
{
If (longest < StrLen(a_loopfield))
longest := StrLen(a_loopfield)
}
return longest
}

max(list, del="") {
del := del ? del : ","
Sort, list, N D%del%
StringTrimLeft, max, list, InStr(list, del, 1, 0)
return max
}

min(list, del="") {
del := del ? del : ","
Sort, list, N D%del%
StringLeft, max, list, InStr(list, del)-1
return max
}

; ### Controls ###

CtrlGetTxt(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGetText, text, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return text
}

IsVisCtrl(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGet, vis, Visible,, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return vis
}

IsDisabledCtrl(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGet, enabled, Enabled,, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return !enabled
}

CtrlGetHwnd(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGet, hwnd, Hwnd,, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return hwnd
}

CtrlGetExStyle(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGet, Exstyle, Exstyle,, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return Exstyle
}

CtrlGetStyle(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGet, style, style,, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return style
}

ToggleCheckbox(ctrl, win, matchMode=1) {
If IsCheckedCtrl(ctrl, win, matchMode)
Control, Uncheck,, %ctrl%, ahk_id%win%
else
Control, Check,, %ctrl%, ahk_id%win%
}

IsCheckedCtrl(ctrl, win, matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGet, checked, checked,, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return checked
}

FocusedCtrl() {
ControlGetFocus, ctrl, A
return ctrl
}

CtrlWaitVis(ctrl,win="",timeout="") {
If ( ! win)
win := WinExist()
Loop {
If IsVisCtrl(ctrl,win) {
errorLevel = 0
return
}
Sleep 10
x += 10
If ( timout != "" && x >= timeout ) {
errorLevel = 1
return
}
}
}

CtrlClick(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlClick, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
}

CtrlCheck(ctrl, win, matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
Loop {
Control, Check,, %ctrl%, ahk_id%win%
If ( errorLevel || IsCheckedCtrl(ctrl, win) )
break
}
SetTitleMatchMode %mm%
}

CtrlUncheck(ctrl, win, matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
Loop {
Control, Uncheck,, %ctrl%, ahk_id%win%
If ( errorLevel || ! IsCheckedCtrl(ctrl, win, mm) )
break
}
SetTitleMatchMode %mm%
}

FrameAroundCtrl(ctrl,win,frame="",width=5,color="" ) {
frame := frame ? frame : "*"
color := color ? color : "0xFF0000"
WinGetPos,wx,wy,,,ahk_id%win%
ControlGetPos,x,y,w,h, %ctrl%, ahk_id%win%
return DrawFrame(frame, wx+x-width,wy+y-width,w+width*2,h+width*2,width,color)
}

; ### Files ###

FileRead(file) {
FileRead, t, %file%
return t
}

FileReadLine(file,line) {
FileReadLine, var, %file%, %line%
return var
}

FileSelectFile(Options="",RootDir="",Prompt="",Fil ter="") {
FileSelectFile, file, %Options%, %RootDir%, %Prompt%, %Filter%
return file
}

IniRead(file,section,key,def="") {
IniRead, var, %file%, %section%, %key%, %def%
If var = ERROR
ErrorLevel = 1
return var
}

CreateCustomFile(file,dir) {
del = `n#----------`n
IfExist %file%
FileDelete %file%
Loop, %dir%\*.txt
{
FileRead, notes, %A_LoopFileFullPath%
StringTrimRight, name, a_loopfilename, 4
FileAppend, %name%:`n%notes%%del%, %file%
num++
}
return num
}

SplitCustomFile(file,dir) {
del = #----------
IfNotExist %file%
return
IfNotExist %dir%
FileCreateDir %dir%
FileRead, str, %file%
Loop, Parse, str, `n, `r`n
{
If (InStr(a_loopfield, del) = 1) {
StringTrimLeft, value, value, 1
num_notes++
IfExist %dir%\%key%.txt
FileDelete %dir%\%key%.txt
FileAppend, %value%, %dir%\%key%.txt
value =
count = 0
continue
}
count++
If (count = 1) {
StringTrimRight, key, a_loopfield, 1
continue
}
value = %value%`n%a_loopfield%
}
return num_notes
}

;url: http://www.autohotkey.com/forum/view...57&start=0
WriteFile(file,data) { ; by corrupt
Handle := DllCall("CreateFile","str",file,"Uint",0x40000000
,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
Loop {
if strlen(data) = 0
break
StringLeft, Hex, data, 2
StringTrimLeft, data, data, 2
Hex = 0x%Hex%
DllCall("WriteFile","UInt", Handle,"UChar *", Hex
,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
}
DllCall("CloseHandle", "Uint", Handle)
return
}

DePCmp1(Pic1) {
format = %A_FormatInteger%
SetFormat, integer, d
TcNt:=42
Loop, 48
TcXp:=TcXp . Chr(A_Index + 127)
Loop, 213 {
TcXp2=
If (TcNt > 126 AND TcNt < 177) {
TcNt += 1
Continue
}
TcXp3 = %A_Index%
Loop, 48
TcXp2 := TcXp2 . Chr(TcNt)
Loop, Parse, TcXp
{
TcXp6 := 51 - A_Index
StringRight, TcXp4, TcXp2, %TcXp6%
TcXp5 := Chr(TcNt) . A_LoopField
StringReplace, Pic1, Pic1, %TcXp5%, %TcXp4%, All
}
TcNt += 1
}
SetFormat, integer, h
Pic2 = %Pic1%
Pic1=
Loop, Parse, Pic2
{
tC1 := Asc(A_LoopField)
If !(tC1 > 0x7e AND tC1 < 0xb1)
If !(tC1 > 0x2f AND tC1 < 0x3A)
If !(tC1 > 0x40 AND tC1 < 0x47)
If !(tC1 > 0x60 AND tC1 < 0x67) {
StringRight, tC1, tC1, 2
StringReplace, tC1, tC1, x, 0
Pic1 = %Pic1%%tC1%
Continue
}
Pic1 = %Pic1%%A_LoopField%
}
SetFormat Integer, %format%
Return Pic1
}

FileSave(str, file) {
FileDelete, %file%
FileAppend, %str%, %file%
}

; ### Pixel ###

; PixelGetColor as a function
PixelGetColor(x,y,options="") {
PixelGetColor, color, x, y, %options%
return color
}

; finds number of specified pixels in a region
GetPixelCount(x1,y1,x2,y2,color,options="") {
pixels := (x2 - x1 + 1)*(y2 - y1 + 1)
If ( pixels <= 0 ) {
ErrorLevel = 1
return
}
count = 0
x = %x1%
Loop {
If ( x > x2 )
break
y = %y1%
Loop {
If ( y > y2 )
break
PixelGetColor, c, x, y, %options%
If ( c = color )
count++
y++
}
x++
}
return count
}

; finds the predomatinate color in a region
GetPredominateColor(x1,y1,x2,y2,options="") {
pixels := (x2 - x1 + 1)*(y2 - y1 + 1)
If ( pixels <= 0 ) {
ErrorLevel = -1
return
}
x = %x1%
Loop {
If ( x > x2 )
break
y = %y1%
Loop {
If ( y > y2 )
break
PixelGetColor, c, x, y, %options%
num%c%++
all_colors = %all_colors%|%c%
y++
;done++
;Tooltip % Floor((done/pixels)*100) "%"
}
x++
}
StringTrimLeft, all_colors, all_colors, 1
num%pred_c% = 0
Loop, Parse, all_colors, |
{
If ( num%a_loopfield% > num%pred_c% )
pred_c = %a_loopfield%
}
ErrorLevel := num%pred_c%
return pred_c
}

; ...or the other way round, of course
BGRToRGB(c) {
If InStr(c, "0x")
StringTrimLeft, c, c, 2
StringLeft, bb, c, 2
StringMid, gg, c, 3, 2
StringRight, rr, c, 2
return "0x" rr . gg . bb
}

; ### Windows ###; ### Windows ###

; get minmax info
; see WinGet, MinMax for more info
WinMinMax(id) {
WinGet, info, MinMax, ahk_id%id%
return info
}

; waits for a window to 'hold still'
; int: inte
Reply With Quote