Windows stopwatch manager

Post your working scripts, libraries and tools for AHK v1.1 and older
HereToHelp
Posts: 1
Joined: 10 Jun 2023, 18:18

Windows stopwatch manager

Post by HereToHelp » 10 Jun 2023, 18:28

I made a basic script to manipulate Windows 11's built-in stopwatch on keypress, for my own use, and I thought I'd share
It's bound to F4, but you could set it to anything. The one conceit is that in the Clock app the last tab you used has to have been the stopwatch, because that changes what tab it will be on when the app launches.
The script basically just checks if the stopwatch is open; if not it opens it for you and sets it up for you, and if it is it just sends a Space input to either start or pause the stopwatch.

Code: Select all

#IfWinExist Clock               ; Check that the stopwatch is open
F4::                            ; When I press F4
WinGet, ActiveId, ID, A         ; Store the window I'm looking at
WinActivate                     ; Focus on the stopwatch
Send {Space}                    ; Press space (this assumes you're tabbed onto the start/stop button (see below))
WinActivate, ahk_id %ActiveId%  ; Return focus to the window I was looking at
Return                          ; End the script
#IfWinExist                     ; End of if statement

#IfWinNotExist Clock            ; Otherwise, if it doesn't exist
F4::                            ; If I press F4
WinGet, ActiveId, ID, A         ; Store the window I'm looking at
run C:\Program Files\WindowsApps\Microsoft.WindowsAlarms_11.2302.5.0_x64__8wekyb3d8bbwe\Time.exe ; Open the clock (you may need to change this filepath)
WinWait Clock                   ; Wait for it to open
sleep 1000                      ; Give it a second to initialize
Send {Tab}                      ; Send three tabs to get to the fullscreen button (this assumes you had the stopwatch open last)
sleep 100                       ; ""
Send {Tab}                      ; ""
sleep 100                       ; ""
Send {Tab}                      ; ""
sleep 100                       ; ""
send {Space}                    ; Make stopwatch fill the window
sleep 100                       ; These 100ms waits are just so they keypresses are distinct
Send {Tab}                      ; Tab onto the start/stop button (see above)
WinActivate, ahk_id %ActiveId%  ; Return focus to the window I was looking at
Return                          ; End the script
#IfWinNotExist                  ; End of if statement

Return to “Scripts and Functions (v1)”