Simulate CTRL+A and CTRL+C
Simulate CTRL+A and CTRL+C
Good morning,
Can we, with Purebasic, simulate CTRL+A, CTRL+C and copy the result into a variable or a text file?
Thank you for your help.
Can we, with Purebasic, simulate CTRL+A, CTRL+C and copy the result into a variable or a text file?
Thank you for your help.
Re: Simulate CTRL+A and CTRL+C
Hello AZJIO
Thanks for the link, I looked but I don't understand anything!
Is there an example to do a CTRL + A and a CTRL + C?
Thanks for the link, I looked but I don't understand anything!
Is there an example to do a CTRL + A and a CTRL + C?
Re: Simulate CTRL+A and CTRL+C
It depends on the source of what you want to copy.
If it's just the content of a gadget with text, then it's easy:

If it's just the content of a gadget with text, then it's easy:
Code: Select all
SetClipboardText( GetGadgetText( ... ) )

Re: Simulate CTRL+A and CTRL+C
Hello Marc56us,
I want to search in google and copy the result of what is displayed.
I tried to download the page but I don't get everything, that's why I want:
1) Create a web gadget
2) Launch my google search (example "Release date song Lionel Richie Can't get over you"
3) Copy the displayed result into a string variable
4) Find the release date of the song in the string variable
See picture

I want to search in google and copy the result of what is displayed.
I tried to download the page but I don't get everything, that's why I want:
1) Create a web gadget
2) Launch my google search (example "Release date song Lionel Richie Can't get over you"
3) Copy the displayed result into a string variable
4) Find the release date of the song in the string variable
See picture

