Re: Simulate CTRL+A and CTRL+C
Posted: Sun Apr 09, 2023 10:30 am
Hello Allen,
I tested the code but in the debug, I get the copy of the program code!
I tested the code but in the debug, I get the copy of the program code!
http://www.purebasic.com
https://www.purebasic.fr/english/
Please changeHello Allen,
I tested the code but in the debug, I get the copy of the program code!
Code: Select all
WebPage2Clipboard()
Code: Select all
WebPage2Clipboard():Delay(3000)
Code: Select all
Procedure WebPage2Clipboard()
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)
;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(20)
;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(20)
;Control key up
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
EndProcedure
#debut_url="https://www.google.com/search?q="
#fin_url=""
Chanson$="date chanson Michael Jackson Thriller"
RequeteGoogle$=URLEncoder(#debut_url + Chanson$ + #fin_url )
RunProgram("C:\Program Files (x86)\Google\Chrome\Application\chrome_proxy.exe",RequeteGoogle$,"")
Delay(4000); wait till chrome becomes stable
;OriginalClipBoard$=GetClipboardText()
WebPage2Clipboard():Delay(3000)
A$=GetClipboardText()
Debug a$
;SetClipboardText(OriginalClipBoard$)
Code: Select all
Procedure WebPage2Clipboard()
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)
;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(20)
;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(20)
;Control key up
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
EndProcedure
#debut_url="https://www.google.com/search?q="
#fin_url=""
Chanson$="date chanson Michael Jackson Thriller"
RequeteGoogle$=URLEncoder(#debut_url + Chanson$ + #fin_url )
RunProgram("C:\Program Files\Google\Chrome\Application\chrome_proxy.exe",RequeteGoogle$,"")
WebPage2Clipboard();:Delay(2000)
A$=GetClipboardText()
Debug a$
Code: Select all
Program = RunProgram(...)
ProcessID = ProgramID(Program)
Code: Select all
Procedure ExtractRegExMatch (text$, Array result$(1), regex$ = "")
Static iRegEx
Protected iRetVal = -1 ; regex error
If regex$
If iRegEx > 0:FreeRegularExpression(iRegEx):EndIf
iRegEx = CreateRegularExpression(#PB_Any, regex$)
EndIf
If iRegEx
iRetVal = ExtractRegularExpression(iRegEx, text$, result$())
EndIf
ProcedureReturn iRetVal
EndProcedure
Procedure.s ExtractRegExString(text$, regex$ = "")
Dim result$(0)
ExtractRegExMatch (text$, result$(), regex$)
ProcedureReturn result$(0)
EndProcedure
Procedure.s scrapString(String$,StartString$,EndString$)
stS.i = FindString(String$,StartString$)
stE.i = FindString(String$,EndString$,stS)
If stS = 0 And stE = Len(EndString$):stE = 0:EndIf
ProcedureReturn Mid(String$,stS,stE)
EndProcedure
Procedure.s GetURLText(url$)
*Buffer = ReceiveHTTPMemory(URLEncoder(url$))
If *Buffer
Size = MemorySize(*Buffer)
text$ = PeekS(*Buffer, Size, #PB_UTF8 | #PB_ByteLength)
FreeMemory(*Buffer)
EndIf
ProcedureReturn text$
EndProcedure
Debug ExtractRegExString(scrapString(GetURLText("https://www.google.com/search?q=Lionel Richie Can't get over you release date"),"Released","img"),"(?!>)[0-9]{1,4}(?=</)")
You can send another short cut key sequence to the chrome window to close it.On the other hand, if I run the program 10 times, it opens 10 web pages. How to close them programmatically?
Code: Select all
Procedure CloseChromeTap()
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)
;w press
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 87 ;87
InputKey\ki\dwFlags = 0
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;w release
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = 87 ;87
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
;Control key up
InputKey\Type = #INPUT_KEYBOARD
InputKey\ki\wVk = #VK_CONTROL
InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @InputKey, SizeOf(INPUT))
Delay(20)
EndProcedure
Code: Select all
A$=GetClipboardText()
CloseChromeTap()