"SOCD cleaning" (blocking directional input on conditions)

Ask gaming related questions (AHK v1.1 and older)
Valcyo
Posts: 1
Joined: 02 Jan 2018, 14:37

"SOCD cleaning" (blocking directional input on conditions)

02 Jan 2018, 15:08

I'm looking into making a SOCD cleaning macro for AutoHotkey for a keyboard but I'm completely slumped how to start doing it. SOCD stands for "Simultaneous Opposing Cardinal Directions.", and one explanation is here

Say you have four directional input keys: ASD for left, down and right and spacebar or W for up.
So left+right = no input.
down+up = either up or no input, depending on preference.
So if you hold left and then tap or hold right, it'll do left first but then has no input, but if you let go of right while still holding left it will go back to holding left and vice versa.
Similarly up+left+right should still do up, etc.

I'm beginning to realize implementing this is way more complicated than I expected and will probably require nested loops or something. I was looking at https://lexikos.github.io/v2/docs/misc/Remap.htm and attempting something by remapping a:: to checking keystate of d and then pressing a or releasing a depending if d is held down but I didn't get working it right. How should I go about realizing this?
TygerByte
Posts: 96
Joined: 12 Aug 2016, 05:22

Re: "SOCD cleaning" (blocking directional input on conditions)

03 Jan 2018, 22:31

I have a sprint macro you can look at it and see if you can get some inspiration. You would likely just need to check every time the while loop runs if the key you need checked is pressed or not and do stuff the way you want. GL. I need sleep on my while loop because my system runs at a higher timer resolution and it eats too cpu resources if I don't have it.

Code: Select all

~$*W::
	; If I'm not set to sprint I'll start sprinting after holding w down for half a second. I use this because I toggle it for other activities and is my primary way of turning on the hotkeys.
	if (RunForestRun = 0) {
		KeyWait w, T0.5
		If ErrorLevel {
			RunForestRun = 1
		}
	}
	
	; While W is considered pressed and my toggle is on, I check first to make sure I actually need to press the Sprint key because I don't want multiple presses if it's already pressed. Combined with other checks.
	While GetKeyState("W") && (RunForestRun = 1) {
		if !GetKeyState(SprintKey) && (Aiming = 0) && (Firing = 0) && (Crouching = 0) && (Walking = 0) && (Secondary = 0) {
			Send, {Blind}{%SprintKey% Down}
		}
		Sleep, 10
	}
	Return

~$*W Up::
	; if any other movement is not being held and sprint is being pressed you can release sprint
	if (!(GetKeyState("A") || GetKeyState("S") || GetKeyState("D")) && GetKeyState(SprintKey)) {
		Send {Blind}{%SprintKey% Up}
	}
	Return

~$*A::
	While GetKeyState("A") && (RunForestRun = 1) {
		if !GetKeyState(SprintKey) && (Aiming = 0) && (Firing = 0) && (Crouching = 0) && (Walking = 0) && (Secondary = 0) {
			Send {Blind}{%SprintKey% Down}
		}
		Sleep, 10
	}
	Return
	
~$*A Up::
	if (!(GetKeyState("W") || GetKeyState("S") || GetKeyState("D")) && GetKeyState(SprintKey)) {
		Send {Blind}{%SprintKey% Up}
	}
	Return

~$*S::
	While GetKeyState("S") && (RunForestRun = 1) {
		if !GetKeyState(SprintKey) && (Aiming = 0) && (Firing = 0) && (Crouching = 0)  && (Walking = 0) && (Secondary = 0) {
			Send {Blind}{%SprintKey% Down}
		}
		Sleep, 10
	}
	Return
	
~$*S Up::
	if (!(GetKeyState("A") || GetKeyState("D") || GetKeyState("W")) && GetKeyState(SprintKey)) {
		Send {Blind}{%SprintKey% Up}
	}
	Return

~$*D::
	While GetKeyState("D") && (RunForestRun = 1) {
		if !GetKeyState(SprintKey) && (Aiming = 0) && (Firing = 0) && (Crouching = 0)  && (Walking = 0) && (Secondary = 0) {
			Send {Blind}{%SprintKey% Down}
		}
		Sleep, 10
	}
	Return
	
~$*D Up::
	if (!(GetKeyState("W") || GetKeyState("S") || GetKeyState("A")) && GetKeyState(SprintKey)) {
		Send {Blind}{%SprintKey% Up}
	}
	Return
GetKeyState() should return 1 if it's being pressed by something either ahk or you.
if GetKeyState() means if it is pressed then do { stuff in here }
if !GetKeyState() means if it's not pressed then do { stuff in here }

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 104 guests