#SingleInstance force
Gui,+AlwaysOnTop
Gui, -SysMenu
Gui, +ToolWindow
Total := 60.00
Percent := 100

;   Your Touchpoint global hotkey for break should be set to Win+Shift+B

Gui, Add, Progress, x2 y1 w110 h14 +Right -Smooth vSlider, %Percent%    ; Slider at the top, a nice visual
Gui, Add, Text, x30 y23 w40 h20 vTotal +Right, %Total%  ; The total time left
Gui, Add, Edit, x72 y20 w40 h20 +Number vInput +Center, ; Input box for when you manually do a break
Gui, Add, Button, x2 y20 w40 h20 vLock, Lock    ; Button to lock PC
Gui, Add, Text, x2 y23 w40 h20 vLockT, Locked   ; Text that confirmes that your PC is locked
Gui, Add, Button, x2 y20 w40 h20 vBreak, Break  ; Button to start break
Gui, Add, Button, x2 y20 w40 h20 vEnd, End      ; Button to end break
Gui, Add, Button, x21 y83 w70 h30 Default +Center vHidden, Subtract ; Button that is default so that when you press enter on the input field it submits the form instead of there being an annoying visible button.

;   Hide the things we don't want to see when it starts up
GuiControl, Hide, Hidden
GuiControl, Hide, Lock
GuiControl, Hide, LockT
GuiControl, Hide, End

;   Show the GUI
Gui, Show, h45 w115, Break time
Return

+esc::ExitApp   ; Shift+Escape will close the thing, its not really a common shortcut and you have to have the window focused for it to work

ButtonSubtract: ; The default button, subtracts the time you entered into the field from the total
    gui, submit, NoHide ; Makes sure the GUI doesn't dissapear when you submit it
    Percent := Input/0.6    ; Divides the time you input by 0.6 so that you have a percentage of an hour
    Total -= Input          ; Subtracts what you entered from the total time
    GuiControl,, Slider, +-%Percent%    ; Modify the slider at the top
    Total := SubStr(Total, 1, 5)        ; Trim off the total cause it now has a bunch of useless zeros at the end, and we don't want to see those
    GuiControl,, Total, %Total%         ; Modify the Total
    GuiControl,, Input,                 ; Clear the input field so nothing happens when you press enter multiple times
Return

ButtonBreak:    ; Starts your break
    gui, submit, NoHide
    GuiControl, Hide, Break ; Hide the Break button
    GuiControl, Show, Lock  ; Show the Lock button
    Send, #+B   ;   Hotkey for default Break Time (10 mins)
    StartTime := A_TickCount    ; Saves the time that we started at in Milliseconds
    Sleep, 2000 ; show the lock button for 2 seconds
    GuiControl, Hide, Lock  ; remove the lock button
    GuiControl, Show, End   ; show the end button
Return

ButtonLock:     ; Locks the PC
    gui, submit, NoHide
    GuiControl, Hide, Lock  ; If you can't figure this one out by now, you might need to RTFM
    GuiControl, Show, LockT
    Run rundll32.exe user32.dll`,LockWorkStation    ;   Locks PC by calling the DLL. just sending Win+L sadly doesn't work
    Sleep, 2000
    GuiControl, Hide, LockT
    GuiControl, Show, End
Return

ButtonEnd:      ; Ends your break
    Send, #+B   ;   Break hotkey
    ElapsedTime := A_TickCount - StartTime  ; grabs the current time in MS, and subtracts it from the time that we recorded earlier
    GuiControl, Hide, End
    ELSeconds := ElapsedTime/1000   ; convert to seconds
    ELMins := ELSeconds/60          ; convert to minutes
    ELMins := Round(ELMins, 2)      ; round it off to 2 places
    Total := (Total-ELMins)         ; subtract the elapsed minutes (in ##.##0000) from the total
    Total := SubStr(Total, 1, 5)    ; Trim off the total cause it now has a bunch of useless zeros at the end, and we don't want to see those
    Percent := ELMins/0.6           ; Divides the time elapsed by 0.6 so that you have a percentage of an hour
    GuiControl,, Slider, +-%Percent%
    GuiControl,, Total, %Total%
    Sleep, 1000
    GuiControl, Show, Break
Return