Sleep hygiene at its finest. :-(
The script is hidden in the "spoiler" to minimize clutter.
Code: Select all
; Name: goto_bed.ahk
; Version: 1.0
; Type: AutoHotkey script
; Author: Joel Polowin, 2017 May 19
; Function: Opens a full-screen window in each monitor displaying a large
; text message, pauses, then closes all of its windows and exits. Intended
; to "nag" to get one to stop using the computer, run as a scheduled task.
; ------
; Configurable options:
Window_text := "Go to bed!" ; Message to show in windows
Duration_in_s := 60 ; Time for the windows to stay up, in s
Text_size := 180 ; Text font size
Stubborn := false ; If true, will disable the "minimize" and "close" icons so
; the script can only be halted through the task manager!
; Background and text colours, in quotes: one of Black, Silver, Gray, White,
; Maroon, Red, Purple, Fuchsia, Green, Lime, Olive, Yellow, Navy, Blue, Teal,
; or Aqua. Or a 6-digit RGB hexadecimal value; e.g., FFA022 is light orange.
Window_colour := "FF1111"
Text_colour := "Green"
; ------
#SingleInstance force ; Cancel any copies of this script already running
SysGet, monitor_count, MonitorCount ; Get the # of monitors
; Here's where we create the windows
Loop, %monitor_count% ; Loop over the monitors
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
PopWindowName := "window" . A_Index ; Create a name for a window
; Create the window, recording its unique ID
Gui, %PopWindowName%:New, +HwndWindowID, %Window_text%
WinIDs%A_Index% := WindowID ; store the window's ID
; If the "stubborn" setting is on, force the window on top of all other
; windows, and don't let it be minimized or closed.
if (Stubborn)
Gui, +AlwaysOnTop -SysMenu -Resize
Gui, Color, %Window_colour% ; Set window colour
Gui, font, s%Text_size% c%Text_colour% ; Set text font size and colour
Gui, %PopWindowName%:Add, Text, , %Window_text% ; Add text to window
; Show the window at the top left of the monitor
Gui, %PopWindowName%:Show, X%monitor_Left% Y%monitor_Top%
Gui, %PopWindowName%:Maximize ; Maximize the window
}
; Wait the specified time. If "Stubborn" is set, each second, we move each
; window back to the top left of its monitor, and re-maximize it.
Loop, %Duration_in_s% ; Loop over the # seconds we're pausing
{
if (Stubborn)
{
Loop, %monitor_count% ; Loop over the monitors
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
ID := "ahk_id " . WinIDs%A_Index% ; Get the window's ID from array
; Move the window back to the top left of the monitor
WinMove, %ID%, , %monitor_Left%, %monitor_Top%
WinMaximize, %ID% ; Maximize the window again
}
}
Sleep, 1000 ; Wait 1000 ms, i.e. 1 second
}
ExitApp ; Exit, closing all of the windows we created
Code: Select all
; Name: goto_bed.ahk
; Version: 2.0
; Type: AutoHotkey script
; Author: Joel Polowin, 2017 May 25
; Function: Opens a full-screen window in each monitor displaying a large
; text message, pauses, then closes all of its windows and exits. Intended
; to "nag" to get one to stop using the computer, run as a scheduled task.
; ------
; Command-line arguments
; bCOLOUR_STRING e.g. bRed, bFFD000 Background/window colour
; fCOLOUR_STRING e.g. fRed, fFFD000 Foreground/text colour
; mMESSAGE e.g. "mSLEEPY TIME!" Message text
; pPAUSE_TIME e.g. p30 Pause time in seconds
; s[TRUE|FALSE] e.g. sTRUE "Stubborn" setting
; tTEXT_FONT_SIZE e.g. t200 Text font size
;
; Example: goto_bed.ahk p60 bFF3333 fGreen "mTIME TO SNOOZE" sTRUE
;
; Either colour can be one of: Black, Silver, Gray, White, Maroon, Red, Purple,
; Fuchsia, Green, Lime, Olive, Yellow, Navy, Blue, Teal, or Aqua. Or a
; 6-digit RGB hexadecimal value; e.g., FFA022 is light orange.
;
; "Stubborn" setting: if true, will disable the "minimize" and "close" icons so
; the script can't be halted, even with the Task Manager. The script will
; halt if there are no active windows, including if the user logs out.
;
; If there is a "lock.txt" file in the same directory, the script will exit
; immediately. This lets us restrict the script to running for particular users
; when they're actually using the computer, not just signed in, using scheduled
; tasks to delete and create the file on "local connect" and "local disconnect"
; respectively.
; ------
; Configurable options' default values:
global Message := "Go to bed!" ; Message to show in windows
global Pause_in_s := 60 ; Time for the windows to stay up, in s
global Text_size := 180 ; Text font size
global Stubborn := false ; "Stubborn" setting
global BG_colour := "FF1111" ; Background/window colour
global FG_colour := "Green" ; Foreground/text colour
; ------
#SingleInstance force ; Cancel any copies of this script already running
; If there's a "lock.txt" file in the same directory, exit immediately.
if FileExist("lock.txt")
ExitApp ; Exit, closing all of the windows we created
; Loop over the command-line arguments and send them to SetArgs() for parsing
loop, %0%
{
param := %A_Index%
SetArgs(param)
}
SysGet, monitor_count, MonitorCount ; Get the # of monitors
; Here's where we create the windows
Loop, %monitor_count% ; Loop over the monitors
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
PopWindowName := "window" . A_Index ; Create a name for a window
; Create the window, recording its unique ID
Gui, %PopWindowName%:New, +HwndWindowID, %Message%
WinIDs%A_Index% := WindowID ; store the window's ID
; If the "stubborn" setting is on, force the window on top of all other
; windows, don't let it be minimized or closed, and no buttons on taskbar.
if (Stubborn)
Gui, +AlwaysOnTop -SysMenu -Resize +ToolWindow
Gui, Color, %BG_colour% ; Set window colour
Gui, font, s%Text_size% c%FG_colour% ; Set text font size and colour
Gui, %PopWindowName%:Add, Text, , %Message% ; Add text to window
; Show the window at the top left of the monitor
Gui, %PopWindowName%:Show, X%monitor_Left% Y%monitor_Top%
Gui, %PopWindowName%:Maximize ; Maximize the window
}
; Wait the specified time, looping every second for the specified number of
; seconds.
Loop, %Pause_in_s% ; Loop over the # seconds we're pausing
{
Sleep, 1000 ; Wait 1000 ms, i.e. 1 second
; If "Stubborn" is set, each second, we move each window back to the top left
; of its monitor, and re-maximize it. We also hide the taskbar.
if (Stubborn)
{
; Terminate the script if the user logs out, providing an escape route.
WinGet, active_id, ID, A ; Get the ID of the "active" window
if (0 = active_id) ; If that ID is 0, i.e. there is no active window,
ExitApp ; exit the script
Loop, %monitor_count% ; Loop over the monitors
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
ID := "ahk_id " . WinIDs%A_Index% ; Get the window's ID from array
; Move the window back to the top left of the monitor
WinMove, %ID%, , %monitor_Left%, %monitor_Top%
WinMaximize, %ID% ; Maximize the window again
WinHide ahk_class Shell_TrayWnd ; Hide the taskbar
}
}
}
ExitApp ; Exit, closing all of the windows we created
; SetArgs() receives the command-line arguments one at a time, and parses them.
; The expected format is a single letter to specify the parameter type, followed
; by the parameter value.
SetArgs(arg)
{
StringCaseSense, Off ; The command parameters aren't case-sensitive
prefix := SubStr(arg, 1, 1) ; Get the first character in the parameter
value := SubStr(arg, 2) ; Get the rest of the parameter
if ("b" = prefix) ; background/window colour
{
BG_colour := value
}
else if ("f" = prefix) ; foreground/text colour
{
FG_colour := value
}
else if ("m" = prefix) ; message text
{
Message := value
}
else if ("p" = prefix) ; pause time in seconds
{
Pause_in_s := value
}
else if ("s" = prefix) ; "stubborn" setting
{
prefix := SubStr(value, 1, 1) ; get the first character of the value
if ("f" = prefix || "0" = prefix) ; see if that char is 'f' or '0'
Stubborn := 0
else
Stubborn := 1
}
else if ("t" = prefix) ; text size
{
Text_size := value
}
}
Code: Select all
type hi > lock.txt
Code: Select all
if exist lock.txt del lock.txt
Code: Select all
; Name: goto_bed.ahk
; Version: 3.0
; Type: AutoHotkey script
; Author: Joel Polowin, 2019 March 3
; Function: In each monitor, opens a full-screen window displaying a large
; text message, pauses, then closes all of its windows and exits. Intended
; to "nag" to get one to stop using the computer, run as a scheduled task.
; ------
; Command-line arguments
; bCOLOUR_STRING e.g. bRed, bFFD000 Background/window colour
; fCOLOUR_STRING e.g. fRed, fFFD000 Foreground/text colour
; kBLINK_PERIOD e.g. k2 Blink period in seconds, 0 = don't blink
; mMESSAGE e.g. "mSLEEPY TIME!" Message text
; pPAUSE_TIME e.g. p30 Pause time in seconds
; s[TRUE|FALSE] e.g. sTRUE "Stubborn" setting
; tTEXT_FONT_SIZE e.g. t200 Text font size
;
; Example: goto_bed.ahk p60 bFF3333 fGreen "mTIME TO SNOOZE" sTRUE
;
; These parameters are not case sensitive. For example, "p60" and "P60" do
; exactly the same thing.
;
; Either colour can be one of: Black, Silver, Gray, White, Maroon, Red, Purple,
; Fuchsia, Green, Lime, Olive, Yellow, Navy, Blue, Teal, or Aqua. Or a
; 6-digit RGB hexadecimal value; e.g., FFA022 is light orange.
;
; "Stubborn" setting: if true, will disable the "minimize" and "close" icons so
; the script can't be halted, even with the Task Manager. The script will
; halt if there are no active windows, including if the user logs out.
;
; In the message text, any instances of the string "`n" will be converted to
; line breaks. Any instances of the string "$TIME" will be converted to the
; current time. For example, message text "Go to bed!`n$TIME" would be drawn
; as something like:
; Go to bed!
; 10:22:05 P.M.
;
; If there is a "lock.txt" file in the same directory, the script will exit
; immediately. This lets the script be restricted to running for particular
; users when they're actually using the computer, not just signed in, using
; scheduled tasks to delete and create the file on "local connect" and "local
; disconnect" respectively.
; ------
; Configurable options' default values:
global g_BG_colour := "FF1111" ; Background/window colour
global g_FG_colour := "Green" ; Foreground/text colour
global g_BlinkPeriod:= 0 ; Blink period in seconds
global g_Message := "Go to bed!`n$TIME" ; Message to show in windows
global g_Pause_in_s := 60 ; Time for the windows to stay up, in s
global g_Stubborn := false ; "Stubborn" setting
global g_Text_size := 180 ; Text font size
; ------
#SingleInstance force ; Cancel any copies of this script already running
global g_WindowArray := [] ; array of window IDs
global g_TextCtrlIDArray := [] ; array of text control IDs
global g_NumMonitors ; number of monitors
global g_LoopCount = 0 ; loop counter used for timing
global g_TitleString ; text drawn in the windows' title bars
global g_WindowString ; text drawb in the windows
global g_BlinkCount = 0 ; counter for blinking
; If there's a "lock.txt" file in the same directory, exit immediately.
if FileExist("lock.txt")
ExitApp ; Exit, closing all of the windows we created
; Loop over the command-line arguments and send them to SetArgs() for parsing
loop, %0%
{
param := %A_Index%
SetArgs(param)
}
SysGet, g_NumMonitors, MonitorCount ; Get the # of monitors
; Generate the window title and text strings from the provided message
GenerateStrings()
; Here's where we create the windows
Loop, %g_NumMonitors% ; Loop over the monitors
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
PopWindowName := "window" . A_Index ; Create a name for a window
TextCtrlID := "text" . A_Index ; Create name for text control
; Create the window, recording its unique ID
Gui, %PopWindowName%:New, +HwndWindowID, %g_TitleString%
g_WindowArray.Push(WindowID) ; Store the window's ID in array
g_TextCtrlIDArray.Push(TextCtrlID) ; Store text control's ID
; If the "stubborn" setting is on, force the window on top of all other
; windows, don't let it be minimized or closed, and no buttons on taskbar.
if (g_Stubborn)
Gui, +AlwaysOnTop -SysMenu -Resize +ToolWindow
Gui, Color, %g_BG_colour% ; Set window colour
Gui, font, s%g_Text_size% c%g_FG_colour% ; Set text font size and colour
; Add the text to the window
Gui, %PopWindowName%:Add, Text, v%TextCtrlID%, %g_WindowString%
; Show the window at the top left of the monitor
Gui, %PopWindowName%:Show, X%monitor_Left% Y%monitor_Top%
Gui, %PopWindowName%:Maximize ; Maximize the window
}
; Run the "TimedLoop" subroutine every 1000 ms in a new thread
SetTimer, TimedLoop, 1000, 0
; Sleep the main thread while the timed stuff runs, + 5 ms for good measure
Sleep, g_Pause_in_s * 1000 + 5
ExitApp ; Exit, closing all of the windows we created
; This subroutine is run every 1000 ms (see above). It checks that the time run
; so far hasn't exceeded the specified pause time, and runs the f'n to update
; the windows.
TimedLoop:
{
g_LoopCount++ ; increment the loop counter
if (g_LoopCount > g_Pause_in_s) ; If it's more than the specified # seconds,
ExitApp ; close the windows and exit
UpdateWindows() ;
return ;
}
; This f'n updates the windows' positions and size.
UpdateWindows()
{
; Terminate the script if the user logs out, providing an escape route.
WinGet, active_id, ID, A ; Get the ID of the "active" window
if (0 = active_id) ; If that ID is 0, i.e. there is no active window,
ExitApp ; exit the script
; If the blink period is non-0, we update that stuff
if (g_BlinkPeriod > 0)
{
g_BlinkCount++ ; Increment the counter
if (g_BlinkCount >= g_BlinkPeriod) ; If the counter reaches the period...
{
g_BlinkCount := 0 ; Reset the counter
temp := g_FG_colour ; Swap the foreground and background colours
g_FG_colour := g_BG_colour ;
g_BG_colour := temp ;
}
}
; Generate the window title and text strings from the provided message. This
; is done with each window update to keep any time displays current.
GenerateStrings()
Loop, %g_NumMonitors% ; Loop over the monitors
{
ID := g_WindowArray[A_Index] ; Get a window's ID from array
; Window's ID, with a prefix needed by some commands prepended
ID_A := "ahk_id " . g_WindowArray[A_Index]
TextID := g_TextCtrlIDArray[A_Index] ; Text control's ID from array
; If "Stubborn" is set, we move each window back to the top left of its
; monitor, and re-maximize it. We also hide the taskbar.
if (g_Stubborn)
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
; Move the window back to the top left of the monitor
WinMove, %ID_A%, , %monitor_Left%, %monitor_Top%
; Send a "maximize window" cmd to the window: 0x112 = WM_SYSCOMMAND,
; 0xF030 = SC_MAXIMIZE . We do this instead of e.g. WinMaximize()
; because of an AHK bug: AHK gets confused if window is being dragged
; while WinMaximize() is executed.
PostMessage, 0x112, 0xF030,,, %ID_A%
WinHide ahk_class Shell_TrayWnd ; Hide the taskbar
}
; Since the "blink" effect may have changed the colours, we update them
Gui, %ID%:Color, %g_BG_colour% ; Set window colour
; Set text font size and colour for window
Gui, %ID%:font, s%g_Text_size% c%g_FG_colour%
WinSetTitle, %ID_A%, , %g_TitleString% ; Set the window title
GuiControl, %ID%:Font, %TextID% ; Set font for text to match window
GuiControl, %ID%:Text, %TextID%, %g_WindowString% ; Update window text
}
}
; SetArgs() receives the command-line arguments one at a time, and parses them.
; The expected format is a single letter to specify the parameter type, followed
; by the parameter value.
SetArgs(arg)
{
StringCaseSense, Off ; The command parameters aren't case-sensitive
prefix := SubStr(arg, 1, 1) ; Get the first character in the parameter
value := SubStr(arg, 2) ; Get the rest of the parameter
if ("b" = prefix) ; background/window colour
{
g_BG_colour := value
}
else if ("f" = prefix) ; foreground/text colour
{
g_FG_colour := value
}
else if ("k" = prefix) ; blink period in seconds
{
g_BlinkPeriod := value
}
else if ("m" = prefix) ; message text
{
g_Message := value
}
else if ("p" = prefix) ; pause time in seconds
{
g_Pause_in_s := value
}
else if ("s" = prefix) ; "stubborn" setting
{
prefix := SubStr(value, 1, 1) ; get the first character of the value
if ("f" = prefix || "0" = prefix) ; see if that char is 'f' or '0'
g_Stubborn := 0
else
g_Stubborn := 1
}
else if ("t" = prefix) ; text size
{
g_Text_size := value
}
}
; GenerateStrings() generates the window title and text strings from the
; provided message string:
; converts "$TIME" to the current time
; changes "`n" to line breaks for the window text, and spaces for the window
; title
GenerateStrings()
{
FormatTime, time_stamp, , h:mm:ss tt ; Generate a string with current time
; Convert "$TIME" to the current time
message1 := StrReplace(g_Message, "$TIME", time_stamp)
; Replace "`n" with blanks for window title, line breaks for window text.
; This is a bit unobvious. If the message declared in this script has a
; "`n", that's a single character, the line break. We don't need to do
; anything with that. If the message comes from a command-line parameter,
; "`n" is two characters, which we need to change. And the string literal
; for the back-tick is *two* of them, giving "``n".
g_WindowString := StrReplace(message1, "``n", "`n")
; Having gotten the window text fixed, we use that to create the title.
g_TitleString := StrReplace(g_WindowString, "`n", " ")
}
Code: Select all
; Name: goto_bed.ahk
; Version: 3.1
; Type: AutoHotkey script
; Author: Joel Polowin, 2019 March 4
; Function: In each monitor, opens a full-screen window displaying a large
; text message, pauses, then closes all of its windows and exits. Intended
; to "nag" to get one to stop using the computer, run as a scheduled task.
; ------
; Command-line arguments
; bCOLOUR_STRING e.g. bRed, bFFD000 Background/window colour
; fCOLOUR_STRING e.g. fRed, fFFD000 Foreground/text colour
; kBLINK_PERIOD e.g. k2 Blink period in seconds, 0 = don't blink
; mMESSAGE e.g. "mSLEEPY TIME!" Message text
; pPAUSE_TIME e.g. p30 Pause time in seconds
; s[TRUE|FALSE] e.g. sTRUE "Stubborn" setting
; tTEXT_FONT_SIZE e.g. t200 Text font size
;
; Example: goto_bed.ahk p60 bFF3333 fGreen "mTIME TO SNOOZE" sTRUE
;
; These parameters are not case sensitive. For example, "p60" and "P60" do
; exactly the same thing.
;
; Either colour can be one of: Black, Silver, Gray, White, Maroon, Red, Purple,
; Fuchsia, Green, Lime, Olive, Yellow, Navy, Blue, Teal, or Aqua. Or a
; 6-digit RGB hexadecimal value; e.g., FFA022 is light orange.
;
; "Stubborn" setting: if true, will disable the "minimize" and "close" icons so
; the script can't be halted, even with the Task Manager. The script will
; halt if there are no active windows, including if the user logs out.
;
; In the message text, any instances of the string "`n" will be converted to
; line breaks. Any instances of the string "$TIME" will be converted to the
; current time showing hours and minutes; "$TIME_S" will show hours, minutes,
; and seconds. For example, message text "Go to bed!`n$TIME_S" would be drawn
; as something like:
; Go to bed!
; 10:22:05 P.M.
;
; If there is a "lock.txt" file in the same directory, the script will exit
; immediately. This lets the script be restricted to running for particular
; users when they're actually using the computer, not just signed in, using
; scheduled tasks to delete and create the file on "local connect" and "local
; disconnect" respectively.
; ------
; Configurable options' default values:
global g_BG_colour := "FF1111" ; Background/window colour
global g_FG_colour := "Green" ; Foreground/text colour
global g_BlinkPeriod:= 0 ; Blink period in seconds
global g_Message := "Go to bed!`n$TIME_S" ; Message to show in windows
global g_Pause_in_s := 60 ; Time for the windows to stay up, in s
global g_Stubborn := false ; "Stubborn" setting
global g_Text_size := 180 ; Text font size
; ------
#SingleInstance force ; Cancel any copies of this script already running
global g_WindowArray := [] ; array of window IDs
global g_TextCtrlIDArray := [] ; array of text control IDs
global g_NumMonitors ; number of monitors
global g_LoopCount = 0 ; loop counter used for timing
global g_TitleString ; text drawn in the windows' title bars
global g_WindowString ; text drawb in the windows
global g_BlinkCount = 0 ; counter for blinking
; If there's a "lock.txt" file in the same directory, exit immediately.
if FileExist("lock.txt")
ExitApp ; Exit, closing all of the windows we created
; Loop over the command-line arguments and send them to SetArgs() for parsing
loop, %0%
{
param := %A_Index%
SetArgs(param)
}
SysGet, g_NumMonitors, MonitorCount ; Get the # of monitors
; Generate the window title and text strings from the provided message
GenerateStrings()
; Here's where we create the windows
Loop, %g_NumMonitors% ; Loop over the monitors
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
PopWindowName := "window" . A_Index ; Create a name for a window
TextCtrlID := "text" . A_Index ; Create name for text control
; Create the window, recording its unique ID
Gui, %PopWindowName%:New, +HwndWindowID, %g_TitleString%
g_WindowArray.Push(WindowID) ; Store the window's ID in array
g_TextCtrlIDArray.Push(TextCtrlID) ; Store text control's ID
; If the "stubborn" setting is on, force the window on top of all other
; windows, don't let it be minimized or closed, and no buttons on taskbar.
if (g_Stubborn)
Gui, +AlwaysOnTop -SysMenu -Resize +ToolWindow
Gui, Color, %g_BG_colour% ; Set window colour
Gui, font, s%g_Text_size% c%g_FG_colour% ; Set text font size and colour
; Add the text to the window
Gui, %PopWindowName%:Add, Text, v%TextCtrlID%, %g_WindowString%
; Show the window at the top left of the monitor
Gui, %PopWindowName%:Show, X%monitor_Left% Y%monitor_Top%
Gui, %PopWindowName%:Maximize ; Maximize the window
}
; Run the "TimedLoop" subroutine every 1000 ms in a new thread
SetTimer, TimedLoop, 1000, 0
; Sleep the main thread while the timed stuff runs, + 5 ms for good measure
Sleep, g_Pause_in_s * 1000 + 5
ExitApp ; Exit, closing all of the windows we created
; This subroutine is run every 1000 ms (see above). It checks that the time run
; so far hasn't exceeded the specified pause time, and runs the f'n to update
; the windows.
TimedLoop:
{
g_LoopCount++ ; increment the loop counter
if (g_LoopCount > g_Pause_in_s) ; If it's more than the specified # seconds,
ExitApp ; close the windows and exit
UpdateWindows() ;
return ;
}
; This f'n updates the windows' positions and size.
UpdateWindows()
{
; Terminate the script if the user logs out, providing an escape route.
WinGet, active_id, ID, A ; Get the ID of the "active" window
if (0 = active_id) ; If that ID is 0, i.e. there is no active window,
ExitApp ; exit the script
; If the blink period is non-0, we update that stuff
if (g_BlinkPeriod > 0)
{
g_BlinkCount++ ; Increment the counter
if (g_BlinkCount >= g_BlinkPeriod) ; If the counter reaches the period...
{
g_BlinkCount := 0 ; Reset the counter
temp := g_FG_colour ; Swap the foreground and background colours
g_FG_colour := g_BG_colour ;
g_BG_colour := temp ;
}
}
; Generate the window title and text strings from the provided message. This
; is done with each window update to keep any time displays current.
GenerateStrings()
Loop, %g_NumMonitors% ; Loop over the monitors
{
ID := g_WindowArray[A_Index] ; Get a window's ID from array
; Window's ID, with a prefix needed by some commands prepended
ID_A := "ahk_id " . g_WindowArray[A_Index]
TextID := g_TextCtrlIDArray[A_Index] ; Text control's ID from array
; If "Stubborn" is set, we move each window back to the top left of its
; monitor, and re-maximize it. We also hide the taskbar.
if (g_Stubborn)
{
SysGet, monitor_, Monitor, %A_Index% ; Get the coords of a monitor
; Move the window back to the top left of the monitor
WinMove, %ID_A%, , %monitor_Left%, %monitor_Top%
; Send a "maximize window" cmd to the window: 0x112 = WM_SYSCOMMAND,
; 0xF030 = SC_MAXIMIZE . We do this instead of e.g. WinMaximize()
; because of an AHK bug: AHK gets confused if window is being dragged
; while WinMaximize() is executed.
PostMessage, 0x112, 0xF030,,, %ID_A%
WinHide ahk_class Shell_TrayWnd ; Hide the taskbar
}
; Since the "blink" effect may have changed the colours, we update them
Gui, %ID%:Color, %g_BG_colour% ; Set window colour
; Set text font size and colour for window
Gui, %ID%:font, s%g_Text_size% c%g_FG_colour%
WinSetTitle, %ID_A%, , %g_TitleString% ; Set the window title
GuiControl, %ID%:Font, %TextID% ; Set font for text to match window
GuiControl, %ID%:Text, %TextID%, %g_WindowString% ; Update window text
}
}
; SetArgs() receives the command-line arguments one at a time, and parses them.
; The expected format is a single letter to specify the parameter type, followed
; by the parameter value.
SetArgs(arg)
{
StringCaseSense, Off ; The command parameters aren't case-sensitive
prefix := SubStr(arg, 1, 1) ; Get the first character in the parameter
value := SubStr(arg, 2) ; Get the rest of the parameter
if ("b" = prefix) ; background/window colour
{
g_BG_colour := value
}
else if ("f" = prefix) ; foreground/text colour
{
g_FG_colour := value
}
else if ("k" = prefix) ; blink period in seconds
{
g_BlinkPeriod := value
}
else if ("m" = prefix) ; message text
{
g_Message := value
}
else if ("p" = prefix) ; pause time in seconds
{
g_Pause_in_s := value
}
else if ("s" = prefix) ; "stubborn" setting
{
prefix := SubStr(value, 1, 1) ; get the first character of the value
if ("f" = prefix || "0" = prefix) ; see if that char is 'f' or '0'
g_Stubborn := 0
else
g_Stubborn := 1
}
else if ("t" = prefix) ; text size
{
g_Text_size := value
}
}
; GenerateStrings() generates the window title and text strings from the
; provided message string:
; converts "$TIME_S" and "$TIME" to the current time
; changes "`n" to line breaks for the window text, and spaces for the window
; title
GenerateStrings()
{
; Generate time strings with and without seconds
FormatTime, time_stamp_s, , h:mm:ss tt
FormatTime, time_stamp, , h:mm tt
; Convert "$TIME_S" and "$TIME" to the current time
message1 := StrReplace(g_Message, "$TIME_S", time_stamp_s)
message1 := StrReplace(message1, "$TIME", time_stamp)
; Replace "`n" with blanks for window title, line breaks for window text.
; This is a bit unobvious. If the message declared in this script has a
; "`n", that's a single character, the line break. We don't need to do
; anything with that. If the message comes from a command-line parameter,
; "`n" is two characters, which we need to change. And the string literal
; for the back-tick is *two* of them, giving "``n".
g_WindowString := StrReplace(message1, "``n", "`n")
; Having gotten the window text fixed, we use that to create the title.
g_TitleString := StrReplace(g_WindowString, "`n", " ")
}
Return to “Scripts and Functions (v1)”
Users browsing this forum: No registered users and 77 guests