Skip to content

Commit

Permalink
- minor code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
GenesisFR authored Feb 15, 2021
1 parent df66355 commit a856b78
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions HoldToggles.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ isSprinting := false

; Config file is missing, exit
if (!FileExist("HoldToggles.ini"))
{
MsgBox, 16, Error, HoldToggles.ini not found! The script will now exit.
ExitApp, -1
}
ExitWithErrorMessage("HoldToggles.ini not found! The script will now exit.")

; Read options from config file
IniRead, windowName, HoldToggles.ini, General, windowName
Expand All @@ -34,15 +31,15 @@ IniRead, aimKey, HoldToggles.ini, General, aimKey, RButton
IniRead, crouchKey, HoldToggles.ini, General, crouchKey, LCtrl
IniRead, sprintKey, HoldToggles.ini, General, sprintKey, LShift
IniRead, hookDelay, HoldToggles.ini, General, hookDelay, 0
IniRead, isDebug, HoldToggles.ini, General, isDebug
IniRead, isDebug, HoldToggles.ini, General, isDebug, 0

if (isDebug)
{
arrValues := [windowName, isAimToggle, isCrouchToggle, isSprintToggle, aimKey, crouchKey, sprintKey]
MsgBox, % Format("windowName: {}`nisAimToggleEnabled: {}`nisCrouchToggleEnabled: {}`nisSprintToggleEnabled: {}`naimKey: {}`ncrouchKey: {}`nsprintKey: {}", arrValues*)
arrValues := [windowName, isAimToggle, isCrouchToggle, isSprintToggle, aimKey, crouchKey, sprintKey, hookDelay]
MsgBox, % Format("windowName: {}`nisAimToggleEnabled: {}`nisCrouchToggleEnabled: {}`nisSprintToggleEnabled: {}`naimKey: {}`ncrouchKey: {}`nsprintKey: {}`nhookDelay: {}", arrValues*)
}

; Make the hotkeys active only for a specific application
; Make the hotkeys active only for a specific window
WinWaitActive, %windowName%
Sleep, %hookDelay%
WinGet, windowID, ID, %windowName%
Expand Down Expand Up @@ -95,9 +92,9 @@ If WinActive(windowName)
tempIsSprinting := isSprinting

DisableAllToggles()
WinWaitActive, %windowName%

; Restore toggle states
WinWaitActive, %windowName%
Aim(tempIsAiming)
Crouch(tempIsCrouching)
Sprint(tempIsSprinting)
Expand Down Expand Up @@ -137,13 +134,6 @@ DisableAllToggles()
Sprint(false)
}

; Exit script
ExitFunc(ExitReason, ExitCode)
{
DisableAllToggles()
ExitApp
}

; Suspend script (useful when in menus)
!F12:: ; ALT+F12
Suspend
Expand All @@ -159,3 +149,18 @@ else
}

DisableAllToggles()
return

; Display an error message and exit
ExitWithErrorMessage(ErrorMessage)
{
MsgBox, 16, Error, %ErrorMessage%
ExitApp, -1
}

; Exit script
ExitFunc(ExitReason, ExitCode)
{
DisableAllToggles()
ExitApp
}

0 comments on commit a856b78

Please sign in to comment.