Auto Fire - can't make key firing without pressing

Ask gaming related questions (AHK v1.1 and older)
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Auto Fire - can't make key firing without pressing

15 Jun 2017, 03:01

I have a question about rapid fire on the keyboard.
Here is my script:

Code: Select all


~$*W:: 
Loop
{ 
GetKeyState, var, W, P 
If var = U 
Break 
Send {W} 
sleep 100
}
I need to make that the W key is hold down for 2 seconds than released for 3 seconds, then again hold down for 2 seconds and released for 3 seconds and so on. That is I don't touch the W key on the keyboard, it is pressing by itself.

I tried different commands, have read the Auto fire Tutorial and many other messages, but still confused how to make such a script, Most scripts a written when the user is pressing the key and I can't find an example when the key is not touched.

Can someone please give me an example how the script should look like.

Thank you!
Last edited by vosined on 15 Jun 2017, 08:07, edited 1 time in total.
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 03:06

P. S. Sorry this is my first messages, should write it in the Games topic.
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 07:33

I am trying to use something like this:

Code: Select all

W::
    while GetKeyState("W", "P"){
        Sendinput, {W Down}
        Sleep, 2000
        SendInput, {W Up}
    }
return
But it is not working...
Help please!
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 07:40

Currently your script releases W and presses it again instantly.
Add a Sleep 3000 command at the end of the loop:

Code: Select all

W::
    while GetKeyState("W", "P"){
        Sendinput, {W Down}
        Sleep, 2000
        SendInput, {W Up}
        Sleep, 3000
    }
return
Hope this helps.

EDIT:
And you want it to toggle so you have your hands free for other stuff?

Code: Select all

#MaxThreadsPerHotkey 2
w::
        If ToggleVar
        {
                ToggleVar := 0
                Return
        }
        
        ToggleVar := 1
        While ToggleVar {
        Sendinput, {w Down}
        Sleep, 2000
        SendInput, {w Up}
        Sleep, 3000
        }
return
#MaxThreadsPerHotkey 1
I did not test it but I wrote this yesterday and it worked. I might have missed some spelling mistakes.
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 07:50

Thanks for the reply, but when trying to run the script it says

Error at line 2
Line text while GetKeyState(W, P)
Error: This line does not contain a recognized action

I copied the script that you've posted, compiled it and ran as administrator. Other simple scripts with rapid fire that I posted in first message are running ok. Can you check please for an error? Thanks.

And the second script can't even compile, it says Error opening the destination file.
Sorry I am new to this staff and a little confused, even though I've tried many things and read a lot of topics.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 08:06

The first one is working on my pc. I'm looking into the second one now.

The second one was triggering itself. Fixed this by adding $ in the hotkey.

Code: Select all

#MaxThreadsPerHotkey 2
$w::
        If ToggleVar
        {
                ToggleVar := 0
                Return
        }
        
        ToggleVar := 1
        While ToggleVar {
        Sendinput, {w Down}
        Sleep, 2000
        SendInput, {w Up}
        Sleep, 3000
        }
return
#MaxThreadsPerHotkey 1
Last edited by DyaTactic on 15 Jun 2017, 08:14, edited 1 time in total.
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 08:09

Yes you are right. I need not to touch the W key on the keyboard, it is pressing by itself. I need to make that the W key is hold down for 2 seconds than released for 3 seconds and so on.

Don't know what is wrong, I'll try to experiment with the script. Other script that I copy from the forum are working fine without errors.
That is the code I am trying to run and it gives the error:

Code: Select all

W::
    while GetKeyState("W", "P"){
        Sendinput, {W Down}
        Sleep, 2000
        SendInput, {W Up}
        Sleep, 3000
    }
return
May be need to update my autohotkey.exe ...
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 08:19

Try to add the $ before the W here too. Maybe that helps. Also, why are you using Uppercase W's in the SEND command. Autohotkey now sends a Shift + W command if I'm not mistaking.

Code: Select all

$w::
    while GetKeyState("w", "P"){
        Sendinput, {w Down}
        Sleep, 2000
        SendInput, {w Up}
        Sleep, 3000
    }
return
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 08:38

I have tried but still gives an error when Running as Administrator, but compiling is fine.
For example if I put simple script like down below is running without errors:

Code: Select all

~$*w::                    
Loop
{ 
    GetKeyState, var, w, P 
    If var = U                            
        Break       
    Send {w}  
    sleep 2000
}
Actually the only thing I need to this script is just to make W key pressing 2 seconds by itself then released by itself for 3 seconds. Maybe there is a way to add to this simple script above so it would work the way I need.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 08:47

Well, if the other one does not like you...^-^ That is also good possible:

Code: Select all

~$*w::                    
Loop
{ 
    GetKeyState, var, w, P 
    If var = U                            
        Break       
    Send {w Down}
    sleep 2000
    Send {w Up}
    sleep 3000
}
Hope this works then
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 09:03

I have updated autohotkey and now the scripts are running, the long one you've posted is working:

Code: Select all

#MaxThreadsPerHotkey 2
$w::
        If ToggleVar
        {
                ToggleVar := 0
                Return
        }
        
        ToggleVar := 1
        While ToggleVar {
        Sendinput, {w Down}
        Sleep, 2000
        SendInput, {w Up}
        Sleep, 3000
        }
return
#MaxThreadsPerHotkey 1
Sorry for my mistake with update. I might ask one more thing later on.
Thanks a lot. Really appreciate it!
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 09:19

