Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Fire Control is a plugin that allows you to configure rapid fire etc
- */
- ; All plugins must derive from the _Plugin class
- class FireControl extends _Plugin {
- Type := "Fire Control"
- Description := "A Rapid Fire macro."
- FireSequence := [] ; The sequence of keys to hit
- SeqPos := 0 ; The current position in the sequence
- SeqMax := 0 ; The number of items in the sequence
- FireRate := 0 ; The rate at which to fire
- FireState := 0 ; The state of the fire button
- ; The Init() method of a plugin is called when one is added. Use it to create your Gui etc
- Init(){
- ; Create the GUI
- Gui, Add, Text, y+10, % "Fire Button: "
- ; Add a hotkey, and give it the name "FireButton". All hotkey objects can be accessed via this.InputButtons[name]
- ; Have it call FireButtonChangedState when it changes state.
- this.AddInputButton("FireButton", 0, this.FireButtonChangedState.Bind(this), "x100 yp-2 w200")
- ; Set up the Fire Sequence and Fire Rate boxes
- Gui, Add, Text, xm, % "Fire Sequence: "
- this.AddControl("FireSequence", this.FireSequenceChangedValue.Bind(this), "Edit", "x100 yp-3 w300", "")
- Gui, Add, Text, x+10 yp+3, % "Fire Rate: "
- this.AddControl("FireRate", this.FireRateChangedValue.Bind(this), "Edit", "x+10 yp-3 w50", "")
- ; Store a pointer to the fire function
- this.FireFunc := this.Fire.Bind(this)
- }
- ; Called when the hotkey changes state (key is pressed or released)
- FireButtonChangedState(e){
- this.FireState := e ; If set to 0, main loop in Fire() will end
- if (e && this.FireRate && this.SeqMax){
- ; Fire Key went down and we seem to have a valid Fire Seqence. FIRE WEAPONS!!!
- ; We must allow this function to "End", so that other inputs continue to work...
- ; ... So do the main Fire loop in another "Thread" by using SetTimer
- fn := this.FireFunc ; Get the pre-built pointer to the fire function
- SetTimer, % fn, -0 ; -0 means "Fire this straight after this function ends, and only once"
- }
- }
- ; Runs while the fire button is held
- Fire(){
- while (this.FireState){ ; this.FireState will get set to 0 in FireButtonChangedState() when the button is released
- SetKeyDelay, 0, 50 ; Keys need to be held for 50ms to work with some games (eg MWO). Cheap bodge to keep code simple.
- try { ; We did not validate the Fire Sequence, so use a "try" block in case it contains invalid key names.
- Send % "{Blind}" this.FireSequence[this.SeqPos] ; Use {blind} to stop ahk releasing modifiers (Ctrl, Alt etc) if they are held.
- }
- this.SeqPos++ ; Move to the next item in the sequence
- if (this.SeqPos > this.SeqMax)
- this.SeqPos := 1 ; Wrap around at the end
- Sleep % this.FireRate ; Sleep until next shot
- }
- }
- ; The user changed the contents of the Fire Rate box
- FireRateChangedValue(rate){
- if (rate is Number) {
- this.FireRate := rate
- } else {
- this.FireRate := 0
- }
- }
- ; The user changed the contents of the Fire Sequence box
- ; Called as each letter is typed, so may be invalid until user finishes typing
- FireSequenceChangedValue(fire_sequence){
- ; Split the sequence on commas
- fire_sequence := StrSplit(fire_sequence, ",")
- ; Did we get an array of at least one item back?
- if (fire_sequence.length()){
- ; Yes - set fire sequence
- this.FireSequence := fire_sequence
- this.SeqPos := 1
- this.SeqMax := this.FireSequence.length()
- } else {
- ; No - disable fire sequence
- this.FireSequence := []
- this.SeqPos := 0
- this.SeqMax := 0
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement