"Keep Forward" hotkey script (AutoHotkey)


Kyopaxa

Recommended Posts

Frustrated by the lack of a "keep forward" hotkey in game, I made a small AutoHotkey script that implements a "keep forward" functionality.

It works like this: When you press q, you'll keep moving forward. Pressing q again, backward or forward keys will cancel it. Use at your own risk, if your character dies jumping from a cliff because of this, don't blame me.

What is AutoHotkey

AutoHotkey is an automation/macro program that runs scripts tied to hotkeys or other events. It is widely used, open source, and has been out there for years. It is not a hack, consider it similar to those fancy keyboards with extra function keys, but without the need of a fancy keyboard. Also, it shouldn't affect your performance, the script is really light. You can find more information and download AutoHotkey here. You'll have to install it in order to use the script below.

The "Keep forward" script

Once you have AutoHotkey installed, you can save this script in a text file with ahk extension (or download it directly from this post, attached) and double click it when you want to play. AutoHotkey will open it and leave it running in a tray icon. What this script does is really simple. It listens to three hotkeys, then presses or releases the forward key according to the situation. If for any reason you use different keys for forward or backward in game, change them in the first lines of the text to match the ones you want to use.

forwardKey := "w"
backwardsKey := "s"
keepForwardKey := "q"
TLDProcessName := "tld.exe"
forwardWasDown = 0

Hotkey, *%keepForwardKey%, KeepForward
Hotkey, ~*%forwardKey% UP, ForwardUp
Hotkey, ~*%backwardsKey%, Backwards
return

; Keep forward
KeepForward:
WinGet, activeProcess, ProcessName, A
if (activeProcess != TLDProcessName) {
    Send, {%keepForwardKey%}
    return
}
if (GetKeyState(forwardKey, "P")) { ; if forward was physically down, save it to keep it down when it goes up
  forwardWasDown = 1
} else if (GetKeyState(forwardKey)) { ; if forward was not physically down, but it was pressed by authotkey, cancel forward
  send, {%forwardKey% up}
} else { ; else, activate Keep forward
  send, {%forwardKey% down}
}
return

; Going backwards cancels Keep forward
Backwards:
WinGet, activeProcess, ProcessName, A
if (activeProcess = TLDProcessName and GetKeyState(forwardKey)) {
  send, {%forwardKey% up}
}
return

; Don't allow forward UP to cancel Keep forward if it was activated when going forward
ForwardUp:
WinGet, activeProcess, ProcessName, A
if (forwardWasDown = 1) {
  if (activeProcess = TLDProcessName) {
    send, {%forwardKey% down}
  }
  forwardWasDown = 0
}
return

 

TLD-KeepForward.ahk

Link to comment
Share on other sites

3 hours ago, PINGU said:

Thanks. How much does this affect game performance? I guess it would if it works thru an external program

AutoHotkey is a hotkey/scripting external program designed to be used for automation, and has been out there for years. It's not heavy on the system, but it depends on what you script with it, of course. This "keep forward" script is super simple, really, I doubt you'll notice anything with it running in the background. The only thing it does is to listen to 3 hotkeys, then press or release the forward key according to what key you pressed.

Link to comment
Share on other sites

2 hours ago, Carbon said:

It would have to or it would violate the EULA, a hack.

I doubt this can be considered a hack since it doesn't interfere with any memory or file from The Long Dark directly. It's just a keyboard macro. Lots of fancy keyboards out there do similar things. This is just software based, no need for a fancy keyboard :)

Link to comment
Share on other sites

2 hours ago, Carbon said:

It would have to or it would violate the EULA, a hack.

I seriously doubt that you actually read terms of service, to post something as unintelligent.

Personally i just use X-Mouse, since i have 2 extra keys on my mouse, this way they serve a purpose as well.

Link to comment
Share on other sites

Edited the script to ensure it only presses the forward key if you are playing TheLongDark. This will prevent the script from doing anything in other programs, which can be annoying if you forgot to close the script after playing :)

Also added more info to the OP and attached the script for direct download. Enjoy!

Link to comment
Share on other sites

  • 2 weeks later...

I use an autohotkey script too -- I have to after a long hiatus from TLD to heal a repetitive use injury to my W finger, ugh.  (Never had this problem with any other WASD game, I blame the wind. :P )

