ELSE with no matching IF

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
HEx_LTU94

ELSE with no matching IF

18 Nov 2017, 20:12

Hey I just start with ahk and tried to write script but do not get it, need help.
Sorry for the bad English

Code: Select all

#NoEnv
SendMode Input
~CapsLock::Suspend
~End::ExitApp


LButton::
RButton:: 
Loop
{
	If (GetKeyState("RButton", "p") && GetKeyState("LButton", "p")=0)
		Click
			sleep 15
			mouseXY(0,70)		
			sleep 70
			mouseXY(0,35)
			sleep 70
			mouseXY(0,15)
			sleep 40
			mouseXY(0,7)
			sleep 40
			mouseXY(0,5)
			Break
{


	Else if (GetKeyState("RButton", "u") && GetKeyState("LButton", "p")=0)
	{
		Click
			sleep 15
			mouseXY(0,50)		
			sleep 70
			mouseXY(0,21)
			sleep 70
			mouseXY(0,11)
			sleep 40
			mouseXY(0,10)
			Break
	}
}

return
mouseXY(x,y)
{
DllCall("mouse_event",int,1,int,x,int,y,uint,0,uint,0)
}
Georgie Munteer

Re: ELSE with no matching IF

19 Nov 2017, 03:24

looking at it quickly it seems you forgot to enclose your if statement in { }, you did it for the else if

Code: Select all

#NoEnv
SendMode Input
~CapsLock::Suspend
~End::ExitApp


LButton::
RButton:: 
Loop
{
	If (GetKeyState("RButton", "p") && GetKeyState("LButton", "p")=0)
		Click
			sleep 15
			mouseXY(0,70)		
			sleep 70
			mouseXY(0,35)
			sleep 70
			mouseXY(0,15)
			sleep 40
			mouseXY(0,7)
			sleep 40
			mouseXY(0,5)
			Break
{


	Else if (GetKeyState("RButton", "u") && GetKeyState("LButton", "p")=0)
	{
		Click
			sleep 15
			mouseXY(0,50)		
			sleep 70
			mouseXY(0,21)
			sleep 70
			mouseXY(0,11)
			sleep 40
			mouseXY(0,10)
			Break
	}
}

return
mouseXY(x,y)
{
DllCall("mouse_event",int,1,int,x,int,y,uint,0,uint,0)
}
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: ELSE with no matching IF

19 Nov 2017, 06:54

Like stated by the user above - You missed { after if and instead of [c}[/c] - there's a { before else if.
Assuming rest of the code is proper - this should work:

Code: Select all

#NoEnv
SendMode Input
~CapsLock::Suspend
~End::ExitApp


LButton::
RButton:: 
Loop
{
	If (GetKeyState("RButton", "p") && GetKeyState("LButton", "p")=0)
	{
		Click
		sleep 15
		mouseXY(0,70)		
		sleep 70
		mouseXY(0,35)
		sleep 70
		mouseXY(0,15)
		sleep 40
		mouseXY(0,7)
		sleep 40
		mouseXY(0,5)
		Break
	}
	Else if (GetKeyState("RButton", "u") && GetKeyState("LButton", "p")=0)
	{
		Click
		sleep 15
		mouseXY(0,50)		
		sleep 70
		mouseXY(0,21)
		sleep 70
		mouseXY(0,11)
		sleep 40
		mouseXY(0,10)
		Break
	}
}

return

mouseXY(x,y)
{
	DllCall("mouse_event",int,1,int,x,int,y,uint,0,uint,0)
}
Also, You can probably mix hotkeys, like LButton && RButton. Don't take my word on it, as I haven't used such.
Furthermore, You can create conditional hotkeys using #If.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk, Spawnova, toddhere, USS_Sandhu and 319 guests