Autofire and toggle

Put simple Tips and Tricks that are not entire Tutorials in this forum
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Autofire and toggle

17 Dec 2015, 14:33

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
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
pewpew

Re: Autofire and toggle

26 Dec 2015, 16:59

best bit of the post above
pewpew
:lol: :bravo:
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Autofire and toggle

26 Dec 2015, 21:58

hahah yes, or even
pewpew pew
So much 'pew' hahah :)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
AlexFromTarget
Posts: 1
Joined: 06 Jan 2016, 13:54

Re: Autofire and toggle

06 Jan 2016, 14:08

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:
vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: Autofire and toggle

15 Jan 2016, 16:02

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)?
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Autofire and toggle

15 Jan 2016, 16:19

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.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Autofire and toggle

17 Jan 2016, 14:01

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?
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Autofire and toggle

17 Jan 2016, 15:57

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".
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
Hannik

Re: Autofire and toggle

01 Mar 2016, 22:56

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
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Autofire and toggle

02 Mar 2016, 15:05

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
Last edited by evilC on 03 Mar 2016, 06:16, edited 1 time in total.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Autofire and toggle

03 Mar 2016, 01:38

Very nice ;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Hannik

Re: Autofire and toggle

03 Mar 2016, 02:23

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
Hannik

Re: Autofire and toggle

03 Mar 2016, 07:10

Thanks so much..that worked..

Hannik
Stain Blapelton

Re: Autofire and toggle

09 Mar 2016, 12:08

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?
Geff T
Posts: 6
Joined: 07 May 2016, 15:16

Re: Autofire and toggle

07 May 2016, 16:22

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 .
BanarMar
Posts: 6
Joined: 07 May 2016, 00:51

Re: Autofire and toggle

09 May 2016, 02:33

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!
Geff T
Posts: 6
Joined: 07 May 2016, 15:16

Re: Autofire and toggle

09 May 2016, 06:57

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
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Autofire and toggle

09 May 2016, 09:24

Welcome to ahk, Geff T :)
rawr. fear me.
*poke*
Is it December 21, 2012 yet?

Return to “Tips and Tricks (v1)”

Who is online

Users browsing this forum: No registered users and 22 guests