Autohotkey Continue Must Be Closed by a Loop

  • Members
  • 42 posts
  • Last active: Oct 10 2013 12:16 PM
  • Joined: 02 Sep 2010

Hey everyone.

I'm trying to harvest some information from a lighting program I use. For starters, I just want it to grab the room name/number to enter into another text box. The text is dumb, single line text, so I have to manually select each piece, and add it to the end of a variable. I have all of that working just fine, but sometimes the name will be one word, sometimes 2 or 3. I'm trying to find a way to keep looping and adding text I select to the end of my variable, but break out of the loop when I press a key (let's say z, for example). I tried adding a hotkey to trigger a BREAK command, but that doesn't seem to work. I want the line KeyWait, LButton, D to also expect my hotkey (z) to exit the loop instead. Can anyone give me some advice?

(Working code if I use Loop, 2)

^Left:: 		Loop [color=#00BF00];I need this to loop until I press the z key[/color] 		{ 			[color=#FF0000];z:: break ;doesn't work[/color] 			Clipboard = 			Send {Ctrl Down}{Shift Down}t{Shift Up}{Ctrl Up} [color=#00BF00];Command to edit text[/color] 			KeyWait, LButton, D [color=#00BF00];Wait for me to select text[/color] 			Sleep 100 			Send ^c [color=#00BF00];copy selected text to clipboard[/color] 			Clipwait, 0 			if (A_Index = 1) 				clip1 := Clipboard [color=#00BF00];store text in variable first time[/color] 			else 				clip1 := clip1 " " Clipboard [color=#00BF00];add to end of variable every other time.[/color] 			Send {Alt Down}{F4}{Alt Up} [color=#00BF00];close dialog[/color] 		} 		sleep 100 		Send ^y [color=#00BF00];command to create calculation zone[/color] 		sleep 500 		ControlFocus, ThunderRT6TextBox10 [color=#00BF00];bring focus to text box[/color] 		Clipboard := Clip1 		Send ^v [color=#00BF00];paste final data[/color] 		click [color=#00BF00];ignore[/color] 	Return

Thanks in advance,

-Chris

  • Back to top

Coco

  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012

Hey everyone.

I'm trying to harvest some information from a lighting program I use. For starters, I just want it to grab the room name/number to enter into another text box. The text is dumb, single line text, so I have to manually select each piece, and add it to the end of a variable. I have all of that working just fine, but sometimes the name will be one word, sometimes 2 or 3. I'm trying to find a way to keep looping and adding text I select to the end of my variable, but break out of the loop when I press a key (let's say z, for example). I tried adding a hotkey to trigger a BREAK command, but that doesn't seem to work. I want the line KeyWait, LButton, D to also expect my hotkey (z) to exit the loop instead. Can anyone give me some advice?

(Working code if I use Loop, 2)

^Left:: 		Loop [color=#00BF00];I need this to loop until I press the z key[/color] 		{ 			[color=#FF0000];z:: break ;doesn't work[/color] 			Clipboard = 			Send {Ctrl Down}{Shift Down}t{Shift Up}{Ctrl Up} [color=#00BF00];Command to edit text[/color] 			KeyWait, LButton, D [color=#00BF00];Wait for me to select text[/color] 			Sleep 100 			Send ^c [color=#00BF00];copy selected text to clipboard[/color] 			Clipwait, 0 			if (A_Index = 1) 				clip1 := Clipboard [color=#00BF00];store text in variable first time[/color] 			else 				clip1 := clip1 " " Clipboard [color=#00BF00];add to end of variable every other time.[/color] 			Send {Alt Down}{F4}{Alt Up} [color=#00BF00];close dialog[/color] 		} 		sleep 100 		Send ^y [color=#00BF00];command to create calculation zone[/color] 		sleep 500 		ControlFocus, ThunderRT6TextBox10 [color=#00BF00];bring focus to text box[/color] 		Clipboard := Clip1 		Send ^v [color=#00BF00];paste final data[/color] 		click [color=#00BF00];ignore[/color] 	Return

Thanks in advance,

-Chris

Try this:

^Left:: LoopKiller := "0"       Loop ;I need this to loop until I press the z key       {          ;z:: break ;doesn't work 		 if (LoopKiller = "1") 			break          Clipboard =          Send {Ctrl Down}{Shift Down}t{Shift Up}{Ctrl Up} ;Command to edit text          KeyWait, LButton, D ;Wait for me to select text          Sleep 100          Send ^c ;copy selected text to clipboard          Clipwait, 0          if (A_Index = 1)             clip1 := Clipboard ;store text in variable first time          else             clip1 := clip1 " " Clipboard ;add to end of variable every other time.          Send {Alt Down}{F4}{Alt Up} ;close dialog       }       sleep 100       Send ^y ;command to create calculation zone       sleep 500       ControlFocus, ThunderRT6TextBox10 ;bring focus to text box       Clipboard := Clip1       Send ^v ;paste final data       click ;ignore    Return        z::    LoopKiller := "1"    return

  • Back to top

cmikaiti

  • Members
  • 42 posts
  • Last active: Oct 10 2013 12:16 PM
  • Joined: 02 Sep 2010

Thanks for the help, Coco. I can't get it to break at the right time, though.

I was hoping for something along the lines of

Keywait (LButton or z), d
if z
break
if Lbutton
code

As it is now, I always have to select another piece of text after pressing my 'break' key. no matter where I put it, it won't break after appending the last text, but before the keywait.

I think the problem is that the lone keywait is the only time my script is 'on hold' but I can't think of another way to accomplish what I'm after.

If anyone has any great ideas, I'd love to hear it. Otherwise, I guess I'll just increment/decrement the loop counter through a hotkey on the fly. That'll work ok.

-Chris

  • Back to top

Leef_me

  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

Hi cmikaiti, in case no one else has said it, "welcome to the forum".

The script changes that Coco suggested would seem to be a working combination.
Have you tried moving these two lines to a different part of the loop ??

if (LoopKiller = "1")          break

  • Back to top

cmikaiti

  • Members
  • 42 posts
  • Last active: Oct 10 2013 12:16 PM
  • Joined: 02 Sep 2010

Yeah, the same thing happens wherever I put it.

No matter where the break-test is, I have a very short period of time between selecting one piece of text at the keywait, and it looping back to the keywait again. While I am at the keywait, z doesn't break out of the loop immediately (since the if-block has either passed, or hasn't occured yet). I need it to break immediately and override the keywait.

The only way to break the loop is to press z, then LButton (which, if I'm understanding things correctly, z changes loopkiller to 1, then LButton allows the loop to continue until it hits the break-test again.

In any event. Consider this problem closed. The issue may be completely on my end (funky program), and the loop will only ever need to loop 2, 3, or 4 times. That's easy enough for me to change on the fly.

Thanks for the help everyone.

-Chris

  • Back to top

Leef_me

  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

>>In any event. Consider this problem closed.

Please don't do that. You need a working program/script.
Can you tell us more about the program?
Perhaps instead of you having to do the marking it can be done a different way.

  • Back to top

Wingfat

  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004

I personally would add in a GetKeyState command to help out the break, seems to work better for me when i do so.

^Left::       Loop        {         GetKeyState, zBreak, Z          If zBreak = D             Break                    Clipboard =          Send {Ctrl Down}{Shift Down}t{Shift Up}{Ctrl Up} ;Command to edit text          KeyWait, LButton, D ;Wait for me to select text          Sleep 100          Send ^c ;copy selected text to clipboard          Clipwait, 0          if (A_Index = 1)             clip1 := Clipboard ;store text in variable first time          else             clip1 := clip1 " " Clipboard ;add to end of variable every other time.          Send {Alt Down}{F4}{Alt Up} ;close dialog       }       sleep 100       Send ^y ;command to create calculation zone       sleep 500       ControlFocus, ThunderRT6TextBox10 ;bring focus to text box       Clipboard := Clip1       Send ^v ;paste final data       click ;ignore    Return            

----------------------------
Wingfool you fat! I mean, Wingfat you fool!
Line from Woody Allen's movie "What's Up Tiger Lilly?"
-----------------------------

  • Back to top

cmikaiti

  • Members
  • 42 posts
  • Last active: Oct 10 2013 12:16 PM
  • Joined: 02 Sep 2010

Thanks for the help, Wingfat, but no luck. It certainly could be that I am doing something wrong, but no matter. Also, thanks to everyone else who helped. The script, as is, cuts my time down to about 1/4 of what it used to be. I'm at a point of diminishing returns if I pursue perfection. I'm happy with my current solution, adjusting the loop counter as I need it. Final code below.

~LButton & WheelUp:: 	LoopCTR += 1 	tooltip %LoopCTR% 	return ~LButton & WheelDown:: 	LoopCTR -= 1 	tooltip %LoopCTR% 	return 	 	^Left:: 		Loop, %LoopCTR% ;I need this to loop until I press the z Button  		{ 			Clipboard = 			Send {Ctrl Down}{Shift Down}t{Shift Up}{Ctrl Up} ;Command to edit text 			KeyWait, LButton, D ;Wait for me to select text 			Sleep 100 			Send ^c ;copy selected text to clipboard 			Clipwait, 0 			if (A_Index = 1) 				clip1 := Clipboard ;store text in variable first time 			else 				clip1 := clip1 " " Clipboard ;add to end of variable every other time. 			If ErrorLevel 				Break 			Else 				Send {Alt Down}{F4}{Alt Up} ;close dialog 		} 		sleep 100 		Send ^y ;command to create calculation zone 		sleep 500 		ControlFocus, ThunderRT6TextBox10 ;bring focus to text box 		Clipboard := Clip1 		Send ^v ;paste final data 		click ;ignore 	Return

  • Back to top

nievesbeentherize.blogspot.com

Source: https://www.autohotkey.com/board/topic/84481-how-to-exit-a-loop-with-a-hotkey/

0 Response to "Autohotkey Continue Must Be Closed by a Loop"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel