AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help stop script when 1 key is pressed, start it with anothe

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Michael4eveR
Guest





PostPosted: Sat Dec 26, 2009 10:25 pm    Post subject: Help stop script when 1 key is pressed, start it with anothe Reply with quote

Im trying to shoot a pistol quite fast on BF:2142
- BUT ONLY PISTOL -
So i thought, ok, ill make LButton exacute loads of clicks when its held down, but only after the "2" key has been pressed (i.e. when i got my pistol out) when i change weopon, by pressing 1,3,4,5,6,7 etc it puts the LButton function back to the norm. (pressing 2 again will start te rapid clickin again Wink )

Laughing right, this is what if done, it fails Razz , could someone plz call out "fool!" and show me what i should 'av done - Cheers me Lads 'n' Lassies

Code:

closing:
~1::Suspend, On
~2::
Suspend, Off
Loop
{
    KeyWait, LButton,D
    if ErrorLevel = 1
   Continue
    Gosub, shoot
KeyWait, 1,D
if ErrorLevel = 1
Return
}

shoot:
click DOWN
sleep 32
click UP
sleep 32
click DOWN
sleep 32
click UP
sleep 34
click DOWN
sleep 32
click UP
sleep 36
click DOWN
sleep 32
click UP
sleep 34
click DOWN
sleep 32
click UP
sleep 30
click DOWN
sleep 32
click UP
sleep 40
click DOWN
sleep 32
click UP
sleep 27
Gosub, closing
Back to top
Micahs



Joined: 01 Dec 2006
Posts: 460

PostPosted: Sun Dec 27, 2009 1:23 am    Post subject: Reply with quote

This might be along the lines you are looking for. Keep in mind that the original click will be 'bang' number one and the others will be 2-11 (if you use 10 shots.) You can customize each key (1-0 or any others, for that matter) to have any number of extra shots rapidfire per mouse click, depending on the selected weapon. Any not specified will default to 0 extra shots. Just modify the 'chooser' if/then stuff. To add keys, change the 'keyList' var.

If it will not work for your game, you might look into various methods to have AHK work better in games. Just search for it on the forum. 'SendPlay' would be one thing to look for. HTH.

Code:
#SingleInstance, Force
rapidFire=0
keyList = 1,2,3,4,5,6,7,8,9,0
Loop, Parse, keyList, CSV
{   Hotkey, ~%A_LoopField%, chooser, On
}
Return

chooser:
   weapon := RegExReplace(A_ThisHotkey, "~|$|^|\*|!|#")   ;remove any modifiers (in this case, just the '~')
   If(weapon = "2")   ;pistol
   {   rapidFire=10   ;how many times to fire
   }
   Else If(weapon = "3")   ;spitwad (or whatever)
   {   rapidFire = 2   ;how many times to fire
   }
   Else   ;you could add stuff for other keys, too
   {   rapidFire=0   ;turn it off
   }
Return

~$LButton Up::
   Sleep, 25
   Loop, % RapidFire   ;however many shots per click
   {   Random, delay, 30, 50   ;rnd delay between 25ms and 50ms
      Click, Down
      Sleep, %delay%
      Click, Up
      Sleep, % delay+25   ;add an extra delay between clicks
      ;OutputDebug, Bang!   ;just for testing
   }
Return

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group