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
}
}
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
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.