Help with ahk

Get help with using AutoHotkey and its commands and hotkeys
ivyandrei
Posts: 7
Joined: 11 Aug 2018, 20:10

Help with ahk

11 Aug 2018, 20:18

Hi! I am a beginer and i don't know why my ahk is not working totally. It's going through 1 loop and then nothing.. I tried find something on site to solve this but i don't understand all from them. Please help me and sorry for my english.

Code: Select all

^+r::
looptot:
loop
{
if (Breakloop = 1) {
break
} else {
WinActivate ahk_class Chrome_WidgetWin_1
Send ^1
Scrollloop:
loop
	{
	PixelGetColor, scroll, 1834 , 134, RGB
	If !(scroll = "0x000000")
	break
}
Click, 1911, 107
Click, 1911, 107
Click, 1911, 107
Click, 1911, 107
Click, 1911, 107
MouseClickDrag, left, 1911, 147, 1916, 211, 0
loopultimele3:
loop
{
PixelSearch, x1, y1, 1312, 265, 1334, 286, 0xFFFFFF, 0, Fast RGB
If (ErrorLevel = 0) {
	one := true
} else {
	one := false
}
PixelSearch, x2, y2, 1343, 265, 1365, 286, 0xFFFFFF, 0, Fast RGB
If (ErrorLevel = 0) {
	two := true
} else {
	two := false
}
PixelSearch, x3, y3, 1376, 265, 1396, 286, 0xFFFFFF, 0, Fast RGB
If (ErrorLevel = 0) {
	three := true
} else {
	three := false
}	
If (one) and (two) and (three) {
	break
}
}
loopurmatoareaculoare:
loop
{
	PixelSearch, x4, y4, 975, 956, 981, 961, 0x000000, 0, Fast RGB
	if !ErrorLevel {
		break
	sleep, 50
}
}
sleep, 4000
click, 905, 745
sleep, 14000
loopurmatoareaculoare2:
loop
{PixelGetColor, color, 979, 956, RGB
if !(color = "0x3C9649") {
	break
}
}
sleep, 1000
loopdacaediferitderosu:
loop
{
PixelGetColor, color2, 979, 956, RGB
If !(color2 = "0xFF0000") {
loopdubleaza:
loop
{
			sleep, 4000
			click, 1135, 1002
			click, 1135, 1002
			sleep, 14000
			loopverificadacavinerosu:
			loop:
			{
			PixelGetColor, color3, 979, 956, RGB
				If (color3 = "0xFF0000") {
				break
			} else {
				Continue , looptot
			}
}
^+s::
Breakloop = 1
return				
Rohwedder
Posts: 1532
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help with ahk

12 Aug 2018, 03:32

Hallo,
6 Errors: Missing "}"
Try it with a clean indentation!
https://autohotkey.com/docs/Tutorial.htm#s84
Alibaba
Posts: 473
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Help with ahk

12 Aug 2018, 14:34

Hello ivyandrei, welcome to the forums!
For your future topics, please try to use more specifical titles. “Help with ahk” is a bit too general for an ahk help forum. ;)
"Nothing is quieter than a loaded gun." - Heinrich Heine
ivyandrei
Posts: 7
Joined: 11 Aug 2018, 20:10

Re: Help with ahk

12 Aug 2018, 14:48

I modified the script to look better and understand something from it and i solved the problem with the missing "}", but it's not doing what i want. I made this script to play for me at roulette. The site is automatic and it doesn't have a start button so i had to schedule it to wait for the spins. I made him to open my chrome tab and fix the page exactly where i need, then is verifying if the last 3 spins were black and then is waiting for the next spin and if it is black it places bet on red and it it is red, restart the all loop.. If i have more black spins in a row it have to double the bet.. The ahk is only fixing my web page and it's not placing any bet. The "loopifthecolorwillchange" is used where i see what came out this round, i used it because there is coming a black/red/green square with a yellow edge.. Please help me!

Code: Select all

^+r::
loopall:
loop
{
	if (Breakloop = 1) {
	break
	} else {
	WinActivate ahk_class Chrome_WidgetWin_1
	Send ^1
		Scrollloop:
			loop
			{
			PixelGetColor, scroll, 1834 , 134, RGB
			If !(scroll = "0x000000") {
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				MouseClickDrag, left, 1911, 147, 1916, 211, 0
				} else {
				break
				}
			}	
		looplast3:
		loop
		{
			PixelSearch, x1, y1, 1312, 265, 1334, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				one := true
			} else {
				one := false
			}
			PixelSearch, x2, y2, 1343, 265, 1365, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				two := true
			} else {
				two := false
			}
			PixelSearch, x3, y3, 1376, 265, 1396, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				three := true
			} else {
				three := false
			}	
			If (one) and (two) and (three) {
			break
			}
		}	
	loopifblackiscoming:
	loop
	{
		PixelSearch, x4, y4, 975, 956, 981, 961, 0x000000, 0, Fast RGB
		if !ErrorLevel {
			break
		sleep, 50
		}
	}
	sleep, 4000
	click, 905, 745
	sleep, 14000
				loopifthecolorwillchange:
				loop
				{
					PixelGetColor, color, 979, 956, RGB
					if !(color = "0x3C9649") {
						break
					}	
				}
				sleep, 1000
							loopifiwon:
							loop
							{
								PixelGetColor, color2, 979, 956, RGB
								If (color2 = "0xFF0000") {
									Continue , loopall
								} else {
									sleep, 4000
									click, 1135, 1002
									click, 1135, 1002
									sleep, 14000
									Continue , loopifthecolorwillchange
								} 			
							}
	}
}

^+s::
Breakloop = 1
return				
ivyandrei
Posts: 7
Joined: 11 Aug 2018, 20:10

Re: Help with ahk

14 Aug 2018, 13:37

Someone know what is the problem?
User avatar
Xtra
Posts: 1271
Joined: 02 Oct 2015, 12:15

Re: Help with ahk

14 Aug 2018, 14:09

Read here: CoordMode
ivyandrei
Posts: 7
Joined: 11 Aug 2018, 20:10

Re: Help with ahk

14 Aug 2018, 18:33

Xtra wrote:Read here: CoordMode
Thank you for your suggestion. That went some way, it's not entering looplast3 where it was supposed to verify if the last three numbers were black and then continue, but it's placing bet after 1 black indifferent if the last 3 are black/red/green.
User avatar
Xtra
Posts: 1271
Joined: 02 Oct 2015, 12:15

Re: Help with ahk

14 Aug 2018, 19:04

Did you set coordmode for mouse and pixel ?

Show your changes.
ivyandrei
Posts: 7
Joined: 11 Aug 2018, 20:10

Re: Help with ahk

14 Aug 2018, 20:03

I did not understand everything from there. That's the ahk with the changes. It's skipping the looplast2. There is the problem.

Code: Select all

^+r::
loopall:
loop
{
	if (Breakloop = 1) {
	break
	} else {
	WinActivate ahk_class Chrome_WidgetWin_1
	Send ^1
		Scrollloop:
			loop
			{
			CoordMode, Pixel , Screen
			PixelGetColor, scroll, 1834 , 134, RGB
			If !(scroll = "0x000000") {
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				MouseClickDrag, left, 1911, 147, 1916, 211, 0
				} else {
				break
				}
			}	
		looplast2:
		loop
		{
			CoordMode, Pixel , Screen
			PixelSearch, x1, y1, 1312, 265, 1334, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				one := true
			} else {
				one := false
			}
			CoordMode, Pixel , Screen
			PixelSearch, x2, y2, 1343, 265, 1365, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				two := true
			} else {
				two := false
			}	
			If (one) and (two) {	
				loopifblackiscoming:
				loop
				{
					CoordMode, Pixel , Screen
					PixelSearch, x4, y4, 975, 956, 981, 961, 0x000000, 0, Fast RGB
					if !ErrorLevel {
						break
					sleep, 50
					}
				}
				sleep, 4000
				click, 905, 745
				sleep, 14000
							loopifthecolorwillchange:
							loop
							{
								CoordMode, Pixel , Screen
								PixelGetColor, color, 979, 956, RGB
								if !(color = "0x3D9749") {
									break
								}	
							}
							sleep, 1000
										loopifiwon:
										loop
										{
											CoordMode, Pixel , Screen
											PixelGetColor, color2, 979, 956, RGB
											If (color2 = "0xFF0000") {
												Continue , loopall
											} else {
												sleep, 4000
												click, 1135, 1002
												click, 1135, 1002
												sleep, 14000
												Continue , loopifthecolorwillchange
											} 			
										}
		}							
	}
}
}