My script is a little different:

  • It disables autowalk if certain UI keys are pressed - Inventory, Radial, and Clothing (prevents autowalk from trying to navigate the UI in these windows!)
  • Also disables autowalk if you press W or S... but not the strafe keys.  So you can just tap W to stop to pick up a stick.  Or if you backpedal when you spot a wolf, autowalk is cancelled.
  • I use some different code for the same functionality... maybe a bit more performant and compact
; Autowalk for The Long Dark
; To cancel autowalk hit the (autowalk) key again, or press w, s, (inventory), (radial) or (clothing)

#SingleInstance Force
#IfWinActive ahk_exe tld.exe   ; only when TLD is the active window

Numpad7::  ; KEYBIND Autowalk
	SendInput % "{w " ( (autowalk:=!autowalk) ? "down" : "up" ) "}" 
	Return
	
#if autowalk   ; PERFORMANCE capture these keystrokes only when autowalk is active
w::
s::
TAB::      ; KEYBIND inventory
c::        ; KEYBIND clothing
	SendInput {%A_ThisHotkey%}
	autowalk:=0
	SendInput {w up}
	Return
e::        ; KEYBIND Radial menu
	autowalk:=0
	SendInput {w up}
	SendInput {%A_ThisHotkey% down}
	Return
	
#if

Going for the best performance (and because I'm lazy) I hardcoded my personal keybinds into the script.  I honestly no longer remember the defaults, but they aren't hard to change.  Look for KEYBIND in the script above and substitute the key name at the start of the line (before the two colons) with the name of the key or mouse button you use.  Consult this page for the names of special keys: https://autohotkey.com/docs/KeyList.htm.

One important tip:  AutoHotKey is incredibly picky about spaces vs. tabs.  The indented lines MUST start with a single tab, so make sure your editor doesn't convert to spaces or the script won't run.

Link to comment
Share on other sites

  • 4 weeks later...

Here's my customised version of @Ruruwawa's script.. adapted to use 'q', the same as @Kyopaxa's script, and with Ruruwawa's custom keybinds replaced by standard ones. It's also been tweaked to play nice with v.423 Cartographer.

; Autowalk for The Long Dark
; To cancel autowalk hit the (autowalk) key again, or press w, s, (inventory), (radial) or (clothing)

#SingleInstance Force
#IfWinActive ahk_exe tld.exe   ; only when TLD is the active window

q::  ; KEYBIND Autowalk
	SendInput % "{w " ( (autowalk:=!autowalk) ? "down" : "up" ) "}" 
	Return
	
#if autowalk   ; PERFORMANCE capture these keystrokes only when autowalk is active
w::
s::
; TAB::      ; KEYBIND information
i::      ; KEYBIND inventory
c::        ; KEYBIND clothing
	SendInput {%A_ThisHotkey%}
	autowalk:=0
	SendInput {w up}
	Return
Space::        ; KEYBIND Radial menu
	autowalk:=0
	SendInput {w up}
	SendInput {%A_ThisHotkey% down}
	Return
	
#if

 

Link to comment
Share on other sites

  • 2 months later...

A new version, merged with @Ruruwawa's F2 RapidClicker for wolf struggles.

 

; Autowalk & RapidClicker for The Long Dark
; To cancel autowalk hit the (autowalk) key again, or press w, s, (inventory), (radial) or (clothing)

; Send left mouse button clicks by holding down a key
; Hold F2 down to send a left mouse click every 50 millisecond.  Release F2 to stop sending clicks.

#SingleInstance Force
#IfWinActive ahk_exe tld.exe   ; works only when TLD is the active window

F2::	; hold down 'F2' for wolf struggle
	While GetKeyState("F2", "P") {
		Click
		Sleep 50
	}
	Return

q::  ; KEYBIND Autowalk
	SendInput % "{w " ( (autowalk:=!autowalk) ? "down" : "up" ) "}" 
	Return
	
#if autowalk   ; PERFORMANCE capture these keystrokes only when autowalk is active
w::
s::
; TAB::      ; KEYBIND information
i::      ; KEYBIND inventory
c::        ; KEYBIND clothing
	SendInput {%A_ThisHotkey%}
	autowalk:=0
	SendInput {w up}
	Return
Space::        ; KEYBIND Radial menu
	autowalk:=0
	SendInput {w up}
	SendInput {%A_ThisHotkey% down}
	Return
	
#if

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.