Trouble with an #If loop Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Crushthebug
Posts: 18
Joined: 07 Mar 2017, 04:30

Trouble with an #If loop

27 May 2017, 11:55

Hi so I've been using a set of scripts that I wrote pretty frequently. They are all very similar and I use them during the same task for different things, but they are all currently separated into separate AHK scripts.

I've been trying for hours to combine them into a single script that uses the "F" keys to toggle between them.

So what I need is, as an example, if I press F1 the script will "enable" only the thread that I have designated for it. If I press F2, it will "disable" all other threads that were running and only enable this thread I have designated for F2.

Here is an example of my current script:

Code: Select all

;My keybinds
key_ClickFast:="F1"
key_ClickFast2:="F2"
key_DeleteSpam:="F3"
key_Trigger1:="~LShift & ~Space"
key_Trigger2:="LCtrl & Space"
key_Exit:="End"

;My sounds so I know what I'm activating
Loop {
		Sleep, 1
		if GetKeyState(key_ClickFast)
			{
				SoundPlay, C:\Users\blahblahblah.mp3
			}
	
				if GetKeyState(key_ClickFast2)
			{
				SoundPlay, C:\Users\blahblahblah2.mp3
			}
		
				if GetKeyState(key_DeleteSpam)
			{
				SoundPlay, C:\Users\blahblahblah3.mp3
			}
			
				if GetKeyState(key_Exit)
			{
				Sleep, 100
				ExitApp
			}
}
	
;My scripts threads that I was trying to combine	
{
	if ClickFast
	{
		Loop
		{
		if GetKeyState (key_Trigger1)
				{
				Send, {LButton}
				Sleep, 150
				}
		if GetKeyState (key_Trigger2)
				{
				Send, {LButton}
				Sleep, 20
				}
		Return
		}
	}
	if ClickFast2
	{
		Loop
		{
		if GetKeyState (key_Trigger1)
				{
				Send, {RButton}
				Sleep, 150
				}
		if GetKeyState (key_Trigger2)
				{
				Send, {RButton}
				Sleep, 20
				}
		Return
		}
	}
	if DeleteSpam
	{
		Loop
		{
		if GetKeyState (key_Trigger1)
				{
				Send, {Delete}
				Sleep, 150
				}
		if GetKeyState (key_Trigger2)
				{
				Send, {Delete}
				Sleep, 20
				}
		Return
		}
	}
}
Return
So obviously I'm clueless on how to do this haha. I feel like I'm making it way more complicated than I should be but I honestly can't figure this out at all! Please help a dude out!
Crushthebug
Posts: 18
Joined: 07 Mar 2017, 04:30

Re: Trouble with an #If loop

27 May 2017, 23:21

Anyone able to help with this? If I'm not explaining well enough what I need this to do, please let me know and I'll try my best to explain it better.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Trouble with an #If loop

28 May 2017, 00:17

There are several points that I could mention:

1) You don't have trouble with #If here (thread title), cause you don't have any #If in your code. You may not realize that #If is a positional directive that affects hotkeys, while If is a conditional statement to control the flow of code. But this is not likely what you are after.

2) You have used if GetKeyState(key_ClickFast) correctly inside your first Loop, after that your code shows an extra space between GetKeyState and the following parenthesis. There must not be that extra space.

3) You check e.g. if ClickFast where the variable ClickFast has not be defined in the script you posted. All these variables contain the empty string, and evaluate to False when used with If.

I guess you won't consider my hints as helpful, since they only refer to the basics, and not to how to organize separate scripts into a single script.
But try to get your If's working first, then see if that works as you expect. I can't test any of this code, I guess it is meant to work for a game. Which one?
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: Trouble with an #If loop  Topic is solved

28 May 2017, 00:46

try this

Code: Select all

#maxthreadsperhotkey 2 

enable := 0

f1::
	enable := 1
	SoundPlay, C:\Users\blahblahblah.mp3
return 
 
f2::
	enable := 2
	SoundPlay, C:\Users\blahblahblah.mp3
return

f3::
	enable := 3
	SoundPlay, C:\Users\blahblahblah.mp3
return

end::
	enable := 0
	sleep 1000
	exitapp
return                          

#if enable = 1
~lshift & ~space::
	send {Lbutton}
	sleep 150 
return              
~lctrl & ~space::
	send {Lbutton}
	sleep 20
return   
#if enable = 2
~lshift & ~space::
	send {Rbutton}
	sleep 150 
return              
~lctrl & ~space::
	send {Rbutton}
	sleep 20
return   
#if enable = 3
~lshift & ~space::
	send {delete}
	sleep 150 
return              
~lctrl & ~space::
	send {delete}
	sleep 20
return   
Crushthebug
Posts: 18
Joined: 07 Mar 2017, 04:30

Re: Trouble with an #If loop

28 May 2017, 08:50

donovv wrote:try this

Code: Select all

#maxthreadsperhotkey 2 

enable := 0

f1::
	enable := 1
	SoundPlay, C:\Users\blahblahblah.mp3
return 
 
f2::
	enable := 2
	SoundPlay, C:\Users\blahblahblah.mp3
return

f3::
	enable := 3
	SoundPlay, C:\Users\blahblahblah.mp3
return

end::
	enable := 0
	sleep 1000
	exitapp
return                          

#if enable = 1
~lshift & ~space::
	send {Lbutton}
	sleep 150 
return              
~lctrl & ~space::
	send {Lbutton}
	sleep 20
return   
#if enable = 2
~lshift & ~space::
	send {Rbutton}
	sleep 150 
return              
~lctrl & ~space::
	send {Rbutton}
	sleep 20
return   
#if enable = 3
~lshift & ~space::
	send {delete}
	sleep 150 
return              
~lctrl & ~space::
	send {delete}
	sleep 20
return   
Hey thanks a ton mate. It seems I was trying to get WAY too fancy and as a result was just confusing myself with stuff I was clueless with haha. Nice job!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Marium0505, Nerafius and 184 guests