Almost there! Need some help creating 2 toggles :) Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Albertstrum
Posts: 4
Joined: 02 May 2017, 11:05

Almost there! Need some help creating 2 toggles :)  Topic is solved

02 May 2017, 11:30

Hello! :)

I created a script to hold down a key (Q and E, respectively) on a toggle. This is so that I can toggle the leaning function in-game. (S.T.A.L.K.E.R : Call of Pripyat)

I need the script to do 3 things:
  • Hold Q down on a toggle
  • Hold E down on a toggle
  • Switch between holding E to holding Q when the other one is pressed
Here is my code, it works in notepad; spamming q then e, etc.
However once in-game it works once, then stops leaning. Alt-tabbing back to notepad and it works no problem?

Any help would be amazing! :dance:
Thanks

Code: Select all


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#maxThreadsPerHotkey, 4

;================DECLARE VARIABLES===================================
toggle_q := 0 
toggle_e := 0

;===========RUN LEAN_HOLD EVERY 100 TICS=============================
settimer, lean_hold_q, 100 ;run lean_hold every 100 tics
settimer, lean_hold_e, 101

;===========Q BUTTON TOGGLE==========================================
*q::                       

toggle_e := 0  ;stop other lean direction

toggle_q := !toggle_q  ; switch from toggle true/false everytime "q" pressed


lean_hold_q:    ;routine runs by setimer
	If (!Toggle_q) ; if not toggled on, do nothing
		Return
	Sendinput {q DOWN}       ; if toggled on send q 
return

;===========E BUTTON TOGGLE (SAME AS Q TOGGLE)=======================
*e::              

Toggle_q := 0

toggle_e := !toggle_e

lean_hold_e:
	If (!Toggle_e)
		Return
	Sendinput {e DOWN}
return

EDIT:

Here is the code that solved my problem! (posted by neomulemi6) (

Code: Select all


*q::
q := !q
if (q) 
	send {e up}{q down}
else 
	send {q up}
Return

*e::
e := !e
if (e)
	send {q up}{e down}
else
	send {e up}
Return


Last edited by Albertstrum on 06 May 2017, 11:14, edited 1 time in total.
neomulemi6
Posts: 216
Joined: 30 Jun 2016, 06:01

Re: Almost there! Need some help creating 2 toggles :)

02 May 2017, 12:11

Code: Select all

q::
q := !q
if (q) 
	send {e up}{q down}
else 
	send {q up}
Return

e::
e := !e
if (e)
	send {q up}{e down}
else
	send {e up}
Return
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Almost there! Need some help creating 2 toggles :)

02 May 2017, 14:50

Looks like you got help. Why asking specific for me?
Albertstrum
Posts: 4
Joined: 02 May 2017, 11:05

Re: Almost there! Need some help creating 2 toggles :)

03 May 2017, 11:50

Thanks neomulemi6 for your code, it is working :) (after adding * to q:: and e:: :p)

There still some issues though :(

I press Q, it holds down Q, I press Q again, and it lets Q go up (perfect!) - Same with using E.

The issue is switching between the toggles, for example: When Q is toggled down, I tap E to switch to E toggle down and it takes between 0 - 3 taps. The same goes for switching from E to Q.

It seems to be getting caught up on something? ( I have tried #MaxThreadsPerHotkey, 4 with no success :( )

In this thread https://autohotkey.com/boards/viewtopic ... 18&t=24666
they suggest using a loop to avoid weird behavior, I will experiment them in the meantime.

@Almost_there Haha a bit of serendipity there sorry, still, any ideas on my issue? :D :D
Albertstrum
Posts: 4
Joined: 02 May 2017, 11:05

Re: Almost there! Need some help creating 2 toggles :)

03 May 2017, 12:44

I have adapted eventhorizon's script to use Q and E, but the exact same issue remains; works a for a few key presses then the game stops being able to hold Q or E at all (although after alt-tabbing into notepad, it works perfectly!?)

Code: Select all

; set all the toggles to 0 first
qtoggle := 0
etoggle := 0


;loop through the keys to send
Loop
{	gosub SendMyKeys
}
return
	
*q:: ;set the q toggle
	etoggle := 0
	keywait,q
	qtoggle := !qtoggle
	;msgbox,0x1000,,qtoggle = %qtoggle%
	return
*e:: ;set the e toggle
	qtoggle := 0
	keywait,e
	etoggle := !etoggle
	;msgbox,0x1000,,etoggle = %etoggle%
	return


;this sends the keys one after the other with a 10ms delay to allow the
;keys to settle; the loop above will keep this thing running even if no
;toggles are active. You may want to find another way to activate the 
;SendMyKeys subroutine so you can use other keys too but this is just a
;proof of concept.

SendMyKeys:
	if (qtoggle)
	{	send, {q DOWN}
		sleep 10
	}
	if (etoggle)
	{	send, {e DOWN}
		sleep 10
	}
	return
neomulemi6
Posts: 216
Joined: 30 Jun 2016, 06:01

Re: Almost there! Need some help creating 2 toggles :)

03 May 2017, 18:15

That's strange. Must be that particular game doing something strange, because I did test my script in a different game and it worked as intended. Maybe try putting SetKeyDelay, 0, 50 at the top of your script?
Albertstrum
Posts: 4
Joined: 02 May 2017, 11:05

Re: Almost there! Need some help creating 2 toggles :)

06 May 2017, 11:10

Must be, the game uses a very buggy engine it's likely.
I'm using the code you posted and it's much better than having to hold down the buttons so I'm happy.

Thanks!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 124 guests