Simple keywait + rapidfire

Ask gaming related questions
changlish76
Posts: 12
Joined: 21 Dec 2018, 05:31

Simple keywait + rapidfire

12 May 2024, 04:11

I've used ahk over the years to save myself from injury, but I am by no means an expert especially with v2. Right now I'm using this script in a game to spam LMB after holding the button down for a short time. I'm not sure if it is optimal (cpu usage/bugs etc) but it seems to work. Can anyone tell me how this would be re-written for the same purpose but with spacebar instead of LMB?

Code: Select all

#Requires AutoHotkey v2.0
AutoClickEnabled := False

F1:: {
    Global AutoClickEnabled := !AutoClickEnabled
    SoundBeep 380 + 320 * AutoClickEnabled
}

#HotIf AutoClickEnabled

~*LButton::
{
    if !KeyWait("LButton", "T.2") 
        Clicker()                
    KeyWait("LButton")           
    SetTimer(Clicker, 0)         

    Clicker() {
        SendEvent("{Click}")     
        SetTimer(Clicker, -10)   
    }
}

#HotIf

+Esc::ExitApp

[Mod action: Moved topic to the “Gaming” section.]
User avatar
boiler
Posts: 17211
Joined: 21 Dec 2014, 02:44

Re: Simple keywait + rapidfire

12 May 2024, 04:54

Code: Select all

#Requires AutoHotkey v2.0
AutoClickEnabled := False

F1:: {
    Global AutoClickEnabled := !AutoClickEnabled
    SoundBeep 380 + 320 * AutoClickEnabled
}

#HotIf AutoClickEnabled

~*$Space::
{
    if !KeyWait("Space", "T.2") 
        Clicker()                
    KeyWait("Space")           
    SetTimer(Clicker, 0)         

    Clicker() {
        SendEvent(" ")     
        SetTimer(Clicker, -10)   
    }
}

#HotIf

+Esc::ExitApp
changlish76
Posts: 12
Joined: 21 Dec 2018, 05:31

Re: Simple keywait + rapidfire

12 May 2024, 05:39

I'm sorry I should have been more clear, I'd like to hold space and have it repeatedly press space not click. But this does look handy for something else :)
User avatar
boiler
Posts: 17211
Joined: 21 Dec 2014, 02:44

Re: Simple keywait + rapidfire

12 May 2024, 07:11

:?: What make you think it clicks? Did you even run it?

If you think it’s because the function is still named Clicker, that has nothing to do with what it does.
changlish76
Posts: 12
Joined: 21 Dec 2018, 05:31

Re: Simple keywait + rapidfire

12 May 2024, 17:25

Works great ty! Had no idea it was this simple, thought clicker was mouse only
User avatar
boiler
Posts: 17211
Joined: 21 Dec 2014, 02:44

Re: Simple keywait + rapidfire

12 May 2024, 19:19

Again, the name “Clicker” has nothing to do with what it does. It’s not an AHK function name. It was just what was chosen for the name of this user-defined function. It’s the code inside it that defines what happens, not the name of it. Replace everywhere you see “Clicker” with “Bob” or “Tomato” and it will work exactly the same.
changlish76
Posts: 12
Joined: 21 Dec 2018, 05:31

Re: Simple keywait + rapidfire

12 May 2024, 22:00

Well that definitely clears it up! I have a followup question about the original script in my first post. Is it possible to add another toggle that will spam LMB on its own without any input (besides toggling it on)?
User avatar
boiler
Posts: 17211
Joined: 21 Dec 2014, 02:44

Re: Simple keywait + rapidfire

12 May 2024, 22:25

I guess you mean this:

Code: Select all

#Requires AutoHotkey v2.0

F1:: {
    static t := 0
    SoundBeep 380 + 320 * (t := !t)
    SetTimer () => Click(), t ? 50 : 0
}

+Esc::ExitApp
changlish76
Posts: 12
Joined: 21 Dec 2018, 05:31

Re: Simple keywait + rapidfire

13 May 2024, 06:49

Now that I have a better understanding of how the game handles inputs, I'm trying to achieve something different. Basically I'd like to know if this is possible:

F1 = Toggle function 1 on/off
SoundBeep 180 + 120 *
press LButton = normal click
hold LButton over .3s = spam F4 (20ms)

MButton = Toggle function 2 on/off
SoundBeep 180 + 120 *
automatic/repeating F2(10ms), F3(10ms), F2(10ms), F3(10ms)...

+Esc::ExitApp

I'm guessing this is possible and likely all I need, but I run into trouble trying to edit or rearrange these types of scripts. Specifically when trying to swap mouse and keyboard functions. Not sure something like this can be written in a way that allows for clicks and keys to be interchangeable by my own simple editing methods. Thank you for all the help
Last edited by changlish76 on 14 May 2024, 01:20, edited 1 time in total.
User avatar
boiler
Posts: 17211
Joined: 21 Dec 2014, 02:44

Re: Simple keywait + rapidfire

13 May 2024, 07:46

Not sure what you mean by the F1 toggling all functions on/off. Do you mean just to make the hotkeys inactive? Or do you mean if they are in the middle of spamming, you want F1 to stop the spamming as well?
changlish76
Posts: 12
Joined: 21 Dec 2018, 05:31

Re: Simple keywait + rapidfire

13 May 2024, 07:54

It would be convenient if F1 could stop both spam and disable hotkeys just to resume normal use in game or on desktop, but if that is not practical I will make due
User avatar
boiler
Posts: 17211
Joined: 21 Dec 2014, 02:44

Re: Simple keywait + rapidfire

13 May 2024, 11:07

It's possible. I'm not going to take the time to keep iterating this, but maybe someone else will, unless you are going to try to implement the logic yourself.
changlish76
Posts: 12
Joined: 21 Dec 2018, 05:31

Re: Simple keywait + rapidfire

13 May 2024, 17:41

Understandable, this will have to be something I pick away at over time
changlish76
Posts: 12
Joined: 21 Dec 2018, 05:31

Re: Simple keywait + rapidfire

14 May 2024, 05:09

I've cobbled together this script that does most of the things I need. I added {blind} because both toggles were causing my modifiers to rapid fire. Now with {blind} the modifier keys get stuck very quickly and consistently if one is pressed while using either of the 2 functions in this script. Any advice is greatly appreciated

Code: Select all

#Requires AutoHotkey v2.0
RapidFireEnabled := False

F1:: {                                ; F1 to toggle on/off                      
	Global RapidFireEnabled := !RapidFireEnabled
	SoundBeep 220 + 180 * RapidFireEnabled
	; Windows volume mixer >System Sounds >Adjust beep volume
}

#HotIf RapidFireEnabled

~*LButton:: {
	if !KeyWait("LButton", "T.3") ; If held down for X seconds
	RapidFire()                   ; Press and repeat every X ms
	KeyWait("LButton")            ; Wait for key to release
	SetTimer(RapidFire, 0)        ; Turn off timer

	RapidFire() {
	; Event mode must be used else the timer will keep running
	; If key is released and sent at the same time
	SendEvent("{Blind}{Click}")   ; Send using event mode
	SetTimer(Rapidfire, -20)      ; Repeat this timer after X ms
}
}

#HotIf

~*MButton:: {                         ; MidMouse to toggle on/off 
	Static t := 0
	SoundBeep 220 + 180 * (t := !t)
	SetTimer () => SendEvent('{Blind}{F2}{F3}'), t ? 80 : 0
}

+Esc::ExitApp                         ; Shift+Esc to exit AHK

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 8 guests