This is a bilingual (English oriented) improved version of my library now CommonC.ahk.
In the short explanations, the parts chosen to be the functions names are in upper cases. The max3q() has been added and some other functions slightly modified, comments improved and translated or bilingual.
To revert it to French : uncomment the French messages lines, comment the English messages lines.
WARNING : I have done a very small number of tests.
Please report ASAP any problems.
CommonC.ahk
Code:
;--------fini() means "loading FINIshed" (En) or "chargement FINI" (Fr)
fini()
{
global wher, fnErr, st, fnl
StartTime := A_TickCount
bu = 1
Loop, 140 ; sleep 100+100+300 = 0.5 s., part. 1 0.5x40=20 s., part. 2 0.5x100=50 s.
{
clipboard = ; Start off empty to allow ClipWait to detect when the text has arrived.
Sleep, 100
Send, {CTRLDOWN}{ALTDOWN}b{ALTUP}{CTRLUP}
Sleep, 100
ClipWait, 10 ; Wait for the clipboard to contain text.
if ErrorLevel
{
continue
}
If clipboard = NotBusy
{
bu = 0
break
}
If a_index = 40 ; 20 s.
{
Send, {ESC} ; stop
Sleep, 300
Send, {CTRLDOWN}{SHIFTDOWN}r{SHIFTUP}{CTRLUP} ; Reload (override cache)
Sleep, 300
}
Sleep, 300
}
ElapsedTime := A_TickCount - StartTime
If bu
{
;ster := wher " * Dépassement temps de chargement " . ElapsedTime . " ms `n "
ster := wher " * Timeout loading " . ElapsedTime . " ms` n "
rc := err1(ster,fnErr)
}
; MsgBox, , , temps de chargement %ElapsedTime% ms. %wher% ,4
; MsgBox,, loading time %ElapsedTime% ms. %Wher%, 4
return ElapsedTime ; >1
}
;--------slect(x) means "SeLECT" (En) or "SéLECTe" (Fr)
slect(x)
{
global wher, fnErr, st, fnl
Loop, 2
{
Send, {CTRLDOWN}f{CTRLUP}
Sleep, 300
Send, %x%
clipboard = ; Start off empty to allow ClipWait to detect when the text has arrived.
Sleep, 100
Send, {CTRLDOWN}{SHIFTDOWN}f{CTRLUP}{SHIFTUP}
ClipWait, 10 ; Wait for the clipboard to contain text.
if ErrorLevel
{
continue ;2nd try
}
break
}
If clipboard = found
{
rc = 0
} else {
;ster := wher " * Erreur slect(" . x . ") : pas trouvé. `n "
ster := wher " * Error in slect(" . x . ") : not found. `n "
rc := err1(ster,fnErr)
}
Sleep, 100
Send, {ESC}
Sleep, 500
return rc ; rc=0 OK , rc=1 KO x not found or clipwait timeout
}
;--------nxpath(x) means "Normal XPATH" (En & Fr)
nxpath(x)
{
global wher, fnErr, st, fnl
clipboard := x
Sleep, 100
Send, {CTRLDOWN}q{CTRLUP}
rc := WClipChange(x)
If clipboard <> Found
{
;ster := wher " * Erreur Xpat(" . x . ") `n " . clipboard . " `n "
ster := wher " * Error in Xpat(" . x . ") `n " . clipboard . " `n "
rc := err1(ster,fnErr)
}
Sleep, 100
return rc ; rc>1 OK
}
;---------rxpath(x) means "Recoverable XPATH" (En) or "XPATH Récupérable" (Fr)
rxpath(x)
{
global wher, fnErr, st, fnl, stertxp
clipboard := x
Sleep, 100
Send, {CTRLDOWN}q{CTRLUP}
rc := WClipChange(x)
If clipboard = Found ; OK
{
return rc ; rc>1 OK
}
;stertxp := wher " * Erreur Xpat(" . x . ") `n " . clipboard . " `n "
stertxp := wher " * Error in Xpat(" . x . ") `n " . clipboard . " `n "
If clipboard = NotFound
{
return 0 ; rc=0 KO Recoverable/récupérable
}else{
rc := err1(stertxp,fnErr) ; KO non Recoverable/récupérable
return rc
}
}
;---------WClipChange(x) means "Wait Clipboard Change" (En)
WClipChange(x)
{
global wher, fnErr, st, fnl
StartTime := A_TickCount
KO = 1
Loop, 100 ; 10 seconds
{
Sleep, 100
If clipboard <> %x%
{
KO = 0
break
}
}
ElapsedTime := A_TickCount - StartTime
If KO
{
;ster := wher " * Dépassement temps WClipChange " . ElapsedTime . " ms `n "
ster := wher " * Timeout WClipChange " . ElapsedTime . " ms `n "
rc := err1(ster,fnErr)
}
return ElapsedTime ; If OK , rc > 1
}
;--------err1(ster,fnErr) normal error procedure : ster is written it to the error log and show it in a MsgBox. st is put in the normal log. (En)
;--------err1(ster,fnErr) procédure normale d'error : ster est écrit dans le log d'erreur et affiché dans une MsgBox. st est mis dans le log normal. (Fr)
err1(x,y)
{
global st, fnl
MsgBox %x%
ster := "**** " . A_Now . " " . A_ScriptName . "`n" . x . " `n "
FileAppend, %ster%, %y%
rc := Purgelog() ;st is put in the normal log
Exit
return 1 ; rc=0 OK , rc=1 KO
}
;--------err1s = err1 + log source
err1s(x,y)
{
global st, fnl, source
MsgBox %x%
ster := "**** " . A_Now . " " . A_ScriptName . "`n" . x
ster .= "`n ******source*** `n" . source . "`n ************ `n"
FileAppend, %ster%, %y%
rc := Purgelog()
Exit ; err1s = err1 + log source
return 1 ; rc=0 OK , rc=1 KO
}
;--------errClipW(x) ClipWait 10 s. with ErrorLevel processing.(En) avec gestion d'ErrorLevel.(Fr)
errClipW(x)
{
global wher, fnErr, st, fnl
ClipWait, 10 ; Wait for the clipboard to contain text.
if ErrorLevel
{
;ster := wher " * Erreur ClipWait dans fonction " . x . " `n "
ster := wher " * Error ClipWait in function " . x . " `n "
rc := err1(ster,fnErr)
}
return 1
}
;--------VerREMatch(x,y) VERify that RegExMatch has found (returned variable x not 0), pass y to the error message. (En)
;--------VerREMatch(x,y) VERifie que RegExMatch a trouvé (variable x retournée n'est pas 0), passe y au message d'erreur. (Fr)
VerREMatch(x,y)
{
global wher, fnErr, st, fnl
If x = 0
{
ErrREMatch(y)
}
Sleep, 100
return 0 ; rc=0 OK , rc=1 KO
}
;--------ErrREMatch(x) ERRor procedure for RegExMatch. (En) procedure d'ERReur pour RegExMatch. (Fr)
ErrREMatch(x)
{
global wher, fnErr, st, fnl
;ster := wher " * Erreur RegExMatch pour " . x . " : rien trouvé `n "
ster := wher " * Error RegExMatch for " . x . " : nothing found `n "
rc := err1s(ster,fnErr)
return rc ; rc=0 OK , rc=1 KO
}
;--------Purgelog() st is put in the normal log. (En) st est mis dans le log normal. (Fr)
Purgelog()
{
global st, fnl
st .= "`n **** Purge " . A_Now . " " . A_ScriptName . "`n"
FileAppend, %st%, %fnl%
return 0 ; rc=0 OK , rc=1 KO
}
;--------sourc() return normal SOURCe (ctrl u).(En) retourne la SOURce normal (ctrl u).(Fr)
sourc()
{
clipboard = ; Start off empty to allow ClipWait to detect when the text has arrived.
Send, {CTRLDOWN}{SHIFTDOWN}u{SHIFTUP}{CTRLUP}
errClipW(A_ThisFunc) ; ClipWait 10 s. with ErrorLevel processing.(En) avec gestion d'ErrorLevel.(Fr)
return clipboard ; source
}
;--------sdom() return Source of DOM.(En) retourne la Source du DOM.(Fr)
sdom()
{
clipboard = ; Start off empty to allow ClipWait to detect when the text has arrived.
Send, {ALTDOWN}{SHIFTDOWN}u{SHIFTUP}{ALTUP}
errClipW(A_ThisFunc) ; ClipWait 10 s. with ErrorLevel processing.(En) avec gestion d'ErrorLevel.(Fr)
return clipboard ; source du DOM
}
;--------maxim() MAXIMise (<-Fr/En-US->) MAXIMize
maxim()
{
Send, {CTRLDOWN}{SHIFTDOWN}m{SHIFTUP}{CTRLUP}
Sleep, 200
return 0
}
;--------max3q() MAXimise au 3 Quarts (<-Fr/En-US->) MAXimize to 3 Quarters
max3q()
{
Send, {CTRLDOWN}m{CTRLUP}
Sleep, 200
return 0
}
;--------vertit(x) VERify that TITle contains x.(En) VERifie que le TITre contient x.(Fr)
vertit(x)
{
global wher, fnErr, Title, st, fnl
WinGetTitle, Title, A
IfNotInString, Title, x
{
;ster := wher " * Erreur titre = " . Title . " `n "
ster := wher " * Error title = " . Title . " `n "
rc := err1(ster,fnErr)
}
return 0 ; rc=0 OK , rc=1 KO
}
;--------versourc(x) VERify that the SOURCe of DOM contains x.(En) VERifie que la SOURCe du DOM contient x.(Fr)
versourc(x)
{
global wher, fnErr, source, st, fnl
source := sdom()
; FileAppend, %source%, %fnErr%
IfNotInString, source, x
{
;ster := wher " * Erreur : source ne contient pas " . x
ster := wher " * Error : source does not contains " . x
rc := err1s(ster,fnErr)
return 1 ; rc=0 OK , rc=1 KO
}
return 0 ; rc=0 OK , rc=1 KO
}
;--------verURL(x) VERify that the URL is x.(En) VERifie que l'URL est x.(Fr)
verURL(x)
{
global wher, fnErr, st, fnl, vURL
vURL := retURL()
If vURL = %x%
return 0 ; rc=0 OK , rc=1 KO
Else
{
;ster := wher " * Erreur : URL = " . vURL . "`n au lieu de " . x
ster := wher " * Error : URL = " . vURL . "`n instead of " . x
rc := err1(ster,fnErr)
return 1 ; rc=0 OK , rc=1 KO
}
}
;--------retURL() RETurn URL.(En) RETourne l'URL.(Fr)
retURL()
{
clipboard = ; Start off empty to allow ClipWait to detect when the text has arrived.
Send, {ALTDOWN}{SHIFTDOWN}l{SHIFTUP}{ALTUP}
errClipW(A_ThisFunc) ; ClipWait 10 s. with ErrorLevel processing.(En) avec gestion d'ErrorLevel.(Fr)
Sleep, 100
return clipboard ; URL
}
;--------URLcont(x) verify that the URL CONTains x.(En) verifie que l'URL CONTient x.(Fr)
URLcont(x)
{
global wher, fnErr, st, fnl, vURL
vURL := retURL()
IfInString, vURL, %x%
return 0 ; rc=0 OK , rc=1 KO
Else
{
;ster := wher " * Erreur : URL = " . vURL . "`n ne contient pas " . x
ster := wher " * Error : URL = " . vURL . "`n does not contains " . x
rc := err1(ster,fnErr)
return 1 ; rc=0 OK , rc=1 KO
}
}
;--------Dur(x) DURation of script.(En) DURée du script.(Fr)
Dur(x)
{
global fnl
y := A_Now
EnvSub, y, %x%, seconds
min := y // 60
sec := mod(y,60)
; FileAppend, ********* %A_Now% %y% s %min% min %sec% s `n, %fnl%
FileAppend, ********* %A_Now% %min% min %sec% s `n, %fnl%
}
;--------variables
; initialize always used variables.(En) Initialisation des variables toujours utilisées.(Fr)
wher := " ??? " ; you see this if it has not been defined in the script.(En) Vous voyez ceci si ça n'a pas été défini dans le script.(Fr)
st := " ... " ; nothing yet to put in normal log file.(En) Rien encore à mettre dans le log.(Fr)
logdir = %A_ScriptDir%\Log\ ; The full path of the directory where you put the log files. Here the sub directory "Log" of the directory of AHK scripts..(En)
; Chemin complet du répertoire des logs. Ici le repertoire des scripts AHK suivi de Log..(Fr)
fnErr = %logdir%Err.log ; standard error log file : one should be defined.(En) Log standard pour les errreurs : il faut en définir un.(Fr)
deb := A_Now ; start time used by dur(deb) at the bottom of script.(En) Temps du début, utilisé par dur(deb) à la fin du script.(Fr)