Help about this particular code

Ask gaming related questions (AHK v1.1 and older)
Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Help about this particular code

Post by Pacifista » 22 May 2023, 10:25

I have this code and it lets me to press "f" key once for every 4 seconds when holding lmb. (I'm shooting when holding lmb)

Now the thing is can someone help me to add another function to this? i just want to add this particular feature like;

After pressing lmb once and hold it the script will activate the f key once like it always did but when i lift my finger and press lmb again it won't activate the script in that 4 seconds

cuz I'm spending one action point to enable the skill for this and its draining my limited ap's so i don't want to press it a few times again for nothing.

The skill is boosting my abilites and the enemy is not present all the time so i need this "don't activate the script in 4 seconds again and again" feature.

Code: Select all

~LButton::
Gosub, Key
SetTimer, Key, 4000
KeyWait, LButton
SetTimer, Key, Off
Return
Key:
Send f
Return

*PAUSE::
Suspend ;Suspend Hotkeys off/on
Pause,, 1 ;Pause Script off/on
Return

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: Help about this particular code

Post by Pacifista » 22 May 2023, 14:24

i tried like 27 variatons on chatgpt.

i just need f button to not to be pressed again for 4 seconds after it's being triggered by lmb.

it's been fruitless 4 hours can anyone help me?

Rohwedder
Posts: 7774
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help about this particular code

Post by Rohwedder » 23 May 2023, 02:02

Hallo,
If with "the script" in
it won't activate the script in that 4 seconds
the subroutine Key is meant:

Code: Select all

~LButton::
if (TLButton < A_TickCount)
{ ; LButton not twice within 4 seconds
	Gosub, Key
	SetTimer, Key, 4000
}
TLButton := A_TickCount + 4000
KeyWait, LButton
SetTimer, Key, Off
Return
Key:
Send f
Return

*PAUSE::
Suspend ;Suspend Hotkeys off/on
Pause,, 1 ;Pause Script off/on
Return

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: Help about this particular code

Post by Pacifista » 23 May 2023, 08:08

Rohwedder wrote:
23 May 2023, 02:02
Hallo,
If with "the script" in
it won't activate the script in that 4 seconds
the subroutine Key is meant:

Code: Select all

~LButton::
if (TLButton < A_TickCount)
{ ; LButton not twice within 4 seconds
	Gosub, Key
	SetTimer, Key, 4000
}
TLButton := A_TickCount + 4000
KeyWait, LButton
SetTimer, Key, Off
Return
Key:
Send f
Return

*PAUSE::
Suspend ;Suspend Hotkeys off/on
Pause,, 1 ;Pause Script off/on
Return
Thx but this didn't work. The original script was running whenever i press lmb and activating the script. if i hold lmb it was repeating as long as i keep lmb holding.

Now the trick was if i let lmb go to not to waste ammo but sometimes enemy was appearing again in 4 that seconds window and i had to press to lmb to hit the enemy again.

if i shoot in that duration again and again the script was consuming my action points so unnecessarily.

The script you have updated didn't even activate f button trigger for some reason.

In a sense script should bypass my lmb for 4 secs after being activated once and it must have some sort of internal cooldown.

Rohwedder
Posts: 7774
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help about this particular code

Post by Rohwedder » 24 May 2023, 02:49

The script you have updated didn't even activate f button trigger for some reason.
Are you really not able to see what my script does and when?
I have no idea about your game. If you then obviously have no idea about Autohotkey, sorry, that does not work!

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: Help about this particular code

Post by Pacifista » 25 May 2023, 16:31

You dont have to be angry with me, if i had known ahk i'd not ask here. I'm sorry if i had offended you.

your script just didn't activate f button when i press lmb in the first place let alone preventing it from pressing for 4 secs.

if there is no prefix lmb is not activating f button so maybe the button description should be different i don't know.

Rohwedder
Posts: 7774
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help about this particular code

Post by Rohwedder » 26 May 2023, 02:20

I just don't like it when someone needs Autohotkey but thought itself too good for to bother with it.
I commented your original script. Try again to explain what it should do differently and when, without mentioning game internals.
I had been of the mistaken opinion that with a 2nd press of LButton within 4 seconds neither the immediate call of the subroutine nor the initialization of the timer should happen.

Code: Select all

~LButton:: ; ~LButton thread is started as soon as LButton (left mouse button) is pressed.
Gosub, Key ; calls the subroutine Key (, which sends a simulated F keystroke)
SetTimer, Key, 4000 ; initializes a timer which calls the subroutine Key
; the first time after 4 seconds and every 4 seconds thereafter.
KeyWait, LButton ; the script waits for the LButton to be released.
SetTimer, Key, Off ; turns off the timer
Return ; ~LButton thread will be terminated

Key: ; subroutine Key
Send f ;sends a simulated F keystroke
Return ; The call of the subroutine Key will be terminated

*PAUSE::
Suspend ;Suspend Hotkeys off/on
Pause,, 1 ;Pause Script off/on
Return

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: Help about this particular code

Post by Pacifista » 26 May 2023, 21:53

@Rohwedder

Script is working now.

1- When i click lmb to shoot, script must activate "f" button once but it mustn't send f button again for another 4 seconds, it mustn't take other lmb clicks into account for 4 secs from the beginning of that f button activation.
2- When lmb is being pressed and hold, first it will activate f button once and gonna keep sending "f" button for once every 4 seconds. The critical thing here is script mustn't send f button
if i release lmb and click lmb again no matter how many times i press lmb during that 4 seconds period.

if there was a resource that teaching this particular type of scripting i'd gladly try to learn. I tried variations for hours then i came here for help, sorry for begging help.

i just wanted to add a few lines to my script.

Post Reply

Return to “Gaming Help (v1)”