Simulate CTRL+A and CTRL+C

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate CTRL+A and CTRL+C

Post by jak64 »

Hello Allen,
I tested the code but in the debug, I get the copy of the program code!
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: Simulate CTRL+A and CTRL+C

Post by BarryG »

What's the URL for musical bases, so I can test?
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate CTRL+A and CTRL+C

Post by jak64 »

Hello BarryG

I looked at this site but I don't know how to use it

https://musicbrainz.org/

I also looked in this list but did not find any database that I could exploit

https://en.wikipedia.org/wiki/List_of_o ... _databases
Allen
Enthusiast
Enthusiast
Posts: 103
Joined: Wed Nov 10, 2021 2:05 am

Re: Simulate CTRL+A and CTRL+C

Post by Allen »

@Jak64,
Hello Allen,
I tested the code but in the debug, I get the copy of the program code!
Please change

Code: Select all

WebPage2Clipboard()
to

Code: Select all

WebPage2Clipboard():Delay(3000)
and try again.

Thanks

Allen
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate CTRL+A and CTRL+C

Post by jak64 »

Hi Allen
Here's the program I'm testing and it doesn't work.

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$)
Allen
Enthusiast
Enthusiast
Posts: 103
Joined: Wed Nov 10, 2021 2:05 am

Re: Simulate CTRL+A and CTRL+C

Post by Allen »

@Jak64,

One reason I can think of is the delay time is not enough and the web page is not completly loaded. Please take a look at below video. You should be able to see the CTRL-A, CTRL-C effect on the chrome page.

https://streamable.com/5b8k7g

Please change the delay time at line 48 to delay(20000) and line 50 to delay(10000) and try again.

Thanks.

Allen Wong
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Simulate CTRL+A and CTRL+C

Post by Caronte3D »

Change:
RunProgram("C:\Program Files (x86)\Google\Chrome\Application\chrome_proxy.exe",RequeteGoogle$,"")
by
RunProgram("C:\Program Files\Google\Chrome\Application\chrome_proxy.exe",RequeteGoogle$,"")
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate CTRL+A and CTRL+C

Post by jak64 »

Hello Allen and Caronte3D,

I removed all the delays and changed the line

RunProgram("C:\Program Files\Google\Chrome\Application\chrome_proxy.exe",GoogleRequest$,"")

As Caront3D advised me and it works perfectly.

On the other hand, if I run the program 10 times, it opens 10 web pages. How to close them programmatically?

THANKS

Here is the code that works

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$
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Simulate CTRL+A and CTRL+C

Post by Caronte3D »

Really the best advice is BarryG's You should use a music database through her API.
Maybe you need to investigate more how to access it, but that way is far better than the google scraper one
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate CTRL+A and CTRL+C

Post by jak64 »

Hello caronte3D,
I agree with you but I want to do this just once to update the release date in my database which has 5000 MP3 songs and empty tags.

For new songs, I will read the tags after ripping the CD to mp3.
ZX80
Enthusiast
Enthusiast
Posts: 361
Joined: Mon Dec 12, 2016 1:37 pm

Re: Simulate CTRL+A and CTRL+C

Post by ZX80 »

Hello, jak64.

To be honest, it's all crutches. And it's not safe! I agree with Caronte3D and BarryG.
But... If you insist on this option, then I would do this:

Code: Select all

Program = RunProgram(...)
ProcessID = ProgramID(Program)
then you can list all running processes in the system and kill the one you need. There have already been such examples on this forum somewhere. Try searching.
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

Re: Simulate CTRL+A and CTRL+C

Post by vwidmer »

This works for me:

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}(?=</)")
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
Allen
Enthusiast
Enthusiast
Posts: 103
Joined: Wed Nov 10, 2021 2:05 am

Re: Simulate CTRL+A and CTRL+C

Post by Allen »

@Jak64,
On the other hand, if I run the program 10 times, it opens 10 web pages. How to close them programmatically?
You can send another short cut key sequence to the chrome window to close it.

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
Close the tap after you got the clipboard content.

Code: Select all

A$=GetClipboardText()
CloseChromeTap()
Thanks.

Allen
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Simulate CTRL+A and CTRL+C

Post by jak64 »

Thank you Allen
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Simulate CTRL+A and CTRL+C

Post by Marc56us »

If you send 5000 identical requests from the same IP to the same server, the firewall of the remote site will consider it a flooding attempt and will block you (at least for a while).
If you want to update a large number of titles, you will have to use a remote database (and sometimes get a login, sometimes pay).
Otherwise, you have to do it one by one. Some sites allow free access with a certain limit per day (e.g. 200 queries / day).
As for the analysis of a standard page of google or other, as you can see, it changes every day.
So you can easily build something based on RegEx, but it will have to be modified often.
Post Reply