Hi Jak64,
If you ( same as me) use google.com to load the web page instead of a webgadget, following code may be of interest to you. In chrome, you can monitor the reload icon at the top left corner to check if a web page is fuly loaded. When a page is loading, it show a "X", once completed, it show a reload icon.
Please noted you may need to adjust the capture position of the icon on procedure CaptureCompress2()
#Originalx=109:#Originaly=60:#Width=24:#Height=24 as your monitor resolution may be diffient from mine.
Thanks.
Allen
Code: Select all
EnableExplicit
UseCRC32Fingerprint()
Procedure WebPage2Clipboard()
Protected.INPUT InputKey
; Control key Down
ZeroMemory_(@InputKey,SizeOf(INPUT)) ;
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;a press
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 65
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
; a release
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 65
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(100)
;c press
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 67
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;c release
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 67
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(100)
;Control key up
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(100)
ProcedureReturn
EndProcedure
Procedure ReloadWebPage()
Protected.INPUT InputKey
ZeroMemory_(@InputKey,SizeOf(INPUT))
; Control key Down
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;R press
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 82
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
; R release
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 82
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(100)
;Control key up
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(150)
EndProcedure
Procedure CloseChrome()
Protected.INPUT InputKey
; Control key Down
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(50)
;w press
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 87 ;87
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(50)
;w release
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 87 ;87
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(50)
;Control key up
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(50)
EndProcedure
Procedure UpdateWebAddr()
Protected.INPUT InputKey
; Control key Down
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;Press L
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 76 ; asc("L")
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;Release L
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 76
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
; Press V
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk =86
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
; Release V
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 86
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;Release Ctrl
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;press enter
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk =#VK_RETURN
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
; release enter
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_RETURN
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(150)
EndProcedure
Procedure.b CompIconString(*String1.quad,*String2.quad) ; string is 8 unicode char long; total 16 bytes, compare as two 64 bit quad
If *String1\q<>*String2\q
ProcedureReturn #False
EndIf
*String1+8
*String2+8
If *String1\q<>*String2\q
ProcedureReturn #False
Else
ProcedureReturn #True
EndIf
EndProcedure
Procedure.s CaptureCompress2()
Protected.i hDC,Image
Protected.i *Buffer
Protected.s Result${8}
#Originalx=109:#Originaly=60:#Width=24:#Height=24
Image=CreateImage(#PB_Any,#Width,#Height)
hDC = StartDrawing(ImageOutput(Image))
BitBlt_(hDC, 0, 0, #Width, #Height, GetDC_(0), #Originalx, #Originaly, #SRCCOPY)
*Buffer = DrawingBuffer()
Result$ = Fingerprint(*Buffer,1728, #PB_Cipher_CRC32)
StopDrawing()
ProcedureReturn Result$
EndProcedure
Procedure.s CaptureReloadIcon()
Protected.s Reload$
RunProgram("https://www.google.com/"," --start-maximized","")
Delay(5000) ;WaitCromeStable()
Repeat
Reload$=CaptureCompress2()
ReloadWebPage()
Delay(1000)
Until Reload$=CaptureCompress2()
ProcedureReturn Reload$
EndProcedure
Procedure Main()
Protected.s URL$
#MaxLoadTime=15000 ; milliseconds
#WaitChromeStable=1000
Protected.i Count,StartTime
Protected.s Current$,Reload$
URL$="https://www.purebasic.fr/english/viewtopic.php?t=82437"
Reload$=CaptureReloadIcon()
SetClipboardText(URL$)
UpdateWebAddr()
ClearClipboard()
StartTime=ElapsedMilliseconds()
Repeat ; wait till reload image appear in chrome
Current$=CaptureCompress2()
If CompIconString(@Reload$,@Current$) ; reload image appear
WebPage2Clipboard() ; copy web content in clipboard
Debug GetClipboardText()
CloseChrome()
ProcedureReturn #True
EndIf
If ElapsedMilliseconds()-StartTime>#MaxLoadTime
ClearClipboard()
Break
EndIf
Delay(300) ; check every 300 ms if reload icon appear
ForEver
; Loading of web page exist time limit
ProcedureReturn #False
EndProcedure
Main()