Maximizing The Sims 4 Experience: Custom Keybindings with AutoHotKey

Post gaming related scripts
User avatar
Fugo
Posts: 8
Joined: 20 Aug 2023, 08:39

Maximizing The Sims 4 Experience: Custom Keybindings with AutoHotKey

22 Aug 2023, 10:53

Hello fellow AHK enthusiasts!

I wanted to share a script that I've been using to greatly enhance my gaming experience in The Sims 4. One of the things that I noticed was that, unlike many other games, The Sims 4 doesn't offer an in-game keybinding setting, which means players are stuck with the default hotkeys, regardless of their preferences. As someone who's always striving for the optimal gaming experience, I found the default keybindings to be a bit cumbersome and not very intuitive.

So, I decided to create a custom keybinding script using AutoHotKey, allowing me to remap certain keys to better suit my gameplay style. For example, I always found it a bit awkward to use the 'P' key to pause or resume the game, so I decided to remap it to the 'Space' key instead, which feels much more natural to me.

However, I encountered a problem: I needed the keybindings to be active only when The Sims 4 window was in focus, and I wanted to be able to toggle the keybindings on or off without affecting other applications.

This script does precisely that! It applies the custom keybindings only when The Sims 4 is the active window and even includes a handy tooltip that reminds you to press the 'Tab' key to toggle the keybinding remappings on or off. Additionally, it has a built-in check to automatically close the script if the game is no longer running.

Here's the gist of how the script works:
  • It first checks if The Sims 4 is running and launches the game if it's not.
  • It then sets a timer to check for the game window every second.
  • Custom keybindings are applied only when the game window is active, and they can be easily toggled on or off using the 'Tab' key.
  • If you're ever unsure about the toggle state of the keybindings, just press the 'Backspace' key to see a tooltip reminding you of the toggle key.
  • Lastly, the script monitors the state of The Sims 4 window and updates the suspension state accordingly. It will also automatically close the script if the game isn't running.
Here is the script:

Code: Select all

; Initialize variables
ScriptSuspended := false
PreviousSuspensionState := false
HasLeftGameWindow := false

; Launch The Sims 4 if it's not already running
if !WinExist("ahk_exe TS4_x64.exe")
{
	Run("steam://rungameid/1222670")
	; Wait for the game window to appear
	WinWait("ahk_exe TS4_x64.exe")
}
else
{
	; Bring The Sims 4 window to the foreground if it's already running
	WinActivate("ahk_exe TS4_x64.exe")
	; Wait for the game window to become active
	WinWaitActive("ahk_exe TS4_x64.exe")
}

; Set a timer to check for The Sims 4 every second
SetTimer(CheckSims4, 1000)

; Apply key remappings only when The Sims 4 is the active window and the script is not suspended
#HotIf WinActive("ahk_exe TS4_x64.exe") and !ScriptSuspended
; Remap various keys for different in-game actions
Space::p ; Pause or resume the game
p::Space ; Switch between active sims
q::,     ; Rotate the camera to the left
e::.     ; Rotate the camera to the right
f::PgUp  ; Move up to the next floor
v::PgDn  ; Move down to the previous floor
b::v     ; Start/stop video capture
t::Tab   ; Toggle camera mode between normal and free
#HotIf


; Apply hotkeys only when The Sims 4 is the active window
#HotIf WinActive("ahk_exe TS4_x64.exe")
; Show tooltip when the user presses the Backspace key
Backspace::
{
    ; Send a Backspace key event so that the key functions normally
    Send("{Backspace}")
    ToolTip("Press Tab key to toggle keybinding remappings on/off")
    SetTimer(HideTooltip, 5000)
	return
}
; Use Tab key to toggle partial suspension of the scripts
Tab::
{
	global ScriptSuspended := !ScriptSuspended
	global PreviousSuspensionState := ScriptSuspended
}
#HotIf

HideTooltip()
{
    ToolTip()
    SetTimer(HideTooltip, 0)
	return
}

; Check the state of The Sims 4 window and update the suspension state accordingly
CheckSims4()
{
	if (!WinActive("ahk_exe TS4_x64.exe") and !HasLeftGameWindow)
	{
		global ScriptSuspended := true
		global HasLeftGameWindow := true
	}
	else if (WinActive("ahk_exe TS4_x64.exe") and HasLeftGameWindow)
	{
		global ScriptSuspended := PreviousSuspensionState
		global HasLeftGameWindow := false
	}
	if !WinExist("ahk_exe TS4_x64.exe")
	{
		; If The Sims 4 isn't running, close the script
		ExitApp()
	}
}
I hope this script proves useful to other Sims 4 players who, like me, found the default keybindings to be a bit limiting. I encourage you to give it a try and see if it enhances your gameplay experience. If you have any feedback or suggestions, feel free to share. And of course, you are more than welcome to edit the script to suit your own preferences and needs. My intention is to provide a starting point, and I'd be thrilled if others find it helpful and make it their own. Together, let's make The Sims 4 an even more enjoyable experience for everyone!

Happy Simming!

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 5 guests