Lag & skipped sent keystrokes in Hitman 3

Ask gaming related questions
Rok
Posts: 63
Joined: 11 Jan 2016, 08:50

Lag & skipped sent keystrokes in Hitman 3

Post by Rok » 24 May 2023, 07:14

Hey.

Context:

The game is Hitman 3 on the Epic Games Launcher platform. Here are my current "headings" at the top of the script, in case any of them are involved in this problem, despite my doubting this because I commented most of them out seemingly without different results:

Code: Select all

#Requires AutoHotkey v2.0
SetWorkingDir A_InitialWorkingDir
A_MaxHotkeysPerInterval := 10000
; #SingleInstance force
; InstallKeybdHook
; #UseHook

DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), SuspendIfActive)

SuspendIfActive(event, hwnd, *) {
  if event != 32772 ; HSHELL_RUDEAPPACTIVATED
    return

  ; if any of the listed executables is the active window
  if WinActive("ahk_exe Wow.exe") or WinActive("ahk_exe XCom2.exe") {
    Suspend true
  } else {
    Suspend false
  }
}
Problem:

Remapped keystrokes with some complexity are unresponsive or highly laggy, and some steps are often skipped, while simpler remapped hotkeys like a::b are much more robust. Some keystrokes simulated via Send don't seem to register unless I break them into their down and up states or steps, as shown in the example code below. Finally, those Sleep times are way too long for my liking, and the game responds to manual key presses much faster than this, but I was only able to get those steps to occur correctly in-game by increasing the 100 and 250 Sleep times to 250 and 500, respectively, for example. The most significant problem, though, is that the third and final keystroke of Enter and the final Esc keystroke in the code below, for example, do not register in-game at all unless I increase the Sleep times to counterproductive lengths.

Code: Select all

#HotIf WinActive("ahk_exe HITMAN3.exe")

b:: {
  ; Open the menu with Esc.
  Send "{Esc Down}"
  Sleep 100
  Send "{Esc Up}"
  Sleep 250
  ; Ensure you're at the topmost option "Save."
  Send "{Up Down}"
  Sleep 100
  Send "{Up Up}"
  Sleep 250
  ; Press Enter to activate the Save option.
  Send "{Enter Down}"
  Sleep 100
  Send "{Enter Up}"
  Sleep 250
  ; Press Enter again to pick the first Save Slot.
  Send "{Enter Down}"
  Sleep 100
  Send "{Enter Up}"
  Sleep 250
  ; Press Enter a 3rd time to Overwrite the Save file.
  Send "{Enter Down}"
  Sleep 100
  Send "{Enter Up}"
  Sleep 250
  ; Exit the menu with Esc.
  Send "{Esc Down}"
  Sleep 100
  Send "{Esc Up}"
}

#HotIf
Objectives:

I'd rather not be forced to break each keystroke into its Down and Up states, if possible. I also want the Sleep times used — to compensate for the game's UI response times — to be much shorter than 100 and 250 ms. Most importantly, I want all the sent keystrokes to register in-game.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Lag & skipped sent keystrokes in Hitman 3

Post by DuckingQuack » 08 Nov 2023, 19:41

Have you tried a different Send Mode?
https://www.autohotkey.com/docs/v2/lib/SendMode.htm
Best of Luck,
The Duck

Noitalommi_2
Posts: 220
Joined: 16 Aug 2023, 10:58

Re: Lag & skipped sent keystrokes in Hitman 3

Post by Noitalommi_2 » 09 Nov 2023, 10:28

Hi,

you can avoid the sleep commands if you use SetKeyDelay.

The entire saving process takes ~1.6s for me with the script below.
It doesn't work any faster for me, otherwise the game would no longer register the key presses correctly.

Code: Select all

#Requires AutoHotkey >=2.0
#Warn
#SingleInstance

SetKeyDelay(250, 25)

b:: {

	SendEvent("{Esc}")
	SendEvent("{Up}")
	Loop 3
		SendEvent("{Enter}")
	SendEvent("{Esc}")

}

Post Reply

Return to “Gaming”