Feeling Stupid, Need a little push in right direction

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Cambridge
Posts: 2
Joined: 29 Nov 2019, 12:25

Feeling Stupid, Need a little push in right direction

29 Nov 2019, 12:45

So, I am trying to learn AHK to use at work. In this little test I am running I was trying to get MSpaint to pick a different Brush, so I got the Basics of it, my problem is I don't want to have to past this long code each time I want to make it pick a brush, so I read about Labels and GoSub, So I made at the start of the script put this code in, but problem is that every time I run the script it runs that part it picks a brush. Then sits and waits, and will run the next part when I press the hotkey. So what I was wondering is there a way to not have it run the label until it is called up by the GoSub, do I have to put all labels at the end? Am I doing this all the wrong way? I thought maybe a function but there are not var to be put in. So seemed not right. I am sorry if this is been asked before, I searched, but could not find the right set of keywords on google or the forums to find a solution. Thanks in advance.

Code: Select all

Brush:
MouseClick, Left, 332, 104
Sleep, 500

Random, zBrush, 1, 9

IfEqual, zBrush, 1
	{
	MouseClick, Left, 335, 137
	Sleep, 100
	
	}

IfEqual, zBrush, 2
	{
	MouseClick, Left, 375, 137
	Sleep, 100

	}

IfEqual, zBrush, 3
	{
	MouseClick, Left, 415, 137
	Sleep, 100
	
	}

IfEqual, zBrush, 4
	{
	MouseClick, Left, 455, 137
	Sleep, 100
	
	}

IfEqual, zBrush, 5
	{
	MouseClick, Left, 335, 177
	Sleep, 100
	
	}

IfEqual, zBrush, 6
	{
	MouseClick, Left, 375, 177
	Sleep, 100
	
	}

IfEqual, zBrush, 7
	{
	MouseClick, Left, 415, 177
	Sleep, 100
	
	}

IfEqual, zBrush, 8
	{
	MouseClick, Left, 455, 177
	
	}

IfEqual, zBrush, 9
	{
	MouseClick, Left, 335, 217
	Sleep, 100
	
}
Return


9::
Loop, 5
{

Random, X3, 765, 962 
Random, Y3, 64, 85
  
MouseClick, Left, X3, Y3 ; Picks a color
Sleep, 100

GoSub Brush ; Picks a brush

Return
	
}
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Feeling Stupid, Need a little push in right direction

29 Nov 2019, 13:40

I don't understand well what you are trying to do, but try starting the script with this and remove it from the bottom and also goto might be better for this than gosub but I really don't know this well.

Code: Select all

9::
Loop, 5
{

Random, X3, 765, 962 
Random, Y3, 64, 85
  
MouseClick, Left, X3, Y3 ; Picks a color
Sleep, 100

GoSub Brush ; Picks a brush

Return
	
}
Cambridge
Posts: 2
Joined: 29 Nov 2019, 12:25

Re: Feeling Stupid, Need a little push in right direction

29 Nov 2019, 14:04

Thanks AHKStudent, Yea have a feeling putting it at the bottom will be the way to go.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Feeling Stupid, Need a little push in right direction

29 Nov 2019, 15:31

I think you want this:

Code: Select all

;before:

GoSub Brush ; Picks a brush

Return

}

;after:

GoSub Brush ; Picks a brush

}

Return
Otherwise the loop stops after the first iteration.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], peter_ahk and 336 guests