Code: Select all
CapsLock::
PopupClose()
;; Delete the timer set by Popup() so it doesn't close the next popup to appear.
SetTimer PopupClose, Delete
Return
Code: Select all
;; Pop up a notification window in the lower right corner of the screen showing TEXT having TITLE.
;; TEXT is word-wrapped to fit in the fixed-width notification window unless option "nowrap" is
;; given (see below). The window's vertical position is adjusted upwards so the amount of TEXT
;; doesn't force it to extend off the bottom of the screen. OPTIONS is a comma-separated (with no
;; space around the commas) string of zero or more of the following:
;;
;; delay=N => Close the popup window in N milliseconds. If N is 0, the window is shown
;; indefinitely, until PopupClose() or another call to Popup() replaces it.
;;
;; xoffset=N => Position the popup window N pixels from the left edge of the screen. N cannot
;; be negative.
;;
;; yoffset=N => Position the popup window N pixels from the top edge of the screen. N cannot
;; be negative. This option disables auto-adjustment of the popup position to
;; prevent the window from extending off the bottom of the screen, so the caller
;; is responsible to avoid that.
;;
;; color=COLOR => Set the text color to COLOR, which must be a hex color value (e.g., 0xffeecc)
;; or a color name known to AutoHotkey.
;;
;; nowrap => Don't word-wrap long lines of TEXT. This dynamically sizes the window's width
;; to fit TEXT and TITLE. If TEXT or TITLE is too long, the window can extend
;; past the right edge of the screen. Option "xoffset" can help avoid that.
;;
;; notitle => Do not show the title and icon.
;;
;; Unrecognized options are silently ignored. Clicking on the TITLE or TEXT closes the popup.
;; Examples:
;;
;; Popup("Good morning!", "Greeting", "delay=10000,color=blue,yoffset=100")
;; Popup("Time to leave!", "Alert", "delay=0")
Popup(TEXT, TITLE := "AutoHotkey Info", OPTIONS := "")
{
;; Parse OPTIONS.
OPTIONS := "," . OPTIONS . ","
NOTITLE := InStr(OPTIONS, ",notitle,")
NOWRAP := InStr(OPTIONS, ",nowrap,")
If (RegExMatch(OPTIONS, ",delay=([0-9]+),", DELAY))
DELAY := DELAY1
Else
DELAY := 5000
If (RegExMatch(OPTIONS, ",color=([^,]+),", COLOR))
COLOR := COLOR1
Else
COLOR := "0x000000"
If (RegExMatch(OPTIONS, ",xoffset=([0-9]+),", XOFFSET))
XOFFSET := XOFFSET1
Else
XOFFSET := A_SCREENWIDTH - 310
If (RegExMatch(OPTIONS, ",yoffset=([0-9]+),", YOFFSET))
YOFFSET := YOFFSET1
If (TITLE == "")
TITLE := "AutoHotkey Info"
If (!NOWRAP)
WIDTH := "W250"
;; Count the number of lines in TEXT. This doesn't modify TEXT.
LINES := StrSplit(TEXT, "`n", "`n")
If (!YOFFSET)
{
;; The caller did not specify a Y offset, so we compute one.
YOFFSETBASE := 105
If (NOWRAP)
{
;; No word-wrapping is happening. The window is as wide as the text
;; requires. Move the window up by 15 pixels for each line of text.
YOFFSET := A_SCREENHEIGHT - YOFFSETBASE - 15 * LINES.Length()
}
Else
{
;; We have word-wrapped text in a fixed width window that is WIDTH pixels
;; wide. Set YOFFSET based on how many wrapped lines will appear.
YOFFSET := A_SCREENHEIGHT - YOFFSETBASE
For INDEX, VALUE in LINES
{
;; Move the window 15 pixels up for each line of wrapped text.
YOFFSET := YOFFSET - 15 * (StrLen(VALUE) // 46 + 1)
}
}
}
;; Create the base window.
Gui MyPopup: New
Gui MyPopup: +AlwaysOnTop +Owner -Resize -Caption +Border
Gui MyPopup: Color, 0xF9F9FB ;; Background color that matches system tray balloon.
TEXTPOSITION := ""
If (!NOTITLE)
{
;; When TITLE is shown, position the text below the icon and TITLE.
TEXTPOSITION := "X12"
;; Show TITLE to the right of a 16x16 icon.
Gui MyPopup: Add, Picture, W16 H-1 GPopupClose, %ICONSDIR%\yellow-button.ico
Gui MyPopup: Font, s11 c0x000088, Verdana
Gui MyPopup: Add, Text, R1 XP+23 YP-2 GPopupClose, %TITLE%
}
;; Create the text control showing TEXT.
Gui MyPopup: Font, s9 c%COLOR%, Segoe UI
Gui MyPopup: Add, Text, %TEXTPOSITION% %WIDTH% GPopupClose, %TEXT%
Gui MyPopup: Show, AutoSize NoActivate X%XOFFSET% Y%YOFFSET%
;; If DELAY is 0, display the popup window indefinitely. Call PopupClose() to close it.
If (DELAY == 0)
Return
;; Close the popup window DELAY milliseconds from now.
SetTimer PopupClose, -%DELAY%
}
PopupClose()
{
Gui MyPopup: Destroy
}
PopupError(TEXT)
{
Popup(TEXT, "AutoHotkey Error")
}