^+s::Exitapp
return				
User avatar
Xtra
Posts: 1271
Joined: 02 Oct 2015, 12:15

Re: Help with ahk

14 Aug 2018, 20:07

Put:
CoordMode, Pixel , Screen
and
CoordMode, Mouse, Screen

At the top of the script and remove all the other coordmode references you added.

Try it and see what happens.
ivyandrei
Posts: 7
Joined: 11 Aug 2018, 20:10

Re: Help with ahk

14 Aug 2018, 20:55

I tried and it's doing the same thing. I posted you a photo of the site to see how it looks.

Code: Select all

^+r::
loopall:
loop
{
	CoordMode, Pixel , Screen
	CoordMode, Mouse, Screen
	if (Breakloop = 1) {
	break
	} else {
	WinActivate ahk_class Chrome_WidgetWin_1
	Send ^1
		Scrollloop:
			loop
			{
			PixelGetColor, scroll, 1834 , 134, RGB
			If !(scroll = "0x000000") {
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				MouseClickDrag, left, 1911, 147, 1916, 211, 0
				} else {
				break
				}
			}	
		looplast2:
		loop
		{
			PixelSearch, x1, y1, 1312, 265, 1334, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				one := true
			} else {
				one := false
			}
			PixelSearch, x2, y2, 1343, 265, 1365, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				two := true
			} else {
				two := false
			}	
			If (one) and (two) {	
				loopifblackiscoming:
				loop
				{
					PixelSearch, x4, y4, 975, 956, 981, 961, 0x000000, 0, Fast RGB
					if !ErrorLevel {
						break
					sleep, 50
					}
				}
				sleep, 4000
				click, 905, 745
				sleep, 14000
							loopifthecolorwillchange:
							loop
							{
								PixelGetColor, color, 979, 956, RGB
								if !(color = "0x3D9749") {
									break
								}	
							}
							sleep, 1000
										loopifiwon:
										loop
										{
											PixelGetColor, color2, 979, 956, RGB
											If (color2 = "0xFF0000") {
												Continue , loopall
											} else {
												sleep, 4000
												click, 1135, 1002
												click, 1135, 1002
												sleep, 14000
												Continue , loopifthecolorwillchange
											} 			
										}
		}							
	}
}
}

