Send Commands and Loops

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kasuokun
Posts: 2
Joined: 12 Aug 2022, 22:03

Send Commands and Loops

Post by kasuokun » 12 Aug 2022, 22:22

Good evening!

I've been using AHK for a couple of years, but today ran into an error that I haven't experienced before, and searching for solutions or similar situations didn't help...

First, the code in question:

Code: Select all

Loop, %times
{
	; selecting search term
	clipboard := % searchterm
	Send ^E
	Sleep 1000
	Send ^V
	Sleep 1000
	Send {Enter}
	Sleep 3000
	; grab page data
}
I understand that this is only a snippet, but it's where the error is located and the rest of the code works fantastically.

This is meant to be run in combination with Edge and Chrome: basically, grab direct search results for an external list of research terms. It seems as though the 3 Send commands only execute with the first pass of the loop. I've tried different AHK installs on this particular computer and tried changing the loop's execution (open the browser, execute the send commands, etc.), but so far the Send commands only works properly on the first loop. The Sleep commands are still being executed in each loop, though.

This feels so weird and is bugging me so much. Any advice or pointers would be amazing! Thank you!

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Send Commands and Loops

Post by Xtra » 13 Aug 2022, 00:51

Code: Select all

Loop, % times    ; <--- when using single % use a space after it or use %times%
{
	; selecting search term
	clipboard := searchterm    ; <--- extra % not needed when using := (expression)
	Send ^e    ; <--- E will send Shift e to make caps
	Sleep 1000
	Send ^v    ; <--- V will send Shift v to make caps
	Sleep 1000
	Send {Enter}
	Sleep 3000
	; grab page data
}
try that

User avatar
kasuokun
Posts: 2
Joined: 12 Aug 2022, 22:03

Re: Send Commands and Loops

Post by kasuokun » 13 Aug 2022, 07:38

Thank you! Looks like the route of the problem was sending ^E instead of ^e, which is strange as this is the first time I've seen this behavior...

I was under the impression that "Send ^E" would be equivalent to "Send {Shift}E", which would've been equivalent to "Send {Shift}e" or "Send ^e" in this situation. But now that I think about it, normal keyboard usage would not allow you to capitalize a capitalized character...

Again, thank you! Now to go back to my older scripts and update them to avoid this in the future...

Post Reply

Return to “Ask for Help (v1)”