Code: Select all
#NoEnv
#SingleInstance Force
SetTitleMatchMode, 2
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
; updated 10-17-2021
;!+w:: Alt+Shift+w but gets called from master script.
!^+w:: ; Alt+Ctrl+Shift+w
closeMode := "Return"
;==========Read from Settings file========
; Add one to toggle 'direct run' vs 'externally called'??
; Add one for list sort order??
iniread, varVisualMode, mtFiles\Settings.ini, MainSettings, VisualSendMode
iniread, varFaveEditor, mtFiles\Settings.ini, MainSettings, FaveEditor
iniread, varTargetWins, mtFiles\Settings.ini, MainSettings, PreferredTargetWins
iniread, varForcePref, mtFiles\Settings.ini, MainSettings, ForceUseOfPreferred
;=========================================
WinGetActiveTitle, myWinTarget ; Get name of active Window so we can wait for it later.
WinGetPos, X, Y, W, H, A ; "A" to get the active window's pos.
X := X + (W * 0.05) ; Use these with GUI Show, below.
Y := Y + (H * 0.2)
ControlGetFocus, fieldFocus, A
If InStr(fieldFocus, "edi") || If RegExMatch(myWinTarget, varTargetWins) ; Colorizes name of active window, label.
{
TextColor := "green"
iniread, varColor, mtFiles\Settings.ini, MainSettings, GUIcolor
}
else
{
TextColor := "red"
iniread, varColor, mtFiles\Settings.ini, MainSettings, GUIwarnColor
}
Menu, Tray, Icon, mtFiles\Swissknife2021.ico
Gui, Destroy
gui, color, %varColor%
Gui, -MinimizeBox +alwaysOnTop
Gui, Font, s11
Gui, Add, Edit, x14 y8 w220 h25 vStudentName, Student ; Box to type in name.
Gui, Add, Radio, xs y40 w80 h20 vGender checked, &Male ; Radio group for gender.
Gui, Add, Radio, xp+80 y42 w80 h20 , &Female
Gui, Add, Radio, xp+80 y42 w80 h20 , &Neutral
Gui, Font, s9
Gui Add, Text, x257 y6 w120 h120 +wrap c%TextColor%, ~Target Window~ %myWinTarget%
Gui, Font, s11
Gui Add, Tab3, x12 y64 vCurrTab, Notices|Tests ; |Tools
Gui Tab, 1 ;====Notices==========================================================
IniRead, AllSchools, mtFiles\SchoolList.ini ; Gets `n-delimited list from ini file.
AllSchools := StrReplace(AllSchools,"`n","|",SchRows) ; Must|convert|to|this.
SchRows++ ; The number of strReplacements +1
Gui, Add, ListBox, r%SchRows% w330 vSchChoice Choose1, %AllSchools%
AllNotices := ""
IniRead, AllNotices, mtFiles\NoticeDefinitions.ini
AllNotices := StrReplace(AllNotices,"`n","|",NoteRows)
NoteRows++
;Gui, Add, ListBox, r%NoteRows% w330 sort vNoteChoice gDblClick, %AllNotices%
Gui, Add, ListBox, r%NoteRows% w330 vNoteChoice gDblClick Choose1, %AllNotices% ; Removed sort
Gui, Add, Button, w65 h30 Section, Insert
Gui, Add, Button, ys x+5 w60 h30, Schools
Gui, Add, Button, ys x+5 w60 h30, Notices
Gui, Add, Button, ys x+5 w30 h30, Ψ
Gui, Add, Button, ys x+5 w60 h30, Esc
Gui Tab, 2 ;====Tests======================================================
IniRead, MySuffixes, mtFiles\TestSuffixes.ini
MySuffixes := StrReplace(MySuffixes,"`n","|")
Gui, Add, ComboBox, w240 vSuffChoice Choose1, %MySuffixes%
IniRead, MySuffixes, mtFiles\TestSuffixes.ini ; Deactivated with below checkbox and TogSub subroutine.
MySuffixes := StrReplace(MySuffixes,"`n","|")
Gui, Add, ComboBox, w240 vSuffsubChoice Disabled, %MySuffixes%
AllTests := ""
IniRead, AllTests, mtFiles\TestBank.ini
AllTests := StrReplace(AllTests,"`n","|",TestRows)
TestRows++
Gui, Add, ListBox, r%TestRows% w330 sort vTestChoice gDblClick Choose1, %AllTests%
Gui, Add, Button, w65 h30 Section, Insert
Gui, Add, Button, ys x+5 w60 h30, Suffix
Gui, Add, Button, ys x+5 w60 h30, Tests
Gui, Add, Button, ys x+5 w30 h30, Ψ
Gui, Add, Button, ys x+5 w60 h30, Esc
Gui, Font, s9
Gui Add, CheckBox, x275 y113 h22 vTogVar gTogSub Checked, link them ; Activates below GoSub "TogSub."
Gui Add, Text, x275 y95 h22 +0x200, Composites
Gui Add, Text, x275 y130 h19 +0x200, Sub Scales
Gui, Font, s11
;~ Gui Tab, 3 ;=====Tools===================================================
;~ Gui, Add, Text, +wrap w330, Hello World. Great things planned for this spot. Many great things....
;~ Gui, Add, Button, w60 h30, Esc
Gui Tab ;=====End of Tabs================================================
Gui Show, x%X% y%Y%, MultiTool
Return
TogSub: ; In Tests Tab, disables subTest comboBox.
Gui, Submit, NoHide
If (TogVar = 0)
GuiControl, Enable, SuffsubChoice
Else If (TogVar = 1)
GuiControl, Disable, SuffsubChoice
Return
ButtonEsc:
GuiEscape:
GuiClose:
If (closeMode != "Return")
ExitApp
else
{
Gui, Hide
Return
}
;ExitApp
DblClick:
IfNotEqual A_GuiControlEvent,DoubleClick
Return
Else
ButtonInsert:
Gui, Submit
MyEntry := ""
IfEqual, CurrTab, Notices ; Checks which tab is being used.
IniRead, MyEntry, mtFiles\NoticeDefinitions.ini, %NoteChoice% ; From notice type, goes back to INI, gets notice content.
IfEqual, CurrTab, Tests
IniRead, MyEntry, mtFiles\TestBank.ini, %TestChoice%, ; Gets content about test. Puts in MyEntry.
;OOOOOOOOOOOOOOOOOOOOOOOOOO check for sub GUI options OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
if !RegExMatch(MyEntry, "s)\R\V*\boptional\b\V*=\R")
{
MsgBox This means regex 'optional' not found, so gosub continue.
goSub, ContinueScript
}
MsgBox and THIS means that the script kept going anyway.
IfEqual, CurrTab, Notices
entrylbl = %NoteChoice% ; Merely used in the Gui label
IfEqual, CurrTab, Tests
entrylbl = %TestChoice%
TopOfLoop:
RegExMatch(MyEntry, "s)\R(\V*\boptional\b\V*=)\R(.+?)\R*(\V+=\V*(\R|$)|$)", outVar) ; Teadrinker regex.
theKey = %outVar1%
theList = %outVar2%
vPun = 0
If InStr(theKey, "radio") ; Determine if Radio Buttons are desired.
{
vRad = 1
guiType := "Radio"
}
else
{
vRad = 0
guiType := "Checkbox"
}
If InStr(theKey, "punctuat") ; Determine if the items should get x, y, and z; or just x y z.
vPun = 1
myOptions=
IfEqual, vPun, 1
mylbl := " or more (punctuated) items." ; Merely used in the Gui label
else IfEqual, vRad, 1
mylbl := " option item."
else
mylbl := " or more items."
Gui, +Owner
Gui, o:Destroy
Gui, o:-MinimizeBox +alwaysOnTop
Gui, o:Add, Text, c%TextColor% ,For [%entrylbl%]`nSelect one%mylbl%
Loop, Parse, theList, `n,`r ; Parses list.
{
fchar := SubStr(A_LoopField, 1, 1)
If fchar is Number
item := SubStr(A_LoopField, 3, 99)
else
item := A_LoopField
;MsgBox, fchar: %fchar%`nitem : %item%
Gui, o:Add, %guiType%, Checked%fchar% vCheckbox%a_index%, %item% ;Dynamically make one per item.
}
Gui, o:Add, Button, default xm w50 gMyOpts, Use
Gui, o:Add, Button, yp x+5 w50 gCancelOpts, Cancel
Gui, o:Show,x%X% y%Y% , Option Items
Return
MyOpts: ; Go here when user clicks Use button.
Gui, o:Submit
vCount=
Loop, parse, theList, `n
{
fchar := SubStr(A_LoopField, 1, 1)
If Checkbox%a_index% <> 0
{
vCount = %a_index%
If fchar is Number
item := SubStr(A_LoopField , 3, 9999)
else
item := A_LoopField
IfEqual, CurrTab, Notices
{
IfEqual, vPun, 1
myOptions = %myOptions%, %item%
else
myOptions = %myOptions% %item%
}
else
myOptions = %myOptions%`n%item% ; If currTab is Tests, keep list as a list
}
}
IfEqual, vPun, 1
{ ; If punctuation was used, chop first comma, then insert "and" before last item.
myOptions := SubStr(myOptions, 3, 999999)
IfEqual, vCount, 2 ; If there were exactly 2 items checkmarked, just use "and."
myOptions := StrReplace(myOptions,", " . item," and " . item)
myOptions := StrReplace(myOptions,", " . item,", and " . item) ; Otherwise, Oxford comma.
}
MyEntry := StrReplace(MyEntry, theList, " " . myOptions,, 1)
MyEntry := StrReplace(MyEntry, theKey, "",, 1) ; Only replace first occurrence.
If RegExMatch(MyEntry, "s)\R\V*\boptional\b\V*=\R", "") ;Options key found in expansion text.
gosub, TopOfLoop ; If found, run this section again.
Else
Gosub, ContinueScript ; If they've all been replaced, continue below.
Return
CancelOpts: ; If users presses "Cancel" then exit the whole app.
If (closeMode != "Return")
ExitApp
else
{
Gui, o:Hide
Return
}
;ExitApp
;OOOOOOOOOOOOOOOOOOOO end of options OOOOOOOOOOOOOOOOOOOO
ContinueScript:
IniRead, MyContactInfo, mtFiles\SchoolList.ini, %SchChoice%, ContactInfo ; From school choice, gets contact info.
IniRead, MySchPhone, mtFiles\SchoolList.ini, %SchChoice%, SchPhone
MyEntry := StrReplace(MyEntry,"[c]",MyContactInfo)
MyEntry := StrReplace(MyEntry,"[p]",MySchPhone)
IfEqual, CurrTab, Notices
{
MyEntry =`n%MyEntry% ; Adds an new-line at beginning so below regex will work.
MyEntry := RegExReplace(MyEntry,"(\n)+[ a-zA-Z0-9]+=") ; Removes all Key names from notice definitions.
;MyEntry := RegExReplace(MyEntry,"(\n)+[ a-zA-Z0-9,/&+.\-#]+=") ; Removes Key names + special chars.
StringReplace, MyEntry, MyEntry,`n, , All ; Gets rid of any leftover newline chars.
}
IfEqual, CurrTab, Tests
{
ifNotEqual, SuffChoice, ; Only gets Suffix Description if comboBox is not empty.
IniRead, MySuffDesc, mtFiles\TestSuffixes.ini, %SuffChoice%
MyEntry := StrReplace(MyEntry,"[sd]",MySuffDesc)
MyEntry := StrReplace(MyEntry,"[co]",SuffChoice A_Space) ; "co" for "composite score"
MyEntry := RegExReplace(MyEntry,"(\n)+[ a-zA-Z0-9]+=") ; Removes all Key names from notice definitions.
If (TogVar = 0)
MyEntry := StrReplace(MyEntry,"[su]",SuffsubChoice A_Space) ; "su" for "sub scale"
Else If (TogVar = 1)
MyEntry := StrReplace(MyEntry,"[su]",SuffChoice A_Space)
}
IfEqual, Gender, 1 ; Checks the results of the gender radio buttons group and assigns variables.
{
varHeShe = he
varHimHer = him
varHisHer = his
varHisHers = his
}
IfEqual, Gender, 2
{
varHeShe = she
varHimHer = her
varHisHer = her
varHisHers = hers
}
IfEqual, Gender, 3
{
varHeShe = they
varHimHer = them
varHisHer = their
varHisHers = theirs
}
MyEntry := StrReplace(MyEntry,"[n]",StudentName) ; Makes the replacements.
MyEntry := StrReplace(MyEntry,"[e]",varHeShe) ; Gender pronouns.
MyEntry := StrReplace(MyEntry,"[m]",varHimHer)
MyEntry := StrReplace(MyEntry,"[s]",varHisHer)
MyEntry := StrReplace(MyEntry,"[r]",varHisHers)
MyEntry := StrReplace(MyEntry,"!","{!}") ; These special characters need {braces} to type correctly.
MyEntry := StrReplace(MyEntry,"#","{#}")
MyEntry := StrReplace(MyEntry,"+","{+}")
MyEntry := StrReplace(MyEntry,"^","{^}")
IfEqual, Gender, 3 ; This part gets skipped if gender = male or female.
{
MyEntry := StrReplace(MyEntry,"they is","they are") ; Fix gramar if gender neutral.
MyEntry := StrReplace(MyEntry,"they has","they have")
;-----I don't like the two below. I think "themself" is acceptable... Uncomment if you'd like this change to be made.
;MyEntry := StrReplace(MyEntry,"themself","themselves")
;MyEntry := StrReplace(MyEntry,"theirself","theirselves")
;-----EXPERIMENTAL! will the two below cause grammar mistakes? They are intended to look for plural words that follow "they" and make them singular. For example "They needs help" is changed to "They need help."
MyEntry := RegExReplace(MyEntry, "([Tt]hey\s)(.*?)ies\b", "$1$2y")
MyEntry := RegExReplace(MyEntry, "([Tt]hey\s)(.*?)s\b", "$1$2")
}
MyEntry := RegExReplace(MyEntry, "^\w|(?:\.|:)\s+\K\w", "$U0") ; Makes sure most sentences are capitalized.
gui, Hide
;MsgBox at bottom... color is |%TextColor%|`nforce is |%varForcePref%|`nmyWinTarg is |%myWinTarget%|
If (TextColor = "red" AND varForcePref = 1)
{
MsgBox, TEXT SENT:`n`n%MyEntry%
}
else
{
winwaitactive, %myWinTarget% ; Wait for the previously active Window.
; Types notice or test into text field(s)
ifEqual, varVisualMode, 1
Send %MyEntry%
else
SendInput %MyEntry%
}
;========= Notes about SEND modes ============
;SendInput is faster but you can't see progress of typing.
;Send is the same as SendEvent. It is more visual but prone to errors.
;SendPlay doesn't seem to work... Maybe because UAC is active.
If (closeMode != "Return")
ExitApp
Return
;ExitApp
;========= Other Buttons go to here if clicked ===============
ButtonSchools:
run, %varFaveEditor% "%A_ScriptDir%\mtFiles\SchoolList.ini",, UseErrorLevel
If ErrorLevel
run, mtFiles\SchoolList.ini ; If Scite is not found, will be prompted to choose default ini opener.
return
ButtonNotices:
run, %varFaveEditor% "%A_ScriptDir%\mtFiles\NoticeDefinitions.ini",, UseErrorLevel
If ErrorLevel
Run, mtFiles\NoticeDefinitions.ini
return
ButtonSuffix:
run, %varFaveEditor% "%A_ScriptDir%\mtFiles\TestSuffixes.ini",, UseErrorLevel
If ErrorLevel
run, mtFiles\TestSuffixes.ini
return
ButtonTests:
run, %varFaveEditor% "%A_ScriptDir%\mtFiles\TestBank.ini",, UseErrorLevel
If ErrorLevel
run, mtFiles\TestBank.ini
return
ButtonΨ:
run, mtSettings.exe
return