^+s::Exitapp
return				
https://imgur.com/a/PzId9OO
User avatar
Xtra
Posts: 1271
Joined: 02 Oct 2015, 12:15

Re: Help with ahk

14 Aug 2018, 21:20

When you got all the coords for "everything" you need make sure you used screen coords (aka absolute)

Might be a good time to start using message boxes or tooltips to debug the issue.

Thats about all i can recommend atm.
ivyandrei
Posts: 7
Joined: 11 Aug 2018, 20:10

Re: Help with ahk

14 Aug 2018, 22:00

Xtra wrote:When you got all the coords for "everything" you need make sure you used screen coords (aka absolute)

Might be a good time to start using message boxes or tooltips to debug the issue.

Thats about all i can recommend atm.
Thank you for your help and for your wasted time. I really appreciate that. Maybe the problem is with “CoorMode, pixel, screen”. Should i use “CoordMode, pixel, window”? I used Mpos/Mousecoord or something like this to found the coordinates for the entire ahk.
User avatar
Xtra
Posts: 1271
Joined: 02 Oct 2015, 12:15

Re: Help with ahk

14 Aug 2018, 22:27

Whichever you used to get the coordinates and colors is what you need to use for the CoordMode setting.

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], newbieforever, swagfag, teadrinker and 37 guests