Page 1 of 2

Autofire and toggle

Posted: 17 Dec 2015, 14:33
by tidbit
Here are 2 of the most commonly asked things (like, 5+ times a day). I'm not here to explain them as you probably don't care (but if you do care, ask below).
Choose which one you want. If you need to modify it, see "Helpful links" below.
Please try changing stuff yourself before asking. We appreciate any effort.

1. Press-and-Hold: Send or click while a button or key is held down

Code: Select all

setKeyDelay, 50, 50
setMouseDelay, 50

$~lbutton::
	while (getKeyState("lbutton", "P"))
	{
		send, {lbutton}
		sleep, 100
	}
return
2. Toggle: Press once to activate, press again to turn it off

Code: Select all

#maxThreadsPerHotkey, 2
setKeyDelay, 50, 50
setMouseDelay, 50
banana:=0

$f1::
	; banana:=!banana .... This assigns banana to the value of NOT (!) banana. so lets
	; say banana starts out FALSE (0). you then turn banana to NOT FALSE. which is
	; TRUE (1). so now banana is set to TRUE. and then lets say you toggle it again.
	; you set banana to NOT TRUE, which is FALSE. banana is now set to FALSE. 
	; .... 1 is true, 0 is false. ! is NOT.
	banana:=!banana
	
	while (banana=1)
	{
		send, hello{space}
		sleep, 100
	}
return
Helpful links:
1. Don't know how to use these? READ THIS: https://autohotkey.com/docs/Tutorial.htm
2. AHK not working in your game/program? READ THIS: https://autohotkey.com/boards/viewtopic.php?f=7&t=11084
3. List of keys to use as HOTKEYS (the line with "::"): https://autohotkey.com/docs/KeyList.htm
4. List of special keys (like {Enter}) to use with SEND: https://autohotkey.com/docs/commands/Send.htm
5. How to click the MOUSE: https://autohotkey.com/docs/commands/MouseClick.htm
6. Addition spamming methods, such as "cycle" and "settimer": https://autohotkey.com/board/topic/6457 ... re-thread/

Keywords (to help boost search results for those who searched):
autofire auto fire rapidfire rapid fire toggle spam spamkey fps shooter cast spell
auto shoot autoshoot cheat hack press key spam key spamkey burst pewpew pew press while held
press to toggle rapid press game start stop activate deactivate

Re: Autofire and toggle

Posted: 26 Dec 2015, 16:59
by pewpew
best bit of the post above
pewpew
:lol: :bravo:

Re: Autofire and toggle

Posted: 26 Dec 2015, 21:58
by joedf
hahah yes, or even
pewpew pew
So much 'pew' hahah :)

Re: Autofire and toggle

Posted: 06 Jan 2016, 14:08
by AlexFromTarget
I need some help with re-configuring a script that I use for an online game. This is what I'm using atm.
Spoiler
Basically, what I want to happen is for it to chain smoothly. I want it to use one skill first (W-hotkeyed) then have a slight delay mimicking the time it takes to switch fingers (without being too fast, otherwise it all turns to crap) and then chain the last skill (2-hotkeyed). At the moment, it's a bit hit or miss. I have zero knowledge in coding, I made this script based on trial and error.

Any help would be appreciated. Thank you. :thumbup:

Re: Autofire and toggle

Posted: 15 Jan 2016, 16:02
by vasili111
tidbit wrote:[Not really sure if this should be in the Tutorial section]

Here are 2 of the most commonly asked things (like, 5+ times a day).
In that case maybe it is better to make this sticky at Ask for help (Gaming)?

Re: Autofire and toggle

Posted: 15 Jan 2016, 16:19
by tidbit
Not many people read stickies, and a lot of people don't even post in the Gaming section. doubt they''d ever find it. But also Toggle is pretty common outside of games (though, the main focus of this thread is toward gamers). I'll leave it as-is. if another staffer feels like moving it, pinning it, whatevering it, they may do so.

Re: Autofire and toggle

Posted: 17 Jan 2016, 14:01
by evilC
I know it's a little OT for this thread, but if I can get UCR working as intended, hopefully the stock answer for "how do i do a toggle" type questions will be "Use UCR".
It seems to me that the majority of the people trying to do this kind of thing anyway aren't really interested in learning AHK, they just want the end result.
Any thoughts on what proportion of these kinds of queries could be solved by a GUI-driven, plugin-based remapping application?
Any thoughts on what plugins I would need (Beyond obviously the plugin that handles Key A --> Key B, with toggle) to be able to satisfy the requirements of most of the posters this is aimed at?

Re: Autofire and toggle

Posted: 17 Jan 2016, 15:57
by tidbit
evilC wrote:I know it's a little OT for this thread, but if I can get UCR working as intended, hopefully the stock answer for "how do i do a toggle" type questions will be "Use UCR".
It seems to me that the majority of the people trying to do this kind of thing anyway aren't really interested in learning AHK, they just want the end result.
Any thoughts on what proportion of these kinds of queries could be solved by a GUI-driven, plugin-based remapping application?
Any thoughts on what plugins I would need (Beyond obviously the plugin that handles Key A --> Key B, with toggle) to be able to satisfy the requirements of most of the posters this is aimed at?
"the majority of the people trying to do this kind of thing anyway aren't really interested in learning AHK"
... "I'm not here to explain them as you probably don't care" :D