DyaTactic one more script I want to ask to help you with. I need to add to the script one more button - "A". When the W key is held up for 3 seconds, at this time the A key is held down for 3 seconds, then when W key is held down for 2 seconds, the same time A key is held up for 2 seconds and so on.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Auto Fire - can't make key firing without pressing

15 Jun 2017, 10:59

You want that in the current hotkey or should it be a different hotkey so you can activate the two versions separately?
This one in integrated in the previous hotkey. You can just copy-paste it in the script and change the hotkey to receive my sugestion above.

Code: Select all

#MaxThreadsPerHotkey 2
$w::
        If ToggleVar
        {
                ToggleVar := 0
                Return
        }
        
        ToggleVar := 1
        While ToggleVar {
        If A_Index <> 1        ; Prevent the {a Up} event when starting the loop, only at the fist cycle.
                SendInput, {a Up}
        Sendinput, {w Down}
        Sleep, 2000
        SendInput, {w Up}
        SendInput, {a Down}
        Sleep, 3000
        }
return
#MaxThreadsPerHotkey 1
I'd love to help with more scripting.
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

16 Jun 2017, 02:05

Yes, that is what I needed in one script!
Thanks a lot!
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Auto Fire - can't make key firing without pressing

29 Jun 2017, 06:42

I need to add to my scripts below a toggle on/off. I want the script to be "on" when I press "3" key and to be "off" when I press "4" in first script and "5" is on, "6" is off for the second script. Now it is only starting to work when I press "a" and "j" and doesn't have any toggle off.
Hi Vosined. I understand that the toggle function is not working properly. The script I wrote before allows to toggle with only one button. You want to use two buttons, the first is on and the second is off.

I rewrote the script with one toggle button to work a bit different. Now the script below should be more reliable.

Code: Select all

$a::
	If ToggleVar
	{
		ToggleVar := 0
		Return
	}
	
	ToggleVar := 1
	SetTimer, LoopAButton, -1	; Start a new thread which runs the loop under "LoopAButton:".
Return

LoopAButton:	
	While ToggleVar {
		SendInput, {a Down}
		Sleep, 30000000
	}
	Return

$j::
	If ToggleVar2
	{
		ToggleVar2 := 0
		Return
	}
	
	ToggleVar2 := 1
	SetTimer, SpamJ, -1	; Start a new thread which runs the loop under "LoopAButton:".
	return
	
SpamJ:
	While ToggleVar2 {
		Sendinput, {j Up}
		Sleep, 100
		SendInput, {j Down}
		Sleep, 100
	}
	Return
Though you asked to use separate buttons for off and on. This script should provide that.

Code: Select all


3::
	ToggleVar := 1
	While ToggleVar {
		SendInput, {a Down}
		Sleep, 30000000
	}
return

4::
	ToggleVar := 0
	Return

5::
	ToggleVar2 := 1
	While ToggleVar2 {
		Sendinput, {j Up}
		Sleep, 100
		SendInput, {j Down}
		Sleep, 100
	}
return

6::
	ToggleVar2 := 0
	Return
Both scripts do not run the two While-loops together. So when J is being spammed, A cannot be send and vice versa. If this is realy necessary it is possible.
vosined
Posts: 32
Joined: 15 Jun 2017, 02:48

Re: Auto Fire - can't make key firing without pressing

02 Jul 2017, 03:15

Yes the last script that is what I needed! Thank you. The only thing left is that when I Press 4 and 6 to Toggle Off the script, it would not Toggle off until I press "a" and "j" buttons. But it would be better if pressing 4 and 6 will Toggle Off without pressing "a" and "j".
I am trying to make one Toggle on/off for three buttons "a", "e" and "j", but it is not working correctly. Can you please correct the script.

Code: Select all

3::
	ToggleVar := 1
	While ToggleVar {
		SendInput, {a Down}
		Sleep, 30000000
	}
return
	ToggleVar := 1
	While ToggleVar {
		SendInput, {e Down}
		Sleep, 30000000
	}
return
	ToggleVar2 := 1
	While ToggleVar2 {
		Sendinput, {j Up}
		Sleep, 100
		SendInput, {j Down}
		Sleep, 100
	}

return
4::
	ToggleVar := 0
	Return
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Auto Fire - can't make key firing without pressing

02 Jul 2017, 13:09

The script can only run one loop at once. So if you want to have a, e, and j be pressing altogether you have to put it in a single (While)loop.
That bug you said is probably caused by the fact that the last Send command in the loop is {j Down}. This way the game thinks that the key is still pressed down. I'll fix it in this script.
The Return command stops the hotkey from executing commands so you can place multiple hotkeys in one script. Due to this Return command the {e Down} and {j Down/Up} are never executed in your script.

This is the script you asked for. Adjust the Seep times to your wishes and you can also change the order of {a Down} and {e Down} and {j Up} etc. Now it is sleeping 2 times 3000000 ms, you might want to change that.

Code: Select all

3::
	ToggleVar := 1
	While ToggleVar {
		SendInput, {a Down}
		Sleep, 30000000
		SendInput, {a Up}
		
		Sleep, 40
		
		SendInput, {e Down}
		Sleep, 30000000
		SendInput, {e Up}
		
		Sleep, 100

		SendInput, {j Down}
		Sleep, 100
		SendInput, {j Up}
		Sleep, 100
	}
Return

4::
	ToggleVar := 0
	Return
Let me know if you have more questions.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 88 guests