Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Auto fire Tutorial


  • Please log in to reply
55 replies to this topic
x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
Tags = Auto Clicker Auto Fire Auto press Auto Spam Auto type hold down button Automatically spam Autospam Turbo Turbofire Turbokey keys Spamkey click buttons repeatedly hold down key

This tutorial shows you how to create scripts which will allow you to autoclick,
auto fire and other things


You should know some basic facts, You can read the official tutorial
<!-- m -->http://www.autohotke...cs/Tutorial.htm<!-- m -->

Or you can read my brief page on 5 things you need to know before you get started
<!-- m -->http://www.autohotke... ... ng_started<!-- m -->


-What is Rapidfire?
Rapidfire is where you hold a button down and that button will then be pressed multiple times quickly. It is needed for games Alot.



this is how a normal autofire script may look

Note that Lbutton means Left mouse click

~$*LButton::::     ;This makes the hotkey, so Lbutton triggers the script
Loop                 ;loop the script untill broken
{ ;loop start
    GetKeyState, var, LButton, P ;Get the state of Lbutton
    If var = U                            ;has it been released?
        Break       ;its been released so break the loop
    Send {LButton}  ;It hasnt been released so send another Click
    sleep 20  ; This is the time between presses, after its slept it will return to the top of the loop and start again
} ;loop end

To change the hotkey (start button) change both the two words highlighted in red

~$*[color=red]Lbutton[/color]::
Loop                
{
    GetKeyState, var, [color=red]LButton[/color], P
    If var = U
        Break
    Send {LButton}
    sleep 20
} 

So, for example changed to the f key

~$*[color=red]F[/color]::
Loop                
{
    GetKeyState, var, [color=red]F[/color], P
    If var = U
        Break
    Send {LButton}
    sleep 20
} 

To change the time between presses, you need to change the sleeping time.

so

Sleep 10 = 0.01 seconds
Sleep 100 = Sleep 0.1 seconds
Sleep 1000 = Sleep 1 second
Sleep 675 = Sleep 0.675 seconds

-example of changing the sleep time

~$*LButton::
Loop                
{
    GetKeyState, var, LButton, P
    If var = U
        Break
    Send {LButton}
   [color=red] sleep 200[/color]  ;Sleep 0.2 seconds
} 

That concludes part one





Advanced features

I use some specail options here, you can read about them at these links

<!-- m -->http://www.autohotke..._NoTrayIcon.htm<!-- m -->
<!-- m -->http://www.autohotke... ... chMode.htm<!-- m -->
<!-- m -->http://www.autohotke... ... Active.htm<!-- m -->
<!-- m -->http://www.autohotke..._Persistent.htm<!-- m -->
<!-- m -->http://www.autohotke...SetKeyDelay.htm<!-- m -->

or, you can use my compact guide which gives a brief explanation of what it does
<!-- m -->http://www.autohotke... ... pt_Options<!-- m -->

I highlighted everything in red that you can change, dont be afraid to change them


#Persistent
SetTitlematchmode, 2
SetKeyDelay, [color=red]5, 5[/color]

#Ifwinactive, [color=red]Modern Warfare[/color]
~$*[color=red]LButton[/color]::
Loop                
{
    GetKeyState, var, [color=red]LButton[/color], P
    If var = U
        Break
    Send [color=red]{LButton}[/color]
    sleep [color=red]200[/color]  ;Sleep 0.2 seconds
} 
#Ifwinactive ;end 
;do nothing, so the hotkey above this wont work outside of modern warfare


x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
Part three: Toggles

I made a brief little explanation of toggles, I hope you find this useful
<!-- m -->http://www.autohotke...hp?title=Toggle<!-- m -->


Okay so here is a script with a toggle. A toggle means
-First press it will turn on
-Second press it will tun off
-Third press it will turn on
-and so on


F1::Toggle := Toggle ? 0 : 1 ;when you press f1, change the toggle

~$*LButton::
[color=darkred]If Toggle = 1[/color]
[color=green]Loop {
GetKeyState, LButtonState, LButton, P
If LButtonState = D
Send Click
return
}[/color]
[color=blue]Else
return[/color]

F1 will turn the script on and off, and if its on, LButton will make the rapidfire


Fully working autofire script


;SCRIPT SETTINGS

   #SingleInstance force
   SetTitleMatchMode, 2
   six = 0


;VARIABLES

   V_RapidFire = 0
   V_Running = 0

;SCRIPT MANAGEMENT
#ifwinactive, Modern Warfare 2
;RAPID FIRE MODE

   Numpad1::
   NumpadEnd::
   V_RapidFire = 0
   Return

   Numpad2::
   NumpadDown::
   V_RapidFire = 1
   Return

   Numpad3::
   NumpadPgDn::
   V_RapidFire = 2
   Return

   NumpadSub::
               six := six - 1
   return

   NumpadAdd::
   six := six + 1
   return



;RAPID FIRE
;---------------------------------------
   ~$*LButton::
   If V_RapidFire = 1
{
   Loop
 {
    GetKeyState, LButton, LButton, P
    If LButton = U
        Break
    MouseClick, Left,,, 1
    Gosub, RandomSleep
    Mousemove, 0, %six%,, R
 }
}
return
       


;----------------------------------------


   ~$*RButton::
   If V_RapidFire = 2
{
   Loop
 {
    GetKeyState, RButton2, RButton, P
    If RButton2 = U
        Break
    Send {RButton}
    Gosub, RandomSleep
 }
}
return

;----------------------------------------


   DualFire:
   Loop
 {
   MouseClick, Left,,, 1
   MouseClick, Right,,, 1
   Gosub, RandomSleep
   GetKeyState, LButtonState, LButton, P
   If LButtonState = U
   Break
   GetKeyState, RButtonState, RButton, P
   If RButtonState = U
   Break
}
   Return