Re: Simulate CTRL+A and CTRL+C
Hello ZX80,
thanks, i will test this in my code.
thanks, i will test this in my code.
Re: Simulate CTRL+A and CTRL+C
Hello ZX80,
I tried with CTRL + A, it doesn't work
I tried with CTRL + A, it doesn't work
Re: Simulate CTRL+A and CTRL+C
@jak64
May also need this.
May also need this.
Code: Select all
...
; Check To see If we are the foreground thread
foregroundThreadID = GetWindowThreadProcessId_(GetForegroundWindow_(), 0)
ourThreadID = GetCurrentThreadId_()
; If not, attach our thread's 'input' to the foreground thread's
If (foregroundThreadID <> ourThreadID)
AttachThreadInput_(foregroundThreadID, ourThreadID, #TRUE);
EndIf
...
Re: Simulate CTRL+A and CTRL+C
Hello ZX80,
Hello ZX80,
I don't understand anything at all, the content of the WEb page is not selected
Here is my code:
Hello ZX80,
I don't understand anything at all, the content of the WEb page is not selected
Here is my code:
Code: Select all
EnableExplicit
;----- Enumérations
Enumeration
#FenetreWindows
#WebGadget
EndEnumeration
;----- Constantes
#debut_url="https://www.google.com/search?q="
#fin_url=""
;----- Variables
Global Event.q
Global Chanson.s
Global RequeteGoogle.s
Global Resultat.s
Global foregroundThreadID
Global ourThreadID
Global Dim SendInputData.INPUT(3)
; press CONTROL
SendInputData(0)\type = #INPUT_KEYBOARD
SendInputData(0)\ki\wVK = #VK_CONTROL
; press A
SendInputData(1)\type = #INPUT_KEYBOARD
SendInputData(1)\ki\wVK = #VK_A
; release A
SendInputData(2)\type = #INPUT_KEYBOARD
SendInputData(2)\ki\dwFlags = #KEYEVENTF_KEYUP
SendInputData(2)\ki\wVK = #VK_A
; release CONTROL
SendInputData(3)\type = #INPUT_KEYBOARD
SendInputData(3)\ki\dwFlags = #KEYEVENTF_KEYUP
SendInputData(3)\ki\wVK = #VK_CONTROL
OpenWindow(#FenetreWindows, 0, 0, 1366, 768, "", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
Chanson="date chanson Michael Jackson Thriller"
RequeteGoogle=URLEncoder(#debut_url + Chanson + #fin_url )
WebGadget(#WebGadget, 0, 0, 1366, 768, RequeteGoogle)
SetActiveGadget(#WebGadget)
foregroundThreadID = GetWindowThreadProcessId_(GetForegroundWindow_(), 0)
ourThreadID = GetCurrentThreadId_()
; If not, attach our thread's 'input' to the foreground thread's
If (foregroundThreadID <> ourThreadID)
AttachThreadInput_(foregroundThreadID, ourThreadID, #True);
EndIf
SendInput_(1, @SendInputData(0), SizeOf(INPUT))
Delay(30)
SendInput_(1, @SendInputData(1), SizeOf(INPUT))
Delay(200)
SendInput_(1, @SendInputData(2), SizeOf(INPUT))
Delay(30)
SendInput_(1, @SendInputData(3), SizeOf(INPUT))
Delay(30)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Re: Simulate CTRL+A and CTRL+C
@jak64
During the pause that I set for the test of 5 seconds, just click on the working field of the page.
It works. You only need set the focus to the working field, and then remove the selection.
During the pause that I set for the test of 5 seconds, just click on the working field of the page.
It works. You only need set the focus to the working field, and then remove the selection.
Code: Select all
Delay(5000)
Dim SendInputData.INPUT(5)
; press CONTROL
SendInputData(0)\type = #INPUT_KEYBOARD
SendInputData(0)\ki\wVK = #VK_CONTROL
; press A
SendInputData(1)\type = #INPUT_KEYBOARD
SendInputData(1)\ki\wVK = #VK_A
; release A
SendInputData(2)\type = #INPUT_KEYBOARD
SendInputData(2)\ki\dwFlags = #KEYEVENTF_KEYUP
SendInputData(2)\ki\wVK = #VK_A
; press C
SendInputData(3)\type = #INPUT_KEYBOARD
SendInputData(3)\ki\wVK = #VK_C
; release C
SendInputData(4)\type = #INPUT_KEYBOARD
SendInputData(4)\ki\dwFlags = #KEYEVENTF_KEYUP
SendInputData(4)\ki\wVK = #VK_C
; release CONTROL
SendInputData(5)\type = #INPUT_KEYBOARD
SendInputData(5)\ki\dwFlags = #KEYEVENTF_KEYUP
SendInputData(5)\ki\wVK = #VK_CONTROL
For i=0 To 5
SendInput_(1, @SendInputData(i), SizeOf(INPUT))
Delay(200)
Next i
Re: Simulate CTRL+A and CTRL+C
You repeat this question.
The day before yesterday I tried to use Ctrl+A, but it didn't work. If I use SetActiveGadget() it still doesn't place the text cursor inside the page. When using CHM files, you can move the cursor to the page with the F6 key and use Ctrl + A, but this does not work in the gadget, you have to click, and this is not reliable, since you can accidentally click on the link. I don't have a solution.
Re: Simulate CTRL+A and CTRL+C
This will get you the Google search result; now you have to find the "1996" in it (it's there). It will be hard to extract, and maybe RegEx will be needed.jak64 wrote: Sat Apr 08, 2023 5:37 pm2) Launch my google search (example "Release date song Lionel Richie Can't get over you"
3) Copy the displayed result into a string variable
4) Find the release date of the song in the string variable
Don't forget that the format of Google's results can and will likely change, so whatever method you use to extract today will probably not work in a month.
It'd be better and more reliable to get the search result from a dedicated online music library, if possible.
Code: Select all
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 GetURLText("https://www.google.com/search?q=Lionel Richie Can't get over you release date")
Re: Simulate CTRL+A and CTRL+C
@Jak64
If you can accept the limitation of using external chrome.exe instead of PB webgaget, you can try below method.
Thanks
Allen
If you can accept the limitation of using external chrome.exe instead of PB webgaget, you can try below method.
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()
A$=GetClipboardText()
Debug a$
;SetClipboardText(OriginalClipBoard$)
Allen
Re: Simulate CTRL+A and CTRL+C
Hello BarryG,
I tried to use musical bases but I did not find how to exploit them.
I tried to use musical bases but I did not find how to exploit them.