But yes, a GUI program for key/toggle/spam/whatever stuff IMO would be ideal. thought about making one myself just to /try/ and reduce the amount of these questions, but meh. And it seems you've already started.
As for how many questions it would solve, no idea. It'd solve a lot of them, but prevent only a few (people don't search). Also ahk doesn't work in all games, so probably wouldn't solve people with stubborn games.
What plugins... toggle, remapping, rapidfire, skill chains (f1, wait 3sec, f5, wait, f4, f3, ...), background windows, maybe color/image detection, and options to set the send/simulation mode, since sometimes send works, not sendplay, etc. but give them a generic name like "mode1" "mode2" because who cares about techno babbly when you "just want it to work".

Re: Autofire and toggle

Posted: 01 Mar 2016, 22:56
by Hannik
I read this and wonder how to convert for what I want to do..but basicly I want to be able to press a button to toggle a script to run that presses one button every 24 seconds and another button every 15 secs but be able to toggle it off when not needed...and am just getting confused by it all..

Hannik

Re: Autofire and toggle

Posted: 02 Mar 2016, 15:05
by evilC
Hannik - You are probably best with a variation on technique #2, but using timers instead of a loop:

Code: Select all

macro_on := 0

F12::
	macro_on := !macro_on
	if (macro_on){
		SetTimer, HitA, 24000
		SetTimer, HitB, 15000
		Gosub, HitA
		Gosub, HitB
	} else {
		SetTimer, HitA, Off
		SetTimer, HitB, Off
	}
	return
	
HitA:
	Send a
	return

HitB:
	Send b
	return

Re: Autofire and toggle

Posted: 03 Mar 2016, 01:38
by joedf
Very nice ;)

Re: Autofire and toggle

Posted: 03 Mar 2016, 02:23
by Hannik
Thanks for all your help but I seem to have the same problem with this one that had with others..I press the button to stop it..and it just keeps going..so its not toggling off...no idea why.

Hannik

Re: Autofire and toggle

Posted: 03 Mar 2016, 06:06
by evilC
oops, typo.

macro_on := !macro on should read macro_on := !macro_on

I corrected my original code

Re: Autofire and toggle

Posted: 03 Mar 2016, 07:10
by Hannik
Thanks so much..that worked..

Hannik

Re: Autofire and toggle

Posted: 09 Mar 2016, 12:08
by Stain Blapelton
Hello. I see the code "If (GetKeyState("LButton","P"))" just about everywhere when looking up rapid-fire scripts, but nobody ever explains what it means. Does the comma between quoted inputs "LButton" and "P" mean "or" or "and"? Where did the "P" come into your script, anyhow? What would this expression look like if it just checked whether, say, the "z" key is currently pressed?

Re: Autofire and toggle

Posted: 09 Mar 2016, 14:52
by evilC
Because the AHK documentation very clearly says what P does.
https://autohotkey.com/docs/commands/GetKeyState.htm

It makes GetKeyState differentiate between the Physical state of the keyboard and the Logical state.

Re: Autofire and toggle

Posted: 07 May 2016, 16:22
by Geff T
many thanks for this , example #2 saved the few last grabs of my hair remaining .
i am in the ''gamer wants end result'' demiographic . this was my first go at programming , so it wasnt just that i never knew my if from my gosub , i never knew the diff between AHK and C (and still dont).
i got to the point where i had almot done it without posting for help . i had '' while banana = 1 '' fine . the key issue was that i never had the '' #maxThreadsPerHotkey, 2 '' and was unlikely to find it with a search .

whilst writing another mort apt language for the likes of me is a good idea , it wont stop peeps coming here to ask ''how do i get this AHK to accept a button when i press it , i meen them f keys'' and similar
for the simple fact , when digging a hole , if you have no spade a shovel will do , if you dont know what either is youll stay using your hands or find a sharpened stick .

Re: Autofire and toggle

Posted: 09 May 2016, 02:33
by BanarMar
Guys pls help me,
#maxThreadsPerHotkey, 2
setKeyDelay, 50, 50
setMouseDelay, 50
banana:=0

$f1::
; banana:=!banana .... This assigns banana to the value of NOT (!) banana. so lets
; say banana starts out FALSE (0). you then turn banana to NOT FALSE. which is
; TRUE (1). so now banana is set to TRUE. and then lets say you toggle it again.
; you set banana to NOT TRUE, which is FALSE. banana is now set to FALSE.
; .... 1 is true, 0 is false. ! is NOT.
banana:=!banana

while (banana=1)
{
send, hello{space}
sleep, 100
}
return

I want a press f2 to toggle and loop x pls!

Re: Autofire and toggle

Posted: 09 May 2016, 06:57
by Geff T
BanarMar wrote:Guys pls help me,
#maxThreadsPerHotkey, 2
setKeyDelay, 50, 50
setMouseDelay, 50
banana:=0

$f1::
; banana:=!banana .... This assigns banana to the value of NOT (!) banana. so lets
; say banana starts out FALSE (0). you then turn banana to NOT FALSE. which is
; TRUE (1). so now banana is set to TRUE. and then lets say you toggle it again.
; you set banana to NOT TRUE, which is FALSE. banana is now set to FALSE.
; .... 1 is true, 0 is false. ! is NOT.
banana:=!banana

while (banana=1)
{
send, hello{space}
sleep, 100
}
return

I want a press f2 to toggle and loop x pls!
change the hotkey FROM $f1:: TO your required F2::
and try reading the help that came with AHK , the search in it is very useful

Re: Autofire and toggle

Posted: 09 May 2016, 09:24
by tidbit
Welcome to ahk, Geff T :)