Code: Select all
;IN DEFENCE OF PROGRESS (AND SPLASHIMAGE)
;Some example scripts.
;I expanded on my Progress command example earlier.
;If there's going to be no more Progress
;command, then at least everybody in the community
;can miss it like I would miss it.
;Btw imagine how you would feel if
;MsgBox/InputBox/ToolTip/FileSelectFile/FileSelectFolder
;were taken away.
;Some of the benefits of Progress:
;- do MsgBox/Progress, InputBox/Progress, Input/Progress at the same time
;- you can change the contents/properties of the Progress window
;while it is visible, without using SetTimer
;- you can change the Static control DT flags, e.g. word wrap on/off
;see: DrawText function (Windows)
;https://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx
;- you can use DrawText to measure the necessary window size in advance
;- you can choose any font style/size
;- you can choose any background colour
;- Progress doesn't cause persistence (#Persistent),
;thus you can include scripts that use Progress in your libraries
;without side effects (cf. the Gui command)
;- I've found that I can do everything I need to do for normal scripts with either:
;MsgBox/InputBox/Progress/SplashImage/ToolTip,
;- and I've not felt particularly that anything has been *missing* that was needed
;- I've found that I don't need the Gui command apart from for full 'software' GUI scripts
;Note:
;SplashImage is useful for producing borders around windows,
;as demonstrated in one of the examples below.
;Progress can also be used to block an area of the screen,
;such as a changing timestamp on a video,
;it can also be used to preview colours to see what they will look like.
;==================================================
;list of example hotkeys:
;q:: ;Progress as a menu (e.g. Recent items)
;w:: ;get words by numbers
;e:: ;flash text with colourful background (warning: potential seizure issues)
;r:: ;change volume level (up)
;t:: ;change volume level (down)
;y:: ;view pixel maps of OCR characters
;u:: ;notify toggle status (e.g. notify toggle capslock)
;i:: ;tooltip big font
;o:: ;tooltip big font, alternative tooltip function code
;p:: ;do other things while the clock is ticking
;a:: ;do other things while the clock is ticking (temporary message)
;s:: ;do other things while the clock is ticking (turn off)
;d:: ;display date + free space
;f:: ;notification message example 1
;g:: ;notification message example 2
;h:: ;notification message example 3
;j:: ;borders around control under cursor (uses SplashImage)
;k:: ;borders around window under cursor (uses SplashImage)
;==================================================
;using Progress and Input to bring up a list of Recent items
;to select item: type in item number and press Enter
;to cancel: press Esc
q:: ;Progress as a menu (e.g. Recent items)
vLimit := 20
vPrompt := ""
VarSetCapacity(vPrompt, 100000*2)
;path of Recent folder on Windows 7
vDir1 = C:\Users\%A_UserName%\AppData\Roaming\Microsoft\Windows\Recent
if !FileExist(vDir1)
vDir1 = C:\Documents and Settings\%A_UserName%\Recent
Loop, %vDir1%\*.*, 0, 0 ;(0/1/2=files/both/folders, 0/1=recurse no/yes)
{
vPathLnk := A_LoopFileFullPath
FileGetShortcut, % vPathLnk, vPath
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
vPrompt .= "(" A_Index ") " vName "`r`n"
vPath%A_Index% := vPath
if (A_Index = 20)
break
}
Progress, zh0 b c0 fs18 w600, % vPrompt
Input, vNum, L3 T8 M, {Enter}{Esc}
vRet := ErrorLevel
Progress, Off
if InStr(vRet, "EndKey:Enter")
&& RegExMatch(vNum, "^\d+$") ;'is digit'
&& (vNum >= 1) && (vNum <= vLimit)
&& FileExist(vPath%vNum%)
{
MsgBox, 3, , % vPath%vNum% "`r`n[choose Yes to open]"
IfMsgBox Yes
Run, % vPath%vNum%
}
Return
;==================================================
w:: ;get words by numbers
vList := "retain retaken retaliation retardation retention reticulation retighten retorn retraction retrain retransformation retranslation retransmission retribution retroaction retrocession retrodden retroflection retrogression retrospection retroversion retune return"
vPrompt := ""
Loop, Parse, vList, % A_Space
{
vPrompt .= A_Index "-" A_LoopField " "
vOpt%A_Index% := A_LoopField
}
vFormat := "zh0 b1 c0 fs18 w1000 y25"
Progress, % vFormat, % vPrompt
InputBox, vItem, , , , , 100
Progress, Off
MsgBox % vOpt%vItem%
Return
;==================================================
;04:50 25/02/2017
e:: ;flash text with colourful background (warning: potential seizure issues)
;e.g. yellow/green/yellow/green, 800 millisecond gap
vList := "FF0000,FFFF00,00FF00,0000FF"
vList := "FFFF00,00FF00"
vList .= "," vList
Loop, Parse, vList, `,
{
vCol := A_LoopField
;vFormat := "zh0 b1 c0 fs18 cw" vCol
vFormat := "zh0 b1 fs18 cw" vCol
vText := "`r`nnew AutoHotkey update available`r`n"
Progress, % vFormat, % vText
Sleep 800
Progress, Off
}
Return
;==================================================
r:: ;change volume level (up)
t:: ;change volume level (down)
;if (A_TimeIdle > 200)
; Return
SoundGet, vNum
vNum := Round(vNum) ;remove decimal part
vDiff := 10
if InStr(A_ThisHotkey, "r")
{
vNum += vDiff
if (vNum+vDiff > 100)
vNum := 100
}
if InStr(A_ThisHotkey, "t")
{
vNum -= vDiff
if (vNum-vDiff < 0)
vNum := 0
}
SoundSet, % vNum
Progress, zh0 b fs18 w70, % vNum
Sleep 300
Progress, Off
SoundBeep
Return
;==================================================
y:: ;view pixel maps of OCR characters
vText = ;continuation section
(
### # # ### ### # # ### ### # # ### # #
# # # # # # # # # # # # # # # # #
### # # # # # ### # # # ## ### ###
# # # # # # # # # # # # # # # #
# # ### # ### # # ### # # # ### #
)
;vText := StrReplace(vText, "#", "@")
;vText := StrReplace(vText, "#", "|")
;vText := StrReplace(vText, "#", "-")
;vText := StrReplace(vText, "#", "\")
;vText := StrReplace(vText, "#", "0")
;vText := StrReplace(vText, "#", "1")
;vText := StrReplace(vText, "#", "H")
;vText := StrReplace(vText, "#", "~")
;vText := StrReplace(vText, "#", "▓") ;Chr(9619)
vText := StrReplace(vText, "#", "█") ;Chr(9608)
Progress, zh0 b c0 fs24 w1000, % vText, , , Courier New
Sleep 1000
Progress, Off
Return
;==================================================
u:: ;notify toggle status (e.g. notify toggle capslock)
vFormat := "zh0 b1 c0 fs18 x1000 y100 w150"
Loop
{
vState := GetKeyState("CapsLock", "T") ? "on" : "off"
if !(vState = vState2)
Progress, %vFormat%, capslock %vState%
vState2 := vState
Sleep 100
}
Return
;==================================================
i:: ;tooltip big font
vFormat = zh0 b1 c0 fs18 ;border + left
Progress, %vFormat%, HELLO WORLD
WinGet, hWnd, ID, %A_ScriptName% ahk_class AutoHotkey2
Sleep 1000
ControlSetText, Static1, Hello World, ahk_id %hWnd%
Sleep 1000
ControlSetText, Static1, hello world, ahk_id %hWnd%
Sleep 1000
Progress, Off
Return
;==================================================
o:: ;tooltip big font, alternative tooltip function code
JEE_Progress2("AUTO", -1)
Sleep 500
Progress, Off
JEE_Progress2("AUTOHOTKEY", 500)
;vText := "AutoHotkey"
vText := "AUTOHOTKEY"
vText2 := ""
Loop, Parse, vText
{
vText2 .= A_LoopField
JEE_Progress2(vText2, 250)
}
;vText := "Au to Hot key"
vText := "AU TO HOT KEY"
vText2 := ""
Loop, Parse, vText, % A_Space
{
vText2 .= A_LoopField
JEE_Progress2(vText2, 500)
}
Return
;==================================================
;vFormat := "zh0 b c0 fs18" ;no border + left-aligned text
;vFormat := "zh0 b1 fs18" ;has border + centred text
;vFormat := "zh0 b1 c0 fs18" ;has border + left-aligned text
JEE_Progress2(vText, vSleep=500, vFormat="zh0 b1 c0 fs18")
{
global vJeeProgressFormat
if !(vJeeProgressFormat = "")
vFormat := vJeeProgressFormat
Progress, % vFormat, % vText
if (vSleep = -1)
Return
Sleep, % vSleep
Progress, Off
Return
}
;==================================================
p:: ;do other things while the clock is ticking
FormatTime, vTime, , HH:mm:ss
vFormat = zh0 b1 c0 fs18 x1000 y100 w150 ;border + left-aligned text
Progress, %vFormat%, %vTime%
SetTimer, Change_Progress, 1000
MsgBox % "a"
MsgBox % "b"
MsgBox % "c"
Return
Change_Progress:
WinGet, hWnd, ID, %A_ScriptName% ahk_class AutoHotkey2
if !hWnd
Return
FormatTime, vTime, , HH:mm:ss
if !(vTime = vTime2)
ControlSetText, Static1, %vTime%, ahk_id %hWnd%
vTime2 := vTime
Return
;==================================================
a:: ;do other things while the clock is ticking (temporary message)
SetTimer, Change_Progress, Off
ControlSetText, Static1, MESSAGE, ahk_id %hWnd%
SetTimer, Change_Progress, On
Return
;==================================================
s:: ;do other things while the clock is ticking (turn off)
SetTimer, Change_Progress, Off
Progress, Off
Return
;==================================================
d:: ;display date + free space
vDate := A_Now
FormatTime, vDate1, % vDate, ddd
FormatTime, vDate2, % vDate, HH:mm dd/MM/yyyy
DriveSpaceFree, vDriveSpaceFree, C:\
vText := vDate1 " " vDate2 "`r`n" vDriveSpaceFree " MB" "`r`n" "more info" "`r`n" "more info"
JEE_Progress2(vText, 1000)
Return
;==================================================
f:: ;notification message example 1
Progress, zh0 b1 fs10 y300, `r`nctrl+z disabled for Explorer windows`r`n, , , Tahoma
Sleep 500
Progress, Off
Return
;==================================================
g:: ;notification message example 2
vFormat := "zh0 b1 fs18" ;has border + centred text
JEE_Progress2("`r`nsave blocked`r`n", 500, "zh0 b1 fs18 w240")
Return
;==================================================
h:: ;notification message example 3
JEE_Progress2("note:`r`ncontains lone Chr(13)s", 1000)
Return
;==================================================
j:: ;borders around control under cursor (uses SplashImage)
MouseGetPos, , , hWnd
WinGetPos, vPosX, vPosY, vPosW, vPosH, A
JEE_Borders(vPosX, vPosY, vPosW, vPosH)
Return
;==================================================
k:: ;borders around window under cursor (uses SplashImage)
MouseGetPos, , , , hCtl, 3
WinGetPos, vPosX, vPosY, vPosW, vPosH, ahk_id %hCtl%
JEE_Borders(vPosX, vPosY, vPosW, vPosH)
Return
;==================================================
;show borders around a window/control/point
JEE_Borders(vPosX, vPosY, vPosW=0, vPosH=0, vTime=1000, vCol="FFFF00")
{
CoordMode, Pixel, Screen
vBorderH := 5 ;height of border
vBorderW := 5 ;width of border
SplashImage, 1:, % "B W" vPosW+(2*vBorderW) "H" vBorderH "X" vPosX-vBorderW "Y" vPosY-vBorderH "Cw" vCol, , , SP1 ;top
SplashImage, 2:, % "B W" vPosW+(2*vBorderW) "H" vBorderH "X" vPosX-vBorderW "Y" vPosY+vPosH "Cw" vCol, , , SP2 ;bottom
SplashImage, 3:, % "B W" vBorderW "H" vPosH+(2*vBorderH) "X" vPosX-vBorderW "Y" vPosY-vBorderH "Cw" vCol, , , SP3 ;left
SplashImage, 4:, % "B W" vBorderW "H" vPosH+(2*vBorderH) "X" vPosX+vPosW "Y" vPosY-vBorderH "Cw" vCol, , , SP4 ;right
Sleep % vTime
SplashImage, 1: Off
SplashImage, 2: Off
SplashImage, 3: Off
SplashImage, 4: Off
Return
}
;==================================================