Browse Source

added stopwatch functionality to Outer Wilds script (first try)

ahk-v1
Mario Alegre 5 years ago
parent
commit
8cd81682ce
  1. 85
      lib/Stopwatch.ahk
  2. 49
      src/Outer_Wilds.ahk

85
lib/Stopwatch.ahk

@ -0,0 +1,85 @@
;
; Functions for stopwatch
;
; The stopwatch gui should be called "StopwatchGui",
; and have a text parameter labeled "StopwatchText".
; Window should be initialized in the main script;
; this library assumes the window already exists.
; Global Vars
StopwatchTime = 0
StopwatchHidden = 0
StopwatchOn = 0
SetTimer, StopwatchUpdate, 1000
SetTimer, StopwatchUpdate, Off
StopwatchStop() {
Global StopwatchOn
SetTimer, StopwatchUpdate, Off
StopwatchOn = 0
}
StopwatchStart() {
Global StopwatchOn
SetTimer, StopwatchUpdate, On
StopwatchOn = 1
}
StopwatchToggle() {
Global StopwatchOn
If StopwatchOn {
StopwatchStop()
} Else {
StopwatchStart()
}
}
StopwatchReset() {
Global StopwatchTime
StopwatchTime = 0
StopwatchShow()
}
StopwatchShow() {
Global StopwatchTime, StopwatchHidden
Minutes := Format("{:02}", StopwatchTime // 2)
Seconds := Format("{:02}", Mod(StopwatchTime, 60))
GuiControl, Text, MyGuiText, %Minutes%:%Seconds%
Gui, Show, NoActivate, StopwatchGui
StopwatchHidden = 0
}
StopwatchHide() {
Global StopwatchHidden
StopwatchStop()
Gui, Hide, , StopwatchGui
StopwatchHidden = 1
}
StopwatchToggleHidden() {
Global StopwatchHidden
If StopwatchHidden {
StopwatchShow()
} Else {
StopwatchHide()
}
}
StopwatchUpdate() {
Global StopwatchTime
StopwatchTime++
StopwatchShow()
}
StopwatchFastforward(Seconds:=1) {
Global StopwatchTime
StopwatchTime += Seconds
StopwatchShow()
}
StopwatchRewind(Seconds:=1) {
Global StopwatchTime
StopwatchTime -= Seconds
StopwatchShow()
}

49
src/Outer_Wilds.ahk

@ -6,7 +6,11 @@
;
; Include general library
#Include ../lib/General.ahk
#Include ../lib/Prelude.ahk
#Include ../lib/Stopwatch.ahk
; Include
; Include ViGEm library
#Include ../thirdparty/AHK-ViGEm-Bus/AHK-ViGEm-Bus.ahk
@ -16,20 +20,45 @@ MyXbox := new ViGEmXb360()
; Set percent to deflect by for fine controls
Defl := 40
; Create Gui for timer
Gui, +AlwaysOnTop -Caption +ToolWindow
Gui, Margin, 0, 0
Gui, Font, s20 CWhite
Gui, Color, Black
Gui, Add, Text, vStopwatchText +Center, 00:00
Gui, Show, NoActivate x0 y0, StopwatchGui
WinSet, TransColor, Black 150, StopwatchGui
StopwatchHide()
; Only do hotkeys if relevant window is active
#IfWinActive, Outer Wilds
#If WinActive("Outer Wilds")
;
; Hotkeys
;
; Hold keys
*!w UP::Hold("w",["s"])
*!s UP::Hold("s",["w"])
*!a UP::Hold("a",["d","w","s"])
*!d UP::Hold("d",["a","w","s"])
*!Space UP::Hold("Space",["Shift"])
*!Shift UP::Hold("Shift",["Space"])
;
; Stopwatch
;
; Alt+F9: Show/Hide stopwatch
!F9::StopwatchToggleHidden()
; F9: Reset stopwatch
F9::StopwatchReset()
; F10: Start/stop stopwatch
F10::StopwatchToggle()
; F11: Rewind stopwatch 5 sec
F11::StopwatchRewind(5)
; F12: Fastforward stopwatch 5 sec
F12::StopwatchFastforward(5)
;
; Fine Controls
;
; Reset all axes when capslock is pressed
~CapsLock::
@ -40,7 +69,7 @@ MyXbox.Axes.LT.SetState(0)
return
; Fine control is active when caps lock is on
#If GetKeyState("CapsLock","T")
#If WinActive("Outer Wilds") and GetKeyState("CapsLock","T")
W::MyXbox.Axes.LY.SetState(50+Defl*.5)
W UP::MyXbox.Axes.LY.SetState(50)

Loading…
Cancel
Save