;TACTICAL INSERTION LOOP
;----------------------------------------

   F11::
   Loop
{
   Sleep 500
   ControlSend,, {LButton}{f}, Modern Warfare 2
   Sleep 7500
   ControlSend,, {e}, Modern Warfare 2
   GetKeyState, F11State, F11, T
   If F11State = U
   Break
}
   Return



;---------------------------------------

RandomSleep:
Random, random, 12, 25
Sleep %random%
return


Numpad5::Msgbox, %six%


fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

Grass = green

If Grass = green

 Send The Grass is Green

[color=red]else[/color] ; missing!

  Send The Grass isnt Green :(



x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
thanks for that spot

tomoe_uehara
  • Members
  • 2166 posts
  • Last active: Jun 11 2015 05:33 PM
  • Joined: 05 Sep 2009
#Ifwinactive, Modern Warfare 
~&*Lbutton:: 
Loop                
{ 
    GetKeyState, Lbvar, LButton, P 
    If Lbvar = U 
        Break 
    Send {LButton} 
    sleep 200  ;Sleep 0.2 seconds 
} 
#Ifwinnotactive, Modern Warfare
; I thought the code must lies within 2 #IfWinActive 's
; Which one is right, #1 or #2?

;#1
#IfWinActive, Opera
a::Msgbox Hello
#IfWinActive

;#2
#IfWinActive, Opera
a::Msgbox Hello
#IfWinNotActive


x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010

#IfWinActive, Opera
a::Msgbox Hello
#IfWinNotActive


#IfWinActive, Opera
a::Msgbox Hello
#IfWinNotActive, Opera


If opera isnt active. clearly it makes sense

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009

To turn off context sensitivity, specify any #IfWin directive but omit all of its parameters.

Does not matter which one you use.

tomoe_uehara
  • Members
  • 2166 posts
  • Last active: Jun 11 2015 05:33 PM
  • Joined: 05 Sep 2009
Ah too bad ahk can't simulate Joystick keypress, although there's PPJoy, but it's not easy to use it :(

x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
bump
:roll:

  • Guests
  • Last active:
  • Joined: --
Hello guys,

Thanks very much for such detailed tutorial, was looking for it a long time.

I have a question. Can you please suggest a code where a button can be always pressed by its own, so I do not need to press the button to have autofire.
For example, I need the "A" button to be always pressed by itself and producing autofire at the same time. I tried to make changes by my own, but it still doesn't work.

Thanks.

x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010

I need the "A" button to be always pressed by itself and producing autofire at the same time. I tried to make changes by my own, but it still doesn't work

.

Im sorry i dont understand your question, are you asking to make A spam left click but also send an A aswell?

~$*A::::
Loop
{
    GetKeyState, Lbvar,A, P
    If Lbvar = U
        Break
    Send {LButton}
    sleep 20
}

try that and tell me if its what you wanted

OceanMachine
  • Members
  • 790 posts
  • Last active: Aug 23 2013 02:10 PM
  • Joined: 15 Oct 2007
I think Guest was trying to get a sort of "toggled" autofire?

Something like the below will do that - press F1 once and the script will start sending A every 20ms. Press F1 again to stop it.

The point here is that you don't need to hold any key down to autofire it.

F1:: ; change F1 to be a different key to turn the autofire on or off
    ToggleSpam := ToggleSpam ? 0 : 1
    If ( ToggleSpam )
        SetTimer, SpamLoop, 20 ; spam the key every 20ms (increase to slow it down)
    Else
        SetTimer, SpamLoop, Off
Return

Esc::ExitApp

SpamLoop:
    SendInput, A ; Change A to be the key you want to send
Return



Also, just a couple of points about your "toggles" section:
1) It is very confusing to me (never mind new users) as to what you mean, due to the wording used in this section. e.g.: " Variables are pieces of data that are always active when made" -- this sentence doesn't make sense to me. Neither does "Toggle is my variable, and toggle = 0, but 0 does not mean toggle"
2) "#Persistent ;There is no return if the statement is true, so this must be here to stop the script closing" - this is not true, as any hotkey in a script will make it automatically persistent (as well as any GUI item, hotstring, or OnMessage will also make a script persistent)
3) You also missed an "Else" in your second example in that section:
#Persistent ;There is no return if the statement is true, so this must be here to stop the script closing
F1::
If [color=red]([/color] Toggle = 0 [color=red])[/color] ; it's a good habit to always have brackets around the expression in If statements IMO
    Toggle = 1        ;Set the state to 1 (on)
[color=red]Else ; you need this Else here, otherwise Toggle will always end up being 0[/color]
   Toggle = 0
return

It is easier to use ternary operators for toggles - I realise it looks a bit strange to a new coder, but the whole of the above code could be replaced with the following (i.e. there is also no need for a Return, or a #Persistent)

F1::Toggle := Toggle ? 0 : 1


Nice job on the tutorial though, this is something that gets asked by lots of people, so well done for creating a beginners guide!

x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
Ocean thanks for your post, ill be honest to say i wrote it rather quickly, but ill have a look at what you said and try to improve it

F1::Toggle := Toggle ? 0 : 1

Also, its funny you mentioned that because i only found out about it yesterday

tomoe_uehara
  • Members
  • 2166 posts
  • Last active: Jun 11 2015 05:33 PM
  • Joined: 05 Sep 2009
I think this topic should be made sticky Posted Image
(or redirected to the wiki)

Because autofire & toggle is one of the most popular question
:lol:

x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
Its not in a good condition at the moment to be stickied, but if people can re-write parts of this tutorial i would be happy to replace what i already have