Pretty specific text expansion tool. -- WayText

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
kunkel321
Posts: 1118
Joined: 30 Nov 2015, 21:19

Pretty specific text expansion tool. -- WayText

Post by kunkel321 » 07 Mar 2021, 15:15

Folks are welcome to tinker about with it. The zipped folder has everything, and you should be able to run it directly from the folder.

The concepts used in the code are not really that advanced. (Though making it was a learning experience for me! LOL) Also, this thing might be too specific to my work as a school psychologist, to be very useful to the general public. The "notice" part is about typing "Prior Written Notices" into the webform database at my work place. The "test" items are for typing out the names of formal psychoeducational tests.
Other suggestions/improvements/recommendations are welcome as well.

Update 12-25-2021:
-Major Update.
-Now bundled with SciTE.
-Can be called from another script or stay in RAM and run as a stand-alone app.
-Separate GUI for settings.
-See also https://www.donationcoder.com/forum/index.php?topic=51967.0.

I'll put the code in the forum post here, but to use it, you need the INI files and the folder structure that is in the attached .zip. FYI the EXE files in the zip are not compiled versions. They are "AutoHotkey.exe" renamed. EDIT: Erhm... Sorry, but I can't attach the zip. Too big apparently. It is attached to the above-linked DonationCoder forum post.

Many thanks to the group here for all the help over the years. This project would not exsist without you guys!

Code: Select all

#NoEnv
#SingleInstance Force
SetTitleMatchMode, 2
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
; updated Dec-2021

Menu, Tray, Icon, shell32.dll, 81   ; I think this is the old "disc defrag" icon?

;==========Read from Settings file======== 
iniread, varHotkey, wtFiles\Settings.ini, MainSettings, MyHotkey
iniread, varStayInRAM, wtFiles\Settings.ini, MainSettings, StayInRAM
iniread, varVisualMode, wtFiles\Settings.ini, MainSettings, VisualSendMode
iniread, varPasteDelay, wtFiles\Settings.ini, MainSettings, PostPasteDelay
iniread, varFaveEditor, wtFiles\Settings.ini, MainSettings, FaveEditor
iniread, varTargetWins, wtFiles\Settings.ini, MainSettings, PreferredTargetWins
iniread, varForcePref, wtFiles\Settings.ini, MainSettings, ForceUseOfPreferred
iniread, varTodayAt, wtFiles\Settings.ini, schedule, %A_DDDD%
iniread, varRememberStu, wtFiles\Settings.ini, MainSettings, RememberStudent
iniread, varFontColor, wtFiles\Settings.ini, MainSettings, FontColor
iniread, varDebug, wtFiles\Settings.ini, MainSettings, Debug
;=========================================

If (varStayInRAM != 1)  ; If varStayInRAM =/= 1, then skip the hotkey and just run the tool. 
	goto, DontWait
Hotkey, %varHotkey%, DontWait

DontWait: 
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)
If (myWinTarget = "")
	Exit ; Otherwise WayText launches at Windows startup and errors because no active window. 

ControlGetFocus, fieldFocus, A
If InStr(fieldFocus, "edi") || If RegExMatch(myWinTarget, varTargetWins) ; Colorizes GUI with "warning" color.
{
	Preferred := ""
	iniread, varColor, wtFiles\Settings.ini, MainSettings, GUIcolor 
	; This is the normal color of the form.
	if (strLen(varColor) > 8)
		varColorCode := subStr(varColor, strLen(varColor) - 5, 6)
	else
		varColorCode = %varColor%
}
else
{
	Preferred := "non"
	iniread, varColor, wtFiles\Settings.ini, MainSettings, GUIwarnColor 
	; This is the Warning Color, indicating non-preferred Window.
	if (strLen(varColor) > 8)
		varColorCode := subStr(varColor, strLen(varColor) - 5, 6)
	else
		varColorCode = %varColor%
}

if (strLen(varFontColor) > 8)
	varFontColorCode := subStr(varFontColor, strLen(varFontColor) - 5, 6)
else
	varFontColorCode = %varFontColor%
	

varLastStuName := "Student" ; Remember Student = 0, so use these defaults. 
ckMale := "1"
ckFemale := "0"
ckNeutral := "0"

If (varRememberStu = 1) ; If Remember Student = 1, then overwrite the 4 above values. 
{
	iniread, varTimeStamp, wtFiles\Settings.ini, MainSettings, MemoryTimeStamp
	TimeDiff :=  A_Now - varTimeStamp ; returns number of seconds passed
	iniread, varMemoryMinutes, wtFiles\Settings.ini, MainSettings, MemoryMinutes
	varMemoryMinutes := varMemoryMinutes * 60
	If (TimeDiff < varMemoryMinutes)
	{
		iniread, varLastStuName, wtFiles\Settings.ini, MainSettings, LastStuName 
		; "Last-used" student name, not "last name" of student.
		iniread, varLastStuSchool, wtFiles\Settings.ini, MainSettings, LastStuSchool ; Returns a name.
		IniRead, AllSchools, wtFiles\SchoolList.ini ; Gets `n-delimited list from ini file.
		loop, parse, AllSchools, `n, `r
		{
			If (A_LoopField = varLastStuSchool) 
				 varTodayAt = %A_Index% ; Convert school name to digit.
				
		}
	
		iniread, varLastStuGender, wtFiles\Settings.ini, MainSettings, LastStuGender
		If (varLastStuGender = "2")
		{
			ckFemale := "1"
			ckMale := "0"
		}
		If (varLastStuGender = "3")
		{
			ckNeutral := "1"
			ckMale := "0"
		}
	}		
}	

Gui, Destroy
Gui, font, c%varFontColorCode%
gui, color, %varColorCode%
Gui, -MinimizeBox +alwaysOnTop
Gui, Font, s11 
Gui, Add, Edit, x14 y8 w220 h25 vStudentName cBlack, %varLastStuName%  ; Box to type in name.
Gui, Add, Radio, xs y40 w60 h20 vGender checked%ckMale%, &Male ; Radio group for gender.
Gui, Add, Radio, xp+60 y40 w80 h20 checked%ckFemale%, &Female 
Gui, Add, Radio, xp+78 y40 w80 h20 checked%ckNeutral%, &Neutral
Gui Add, Text, x240 y6 w138 h125 +wrap, --- Target Window ---`n %myWinTarget% 
; Identify which window will get typed into. 
Gui Add, Tab3, x12 y64 0x400 vCurrTab, Notices|Tests ; The tabs.  

Gui Tab, 1 ;###### Notices ##########################################################

IniRead, AllSchools, wtFiles\SchoolList.ini ; Gets `n-delimited list from ini file.
If (!AllSchools) ; If file not found, use below error statement.
	AllSchools := "'SchoolList' file not found."
AllSchools := StrReplace(AllSchools,"`n","|",SchRows) ; Must|convert|to|this.
SchRows++  ; The number of strReplacements +1.  The ListBox will be this high.
Gui, Add, ListBox, r%SchRows% w330 vSchChoice cBlack Choose%varTodayAt%, %AllSchools%

AllNotices := ""
IniRead, AllNotices, wtFiles\NoticeDefinitions.ini 
If (!AllNotices)
	AllNotices := "'NoticeDefinitions' file not found."
AllNotices := StrReplace(AllNotices,"`n","|",NoteRows) 
NoteRows++
;Gui, Add, ListBox, r%NoteRows% w330 sort vNoteChoice gDblClick, %AllNotices%
Gui, Add, ListBox, r%NoteRows% w330 vNoteChoice gDblClick cBlack Choose1, %AllNotices% ; Removed sort

Gui, Add, Button, w70 h30 Section, Insert
Gui, Add, Button, ys x+5 w70 h30, Schools
Gui, Add, Button, ys x+5 w70 h30, Notices
Gui, Add, Button, ys x+5 w30 h30, Ψ
Gui, Add, Button, ys x+5 w70 h30, Esc

Gui Tab, 2 ;###### Tests ############################################################

IniRead, MySuffixes, wtFiles\TestSuffixes.ini
If (!MySuffixes)
	MySuffixes := "'TestSuffixes' file not found."
MySuffixes := StrReplace(MySuffixes,"`n","|")  		
Gui, Add, ComboBox, w240 vSuffChoice cBlack Choose1, %MySuffixes%

IniRead, MySuffixes, wtFiles\TestSuffixes.ini 
; Deactivated with below checkbox and TogSub subroutine. 
MySuffixes := StrReplace(MySuffixes,"`n","|")  		
Gui, Add, ComboBox, w240 vSuffsubChoice cBlack Disabled, %MySuffixes%

AllTests := ""
IniRead, AllTests, wtFiles\TestBank.ini
If (!AllTests)
	AllTests := "'TestBank' file not found."
AllTests := StrReplace(AllTests,"`n","|",TestRows) 
TestRows++
Gui, Add, ListBox, r%TestRows% w330 sort vTestChoice gDblClick cBlack Choose1, %AllTests%

Gui, Add, Button, w70 h30 Section, Insert
Gui, Add, Button, ys x+5 w70 h30, Suffix
Gui, Add, Button, ys x+5 w70 h30, Tests
Gui, Add, Button, ys x+5 w30 h30, Ψ
Gui, Add, Button, ys x+5 w70 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 ;############################################################################

Gui Show, x%X% y%Y%, WayText  ; Position form based on coordinates obtained above. 
Return

TogSub: ; In Tests Tab, disables/enables subTest comboBox.
Gui, Submit, NoHide
If (TogVar = 0)
	GuiControl, Enable, SuffsubChoice
Else If (TogVar = 1)
	GuiControl, Disable, SuffsubChoice	
Return

ButtonEsc:
GuiEscape:
GuiClose:
If (varStayInRAM != 1)
 ExitApp
else
{
	Gui, Hide
	Exit
}

DblClick:
	IfNotEqual A_GuiControlEvent,DoubleClick ; Ignore double-clicks unless it was on a list item. 
Return
	Else
ButtonInsert:
Gui, Submit

If (varRememberStu = 1) ; Should we remember the student information?
{
	iniWrite, %A_Now%, wtFiles\Settings.ini, MainSettings, MemoryTimeStamp
	iniWrite, %StudentName%, wtFiles\Settings.ini, MainSettings, LastStuName
	iniWrite, %Gender%, wtFiles\Settings.ini, MainSettings, LastStuGender
	iniWrite, %SchChoice%, wtFiles\Settings.ini, MainSettings, LastStuSchool 
}

MyEntry := ""
IfEqual, CurrTab, Notices ; Checks which tab is being used.
	IniRead, MyEntry, wtFiles\NoticeDefinitions.ini, %NoteChoice%  ; From notice type, goes back to INI, gets notice content.

IfEqual, CurrTab, Tests
	IniRead, MyEntry, wtFiles\TestBank.ini, %TestChoice%, ; Gets content about test. Puts in MyEntry.

If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
    msgbox,, First check, Entry has been obtained we will 
	 ,now check for INI Key Names with Options:`n`n |%MyEntry%|


; "s)\R(\V*\bpaste\b\V*=)(.+?)(\V+=\V*($)|$)"  If key has "paste" in it, and key val has no new lines. 
;OOOOOOOOOOOOOOOOOOOOOOOOOO check for sub GUI options OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

if !RegExMatch(MyEntry, "s)\R\V*\bOptional\b\V*=\R")	; Check for any keys with "Optional" in key name. 
	goSub, ContinueScript								; If not, skip this whole section.
else
{		; The matching } is 100 lines down. 
	IfEqual, CurrTab, Notices
		entrylbl = %NoteChoice% ; Merely used in the Gui label
	IfEqual, CurrTab, Tests
		entrylbl = %TestChoice%

	TopOfLoop: ; Script comes back here until there are no more key names with "optional." 
   
If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
    msgbox,, Check at top of 'option' loop, At least one Option key has 
	 ,been found.`n`nLoop number: %A_Index% `n`n |%MyEntry%|   
    
    
	RegExMatch(MyEntry, "s)\R(\V*\bOptional\b\V*=)\R(.+?)\R*(\V+=\V*(\R|$)|$)", outVar)  ; Teadrinker's regex.
	theKey = %outVar1%
	theList = %outVar2%
	vPun = 0 ; By default, assume there is no punctuation needed. 

	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 ; Ensures that only one instance of the miniform occurs at a time. 
	Gui, o:-MinimizeBox +alwaysOnTop
	Gui, o:font, c%varFontColorCode% s11
	gui, o:color, %varColorCode%
	Gui, o:Add, Text, ,For [%entrylbl%]`nSelect one%mylbl%
	Loop, Parse, theList, `n,`r  ; Parses list.
		{
			fchar := SubStr(A_LoopField, 1, 1)
			If fchar is Number ; Get first char and see if it's a digit.
				item := SubStr(A_LoopField, 3, 99) ; If so, chop first 2 chars. 
			else
				item := A_LoopField ; If not a digit, use entire line. 
				If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
					MsgBox,, Checking Optional Item, In preparation for displaying the mini gui.
					,The first character is: |%fchar%|`n`nFor item: |%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
    If (guiType = "Checkbox") { ; Only add these buttons if it's checkboxes.
        Gui, o:Add, Button, yp x+5 w50 gAll, All
        Gui, o:Add, Button, yp x+5 w50 gNone, None
    }
	Gui, o:Add, Button, yp x+5 w50 gCancelOpts, Cancel
	Gui, o:Show,x%X% y%Y% , Option Items ; Show miniform at same location as main MutliTool form.
	Return
    
    All: ; From Select "All" button of mini form.
    Gui, o:Submit, NoHide
    WinGet, list, ControlList
	For each, control in StrSplit(list, "`n")
		 GuiControl,,Checkbox%A_Index%,1
    return
    None: ; From Select "None" button of mini form.
    Gui, o:Submit, NoHide
    WinGet, list, ControlList
	For each, control in StrSplit(list, "`n")
		 GuiControl,,Checkbox%A_Index%,0
    return
    
	MyOpts: ; Go here when user clicks "Use" button.
	Gui, o:Submit
	vCount= ; Need this var for puntuation.
	Loop, parse, theList, `n
		{
			fchar := SubStr(A_LoopField, 1, 1)
			If Checkbox%a_index% <> 0 ; The unchecked ones will be zero.
			{
				vCount = %a_index%
				If fchar is Number ; Again, if 1st char is digit, chop 1st two. 
					item := SubStr(A_LoopField , 3, 9999)
				else
					item := A_LoopField ; Otherwise, use whole line.
				IfEqual, CurrTab, Notices
				{
					IfEqual, vPun, 1 ; If Puncuation flag found, separate with comma
						myOptions = %myOptions%, %item%
					else
						myOptions = %myOptions% %item%
				}
				else
					myOptions = %myOptions%`n%item%  ; If currTab is Tests, keep list as a list.
			}
			If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
				MsgBox,, Bottom of opts loop, Loop number %A_Index% `nOne loop per item to append the 
				,selected ones.`nvariable is:`n|%myOptions%|
		}
	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 get rid of first 'Optional' key.

	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 ...
	If (varStayInRAM != 1)
	 ExitApp ; If 'Stay in RAM' set to 0, total exit.
	else
	{
		Gui, o:Hide  ; If 'Stay in RAM' set to 1, close form, but stay in memory.
		Exit
	}
} ; This brace closes the "else" 100 lines up. 
;OOOOOOOOOOOOOOOOOOOO end of options OOOOOOOOOOOOOOOOOOOO

ContinueScript:
If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
    msgbox,, Past Optional loop, All Optional keys have been resolved.  Next is [r]eplacments.`n`n %MyEntry%
IniRead, MyContactInfo, wtFiles\SchoolList.ini, %SchChoice%, ContactInfo ; From school choice, gets contact info.
IniRead, MySchPhone, wtFiles\SchoolList.ini, %SchChoice%, SchPhone
MyEntry := StrReplace(MyEntry,"[c]",MyContactInfo) 
MyEntry := StrReplace(MyEntry,"[p]",MySchPhone)

IfEqual, CurrTab, Tests
{
	ifNotEqual, SuffChoice, ; Only gets Suffix Description if comboBox is not empty.
		IniRead, MySuffDesc, wtFiles\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
	If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
    msgbox Gender is Neutral so several gramar fixes will be attempted.  Each sentence will go through a series of gramar checks. 
}

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)

If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
    msgbox,, Below pronouns, Name and Pronoun replacements have been made. [n] [e] [m] [s] [r]`n`n %MyEntry%

MyEntry := StrReplace(MyEntry,"!","{!}") ; These special characters need {braces} to type correctly.
MyEntry := StrReplace(MyEntry,"#","{#}")
MyEntry := StrReplace(MyEntry,"+","{+}")
MyEntry := StrReplace(MyEntry,"^","{^}")

if instr(MyEntry, "{clipboard}") ; Look for clipboard flag and insert clipboard contents if present.
{
	myClipContent = %clipboard%
	myEntry := StrReplace(MyEntry, "{clipboard}", myClipContent)
}

if instr(MyEntry, "{now,")  ; Look for datestamp tag and insert if needed.  
{
RegExMatch(MyEntry, "{now, ?(.+?)}", DateFormat)
FormatTime, MyDate, %A_Now%, %DateFormat1%
MyEntry := strReplace(MyEntry, DateFormat, MyDate)
}

IfEqual, Gender, 3 ; This part gets skipped if gender = male or female.
{
	If InStr(MyEntry, "they ")
	{
		MyEntry := StrReplace(MyEntry,"they is","they are") ; Fix gramar if gender neutral.
		MyEntry := StrReplace(MyEntry,"they's","they are") ; Can break with "he's done that."
		MyEntry := StrReplace(MyEntry,"they has","they have")
		MyEntry := StrReplace(MyEntry,"they was","they were")
		;-----EXPERIMENTAL! will the loop below cause grammar mistakes? It is intended to look for 
		;plural words that follow "they" and make them singular.  For example "They needs help" 
		;is changed to "They need help."  
		loop, parse, myEntry, "." 
		{
			;preSeg = %A_LoopField%
			if (regexmatch(A_LoopField, "s)((T|t)hey\s\w*)ies\b"))
				segment := RegExReplace(A_LoopField, "s)((T|t)hey\s\w*)ies\b", "$1y") 
			Else if (regexmatch(A_LoopField, "s)((T|t)hey\s\w*ly\s\w*(s|z|sh|ch|x|o))es\b"))
				segment := RegExReplace(A_LoopField, "s)((T|t)hey\s\w*ly\s\w*(s|z|sh|ch|x|o))es\b", "$1") 
			Else if (regexmatch(A_LoopField, "s)((T|t)hey\s\w*(s|z|sh|ch|x|o))es\b"))
				segment := RegExReplace(A_LoopField, "s)((T|t)hey\s\w*(s|z|sh|ch|x|o))es\b", "$1")
			Else if (regexmatch(A_LoopField, "s)((T|t)hey\s\w*ly\s\w*)s\b"))
				segment := RegExReplace(A_LoopField, "s)((T|t)hey\s\w*ly\s\w*)s\b", "$1") 
			Else if (regexmatch(A_LoopField, "s)((T|t)hey\s\w*)s\b"))
				segment := RegExReplace(A_LoopField, "s)((T|t)hey\s\w*)s\b", "$1") 
			else 
				segment = %A_LoopField%
			combined = %combined% %segment%.
			;MsgBox |%preSeg%|`n|%segment%|`n`n%combined%
			MyEntry := RegExReplace(combined, "D)\Q. .\E$", ".") 
			; Gets rid of that extra dot that's caused by the last parse loop. 
		}
	}
} ; End of gender gramar fixes.

MyEntry := RegExReplace(MyEntry, "^\w|(?:\.|:)(\s|\R|\Q{Enter}\E)+\K\w", "$U0") ; Makes sure most sentences are capitalized.

MyEntry := StrReplace(MyEntry, "`n`n", "`n") ; Get rid of duplicate new lines. Is this even needed?
gui, Hide  ; GUI is already hidden at this point..??
	; If shift key is held down, OR nonpreferred+setting use MsgBox.

If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
    msgbox After getting rid of extra lines.`n`n %MyEntry%

If (GetKeyState("Shift", "P")) || If (Preferred = "non" AND varForcePref = 1) 
{
	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.
	IfNotEqual, CurrTab, Tests
        StringReplace, MyEntry, MyEntry,`n, , All ; Gets rid of any leftover newline chars.	
   MsgBox,, Text Sent by WayText, %MyEntry%
}
else ; Normal state:  We'll paste or type.
{
    ifEqual, varVisualMode, 1
        SendMode Event 	;Send is the same as SendEvent. It is more visual but prone to errors.
    else,
        SendMode Input	;SendInput is faster but you often can't see progress of typing.  
        
   if RegExMatch(MyEntry, "is).*Paste.*=") ; There is a paste command, so use the array.
   {  ; Set up restoration of clipboard here?
        PasteMode := 0  ; Always type out text by default.    
        myArray := []
        MyEntry := StrReplace(MyEntry, "`n`n", "`n")
        loop, parse, MyEntry, `n ; Break up variable line by line.
        {
            If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
                MsgBox,, Type or Paste, Breaking up entry line by line.`nThe key name and value 
					 ,for Loop %A_Index% is:`n`n%A_Loopfield%
            data := StrSplit(A_LoopField, "=") ; Split each line at the '=' sign. 
            myArray.Push({key:data[1],value:data[2]}) ; Add to end of myArray.
        }
       
        for each, item in myArray
        {
            If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
                MsgBox % "Separating key name: `n" item.key "`n`nFrom key value: `n" item.value
            If InStr(item.key, "Paste") ; If the key name has 'paste' set it to PasteMode.
                PasteMode := 1
            Else If InStr(item.key, "Type") ; If the key has 'Type' remove PasteMode.
                PasteMode := 0
               
            If (item.value = "") ; If there is a blank line with no key, this will catch it. 
                item.value := A_Space item.key
                
            item.value := StrReplace(item.value, "  ", " ")
            item.value := StrReplace(item.value, ". ", ".  ")
            winwaitactive, %myWinTarget% ; Wait for the previously active Window. 
            If (PasteMode = 1)
            {
                Clipboard = ; Add restoration of clipboard?  Maybe at the bottom? 
					  If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
					  {
							tempvar = % item.value
							MsgBox For Loop %A_Index%, Paste mode is Yes.  
							,Clipboard starts as`n|%Clipboard%|`n`nitem value is`n|%tempvar%|
						}
                Clipboard = % item.value
                send ^v
					 Sleep %varPasteDelay%
            }
            ; Else if (PasteMode = 0)        
            Else
				{
					If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
					{
						tempvar = % item.value
						MsgBox For Loop %A_Index%, Paste mode is No.`n`nitem to be typed is`n|%tempvar%|
					}
					send % item.value
				}
        }
    }
    Else
    {
        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.
        IfNotEqual, CurrTab, Tests
           StringReplace, MyEntry, MyEntry,`n, , All ; Gets rid of any leftover newline chars, but not for tests.	
		  winwaitactive, %myWinTarget% ; Wait for the previously active Window. 
        Send %MyEntry%
    }
}

If (varDebug = 1) ; DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG  DEBUG 
    msgbox Text sent and done.
    
If (varStayInRAM != 1)
 ExitApp 	; If 'Stay in RAM' set to 0, total exit.
Exit		; If 'Stay in RAM' set to 1, close form, but stay in memory.

;=========  Other Buttons go to here if clicked ===============
ButtonSchools:
	run, %varFaveEditor% "%A_ScriptDir%\wtFiles\SchoolList.ini",, UseErrorLevel 
		If ErrorLevel 
			run, wtFiles\SchoolList.ini ; If Scite is not found, will be prompted to choose default ini opener.
return

ButtonNotices:
	run, %varFaveEditor% "%A_ScriptDir%\wtFiles\NoticeDefinitions.ini",, UseErrorLevel
		If ErrorLevel 
			Run, wtFiles\NoticeDefinitions.ini
return

ButtonSuffix:
	run, %varFaveEditor% "%A_ScriptDir%\wtFiles\TestSuffixes.ini",, UseErrorLevel
		If ErrorLevel 
			run, wtFiles\TestSuffixes.ini
return

ButtonTests:
	run, %varFaveEditor% "%A_ScriptDir%\wtFiles\TestBank.ini",, UseErrorLevel
		If ErrorLevel 
			run, wtFiles\TestBank.ini
return

ButtonΨ:
	run, wtSettings.exe
return

Code: Select all

#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Menu, Tray, Icon, shell32.dll, 81 

;==========Read from Settings file======== 
iniread, varHotkey, wtFiles\Settings.ini, MainSettings, MyHotkey
iniread, varStayInRAM, wtFiles\Settings.ini, MainSettings, StayInRAM
iniread, varVisualMode, wtFiles\Settings.ini, MainSettings, VisualSendMode
iniread, varPasteDelay, wtFiles\Settings.ini, MainSettings, PostPasteDelay
iniread, varFaveEditor, wtFiles\Settings.ini, MainSettings, FaveEditor
iniread, varTargetWins, wtFiles\Settings.ini, MainSettings, PreferredTargetWins
iniread, varForcePref, wtFiles\Settings.ini, MainSettings, ForceUseOfPreferred
iniread, varColor, wtFiles\Settings.ini, MainSettings, GUIColor
iniread, varFontColor, wtFiles\Settings.ini, MainSettings, FontColor
iniread, varWColor, wtFiles\Settings.ini, MainSettings, GUIwarnColor
iniread, varDebug, wtFiles\Settings.ini, MainSettings, Debug
iniread, varLastTab, wtFiles\Settings.ini, MainSettings, LastTab
iniread, varMon, wtFiles\Settings.ini, schedule, Monday
iniread, varTue, wtFiles\Settings.ini, schedule, Tuesday
iniread, varWed, wtFiles\Settings.ini, schedule, Wednesday
iniread, varThu, wtFiles\Settings.ini, schedule, Thursday
iniread, varFri, wtFiles\Settings.ini, schedule, Friday
iniread, varRememberStu, wtFiles\Settings.ini, MainSettings, RememberStudent
iniread, varMemoryMinutes, wtFiles\Settings.ini, MainSettings, MemoryMinutes 
iniread, varMyColors, wtFiles\Settings.ini, ColorsList
;=========================================

WinGetPos, X, Y, W, H, A   	; "A" to get the active window's position.
X := X + (W * 0.05) ; Use these with GUI Show, below.
Y := Y + (H * 0.2)
IF (!Y)  ; If launched and can't get Win position, use screen size/4.
{
	X := A_ScreenWidth / 4
	Y := A_ScreenHeight / 4
}

if (strLen(varColor) > 8) ; There's more than just a hexcode, so do subStrings. 
{
	varColorName := subStr(varColor, 1, strLen(varColor) - 8)
	varColorCode := subStr(varColor, strLen(varColor) - 5, 6)
}
else
{
	varColorName = %varColor%
	varColorCode = %varColor%
}

if (strLen(varFontColor) > 8)
{
	varFontColorName := subStr(varFontColor, 1, strLen(varFontColor) - 8)
	varFontColorCode := subStr(varFontColor, strLen(varFontColor) - 5, 6)
}
else
{
	varFontColorName = %varFontColor%
	varFontColorCode = %varFontColor%
}

Gui, Destroy
Gui, -MinimizeBox +alwaysOnTop
Gui, font, c%varFontColorCode% s11
Gui, color, %varColorCode%
myTabs := "Activation Mode|Send Mode|Editor|Files|Targets|Colors|Schedule|Pre-Fill|Debug"  
Gui Add, Tab3, AltSubmit vCurrTab Choose%varLastTab%, %myTabs% ; AltSubmit so we can save the Tab number and open with same.

;###############################################################################################
Gui Tab, 1 ;######## ACTIVATION MODE #####################################
Gui Add, Text, Wrap  w340, Exit the app from RAM each time?  If used as a "stand alone" application, then staying running in RAM between uses is recommended.  If there is another "master script" which is already running all the time, then having WayText exit each time makes sense. 
ifEqual, varStayInRAM, 1
{
	RAMMode := "checked"
	exitMode := ""
}
else
{
	RAMMode := ""
	exitMode := "checked"
}
gui, add, groupbox, R2 w340, Mode
Gui Add, Radio, yp+18 xp+10 wrap gYesStay %exitMode% , Activated from another script, so exit each use.
Gui Add, Radio, wrap vStayMode gYesStay %RAMMode% , Stay running in RAM and use hotkey to launch.

IfExist %A_Startup%\WayText.lnk
{
	StartCheck = Checked
	StartTxt = Unheck to NOT start with Windows.
}
else
{
	StartCheck = 
	StartTxt = Check to start with Windows.
}

Gui Add, Text, yp+34 Wrap w340 vChosenHotkeyTxt, The current hotkey is indicated below. Change if desired.  
Gui Add, Hotkey, vChosenHotkey, %varHotkey% 
Gui Add, CheckBox, vVarStartup gStartupLbl %StartCheck%, %StartTxt%

ifEqual, varStayInRAM, 1
{
	GuiControl, Enable, ChosenHotkeyTxt
	GuiControl, Enable, ChosenHotkey
	GuiControl, Enable, VarStartup
}
else
{
	GuiControl, Disable, ChosenHotkeyTxt
	GuiControl, Disable, ChosenHotkey
	GuiControl, Disable, VarStartup
}

;###############################################################################################
Gui Tab, 2 ;######### SEND MODE ####################################
Gui Add, Text , Wrap gTipsSendMode w340, Click for Tips about Send Mode.

ifEqual, varVisualMode, 1
{
	ModeVisual := "checked"
	ModeSafer := ""	
}
else
{
	ModeVisual := ""
	ModeSafer := "checked"	
}
gui, add, groupbox, R2 w340, Text Type Send Modes
Gui Add, Radio, yp+20 xp+10 %ModeSafer% , Safer and Faster, but works in Background.
Gui Add, Radio, vVisMode %ModeVisual% , More Visual, but prone to errors.

Gui Add, Text, xp-12 yp+60 Wrap gTipsPasteDelay w340, Click for Tips about Delay.
gui, add, groupbox, R2 w340, Text Paste Delay
Gui, Add, Edit, yp+22 xp+10 vDelayEdit w60 cBlack
Gui, Add, UpDown, vPasteDelay Range1-1000, %varPasteDelay%

;###############################################################################################
Gui Tab, 3 ;####### EDITOR #########################################
Gui Add, text, Wrap w340, The Notice and Tests INI libraries can be opened from the WayText window.  Currently assigned editor for opening INI files is:

If (StrLen(varFaveEditor)>48) ; If the path is too long, it make the GUI too wide. 
	EditorLBL := SubStr(varFaveEditor, 1, 3) "...." SubStr(varFaveEditor, -40)
Else
	EditorLBL = %varFaveEditor%	
	
Gui Add, text,, %EditorLBL%
Gui, add, button,  section gChooseEditor , Choose Different Editor
Gui, add, button,  gScite , Use Embeded SciTE


;###############################################################################################
Gui Tab, 4 ;###### FILES #########################################
Gui Add, Text , Wrap  w340, These are the INI files that WayText pulls boilerplate information from.  They also populate the lists of items that appear in the WayText main form. Click to open.
;Gui, font, bold
Gui, Add, Text, xp+24 yp+80 section gSchoolsLabel, ---> List of Schools
Gui, Add, Text, gNoticesLabel, ---> List of Boilerplate Entries
Gui, Add, Text, gSuffixLabel, ---> List of Test Item 'Suffixes'
Gui, Add, Text, gTestsLabel, ---> Test Bank
;Gui, font, 

;###############################################################################################
Gui Tab, 5 ;####### TARGETS ########################################
Gui Add, Text , Wrap  w340, "Preferred" target windows are those that you intend to send text input to.  It is easy (and frustrating) to accidentally send a bunch of key presses to the wrong window, or to the desktop. Enter a list of preferred windows, separated by comma space. RegEx partial-match rules used to identify windows by their titles. 
varTargetWins := StrReplace(varTargetWins,"|",", ")

Gui Add, Edit, +wrap  w340 h42 vVarTargetWins cBlack, %varTargetWins%
gui, add, text, +wrap  w340, Check below to only type into preferred windows. WayText uses a popup MessageBox if accidentally triggered in wrong window. (Note: Some text edit fields will automatically be "preferred.") Tip: Holding <Shift> forces use of MsgBox regardless of window.
Gui Add, CheckBox, xs+10 vChkForcePref checked%varForcePref%, Use MsgBox if target window is non preferred.

;###############################################################################################
Gui Tab, 6  ;####### COLORS #########################################
Gui Add, Text , Wrap  w340, If WayText is activated in a non-preferred taget window, the "Warning" Color is used as the color of the WayText Form.  Choose a color or paste in a Hex Code. ListBoxes and EditBoxes will always be white with black font. 

varMyColors := StrReplace(varMyColors,"`n","|") ; Must|convert|to|this.

loop, parse, varMyColors, "|"
	if (A_loopfield = varColor)
		ColorChoose := A_Index ; Get position of current color for 'Choose' option.
Gui Add, ComboBox, w160 vvarColor gColorChange Section Choose%ColorChoose%, %varMyColors%

loop, parse, varMyColors, "|"
	if (A_loopfield = varFontColor)
		FontColorChoose := A_Index
Gui Add, ComboBox, w160 vvarFontColor gFColorChange Choose%FontColorChoose%, %varMyColors%

loop, parse, varMyColors, "|"
	if (A_loopfield = varWColor)
		WColorChoose := A_Index
Gui Add, ComboBox,  w160 vvarWColor gWColorChange Choose%WColorChoose%, %varMyColors%

if (strLen(varWColor) > 8)
{
	varWColorName := subStr(varWColor, 1, strLen(varWColor) - 8)
	varWColorCode := subStr(varWColor, strLen(varWColor) - 5, 6)
}
else
{
	varWColorName = %varWColor%
	varWColorCode = %varWColor%
}

Gui Add, text, ys vTxtForm Section, Form: %varColorName%
Gui Add, text, vTxtFont Section, Font: %varFontColorName%
Gui Add, text, vTxtWarning, Warning: %varWColorName%

Gui, Add, Progress, xp-174  yp+30 w330 h50 c%varWColorCode%, 100
Gui Add, text, xp+14 yp+7 +BackgroundTrans, Sample of color when activated from a`nnon-preferred window: [ %varWColorName% ] .
Gui Add, text, xp+45 yp+56 gColorPicker, -->   [ Launch Color Picker ]   <--
;###############################################################################################
Gui Tab, 7 ;###### SCHEDULE #########################################
Gui Add, Text , Wrap  w340, In Notices Tab, choose which school should be the default item for each day of the week. 
Gui Add, Text, section, Monday
Gui Add, Text, , Tuesday
Gui Add, Text, , Wednesday
Gui Add, Text, , Thursday
Gui Add, Text, , Friday

IniRead, AllSchools, wtFiles\SchoolList.ini ; Gets `n-delimited list from ini file.
AllSchools := StrReplace(AllSchools,"`n","|") ; Format|list|like|this.
Gui Add, DropDownList, ys section w130 AltSubmit vvarMonBld Choose%varMon%, %AllSchools%
Gui Add, DropDownList, w130 vvarTueBld AltSubmit Choose%varTue%, %AllSchools%
Gui Add, DropDownList, w130 vvarWedBld AltSubmit Choose%varWed%, %AllSchools%
Gui Add, DropDownList, w130 vvarThuBld AltSubmit Choose%varThu%, %AllSchools%
Gui Add, DropDownList, w130 vvarFriBld AltSubmit Choose%varFri%, %AllSchools%

;###############################################################################################
Gui Tab, 8 ;###### PREFILL #########################################
Gui Add, Text , Wrap  w340, Should WayText remember the Name, Gender, and School that was used with the last text replacement? NOTE:  This memory will override the 'Calendar' chosen School. 

ifEqual, varRememberStu, 1
	MemoryMode := "checked"
else
	MemoryMode := ""
Gui Add, Checkbox, vUseMemory gMemoryToggle %MemoryMode%, Remember the last used student information.

Gui Add, Text, Wrap w340 vMemoryDurationTxt, Last used information should be prefilled if the last use was within this many mintes. Choose from 1-600. If WayText has been unused for more than this, the default values will be used. 
Gui, Add, Edit, vMemoryEdit w60 cBlack
Gui, Add, UpDown, vMemoryMinutes Range1-600, %varMemoryMinutes%

ifEqual, varRememberStu, 1
{
	GuiControl, Enable, MemoryDurationTxt
	GuiControl, Enable, MemoryEdit
	GuiControl, Enable, MemoryMinutes
}
else
{
	GuiControl, Disable, MemoryDurationTxt
	GuiControl, Disable, MemoryEdit
	GuiControl, Disable, MemoryMinutes
}

;###############################################################################################
Gui Tab, 9 ;###### DEBUG #########################################
Gui Add, Text , Wrap  w340, If Debug mode is checked, several Popup Messages will occur, showing what the text looks like on its stages from INI file to being typed or pasted.`n`nIf there are many "Optional" GUIs in a text entry, or many items in the Optional GUIs, then there may be several dozen Popup Messages.

ifEqual, varDebug, 1
	DebugMode := "checked"
else
	DebugMode := ""
Gui Add, Checkbox, vUseDebug %DebugMode%, Show Debug information during execution.

;###############################################################################################
Gui Tab ;###### END OF TABS #########################################

Gui Add, Button, w106 h30 Section, Apply
Gui Add, Button, ys w136 h30 gApply_Then_Close, Apply Then Close
Gui Add, Button, ys w106 h30, Cancel
Gui Show, x%X% y%Y%, WayText Settings

if (varHotkey = "ERROR")  ; Will catch if Settings INI is missing.
  MsgBox, 262192, Error Reading File, There may be one or more missing INI files that are needed.  In the same folder as this AHK file, there should be a folder called "wtFiles."  Inside of wtFiles should be the following files: `n`n`tNoticeDefinitions.ini`n`tSchoolList.ini`n`tSettings.ini`n`tTestBank.ini`n`tTestSuffixes.ini
Return

TipsSendMode:
MsgBox, 262192, Send Modes Tips, How should the replacement text get typed into the target window? In Google Chrome text boxes, "safe mode" will cause WayText to run in the background.  The text won't be seen until the script is completely finished.  Then Chrome will 'refresh' the page.  During this time, extraneous mouse clicks and key presses are mostly ignored.  That's why it's "safe mode." `n**Note that, if an INI key name contains "Paste," then the send mode is largely irrelevant for that key. 

TipsPasteDelay:
MsgBox, 262192, Paste Delay Tips, It takes 100 miliseconds or so for Windows to clear and rewrite its build in clipboard.  This mostly matters if a text entry has multiple "Paste Keys" back-to-back. This setting causes a pause (in miliseconds) after each paste command. 

ColorChange:
	gui, submit, nohide
	varColorName := subStr(varColor, 1, strLen(varColor) - 8)
	guicontrol,,TxtForm, Form: %varColorName%	
	varColorCode := subStr(varColor, strLen(varColor) - 5, 6)
	gui, color, %varColorCode%
return

FColorChange:
	gui, submit, nohide	
	varFontColorName := subStr(varFontColor, 1, strLen(varFontColor) - 8)
	varFontColorCode := subStr(varFontColor, strLen(varFontColor) - 5, 6)	
	Gui, Font, s11 c%varFontColorCode%
	WinGet, list, ControlList
	For each, control in StrSplit(list, "`n")
		GuiControl, Font, %control%
	GuiControl, MoveDraw, %control%
	guicontrol,,TxtFont , Font: %varFontColorName%
return

WColorChange:
	gui, submit, nohide
	varWColorName := subStr(varWColor, 1, strLen(varWColor) - 8)
	guicontrol,,TxtWarning, Warning: %varWColorName%
	varWColorCode := subStr(varWColor, strLen(varWColor) - 5, 6)
	gui, color, %varWColorCode%
return

YesStay: ; If stay in RAM, enable hotkey cmd. 
	Gui, Submit, NoHide
	If (StayMode = 1)
	{
		GuiControl, Disable, ChosenHotkeyTxt
		GuiControl, Disable, ChosenHotkey
		GuiControl, Disable, VarStartup
		StayMode -= 1  ; Radio buttons return 1 or 2 so, change those into 0 or 1 for our ini file.
		IniWrite, %StayMode%, wtFiles\Settings.ini, MainSettings, StayInRAM
		IniWrite, %ChosenHotkey%, wtFiles\Settings.ini, MainSettings, MyHotkey
		IfExist %A_Startup%\WayText.lnk
		{
			FileDelete %A_Startup%\WayText.lnk
			StartCheck = 
			MsgBox, 0x1000, WayText Settings, WayText will NO LONGER auto start with Windows.
			reload
		}	

	}
	Else If (StayMode = 2)
	{
		GuiControl, Enable, ChosenHotkeyTxt
		GuiControl, Enable, ChosenHotkey
		GuiControl, Enable, VarStartup
	}	
Return

StartupLbl:
	Gui, Submit, NoHide 
	If (VarStartup = 1)
	{
		FileCreateShortcut %A_WorkingDir%\WayText.exe,%A_Startup%\WayText.lnk
		MsgBox, 0x1000, WayText Settings, WayText will auto start with Windows.
	}
	Else If (VarStartup = 0)
	{
		FileDelete %A_Startup%\WayText.lnk
		MsgBox, 0x1000, WayText Settings, WayText will NO LONGER auto start with Windows.
	}
Return

MemoryToggle:
	Gui, Submit, NoHide 
	ifEqual, useMemory, 1
	{
		GuiControl, Enable, MemoryDurationTxt
		GuiControl, Enable, MemoryEdit
		GuiControl, Enable, MemoryMinutes
	}
	else
	{
		GuiControl, Disable, MemoryDurationTxt
		GuiControl, Disable, MemoryEdit
		GuiControl, Disable, MemoryMinutes
	}
Return

ButtonApply:
Apply_Then_Close: 
	gui, submit, NoHide
	iniWrite, %CurrTab%, wtFiles\Settings.ini, MainSettings, LastTab ; Number for open tab, so we can restore it.
		;======= Tab 1 Stay in RAM mode ===================
	StayMode -= 1  ; Radio buttons return 1 or 2 so, change those into 0 or 1 for our ini file.
	IniWrite, %StayMode%, wtFiles\Settings.ini, MainSettings, StayInRAM
	IniWrite, %ChosenHotkey%, wtFiles\Settings.ini, MainSettings, MyHotkey
		;======= Tab 2 Send text mode =====================
	VisMode -= 1
	IniWrite, %VisMode%, wtFiles\Settings.ini, MainSettings, VisualSendMode
	IniWrite, %PasteDelay%, wtFiles\Settings.ini, MainSettings, PostPasteDelay
		;========  Tab 3 Fave Editor ======================
		;======== Tab 4 Fave Windows ======================
	varTargetWins := StrReplace(varTargetWins,", ","|")
	IniWrite, %varTargetWins%, wtFiles\Settings.ini, MainSettings, PreferredTargetWins
	IniWrite, %ChkForcePref%, wtFiles\Settings.ini, MainSettings, ForceUseOfPreferred
		;======= Tab 5 Colors =============================
	varColor := StrReplace(varColor, "#", "")
	iniWrite, %varColor%, wtFiles\Settings.ini, MainSettings, GUIColor
	varFontColor := StrReplace(varFontColor, "#", "")
	iniWrite, %varFontColor%, wtFiles\Settings.ini, MainSettings, FontColor
	varWColor := StrReplace(varWColor, "#", "")
	iniWrite, %varWColor%, wtFiles\Settings.ini, MainSettings, GUIwarnColor
		;======= Tab 6 Schedule ===========================
	iniWrite, %varMonBld%, wtFiles\Settings.ini, schedule, Monday
	iniWrite, %varTueBld%, wtFiles\Settings.ini, schedule, Tuesday
	iniWrite, %varWedBld%, wtFiles\Settings.ini, schedule, Wednesday
	iniWrite, %varThuBld%, wtFiles\Settings.ini, schedule, Thursday
	iniWrite, %varFriBld%, wtFiles\Settings.ini, schedule, Friday
		;======= Tab 7 Prefill ===========================
	iniWrite, %UseMemory%, wtFiles\Settings.ini, MainSettings, RememberStudent
	iniWrite, %MemoryMinutes%, wtFiles\Settings.ini, MainSettings, MemoryMinutes 
		;======= Tab 9 Debug =============================
	iniWrite, %UseDebug%, wtFiles\Settings.ini, MainSettings, Debug 
	
if (A_ThisLabel = "Apply_Then_Close")
	ExitApp
else
{
	Reload
	Return
}

	;======= Tab 8 Files ===========================
SchoolsLabel:
	run, %varFaveEditor% "%A_ScriptDir%\wtFiles\SchoolList.ini",, UseErrorLevel 
	If ErrorLevel 
		run, wtFiles\SchoolList.ini ; If Scite is not found, will be prompted to choose default ini opener.
return
NoticesLabel:
	run, %varFaveEditor% "%A_ScriptDir%\wtFiles\NoticeDefinitions.ini",, UseErrorLevel
	If ErrorLevel 
		Run, wtFiles\NoticeDefinitions.ini
return
SuffixLabel:
	run, %varFaveEditor% "%A_ScriptDir%\wtFiles\TestSuffixes.ini",, UseErrorLevel
	If ErrorLevel 
		run, wtFiles\TestSuffixes.ini
return
TestsLabel:
	run, %varFaveEditor% "%A_ScriptDir%\wtFiles\TestBank.ini",, UseErrorLevel
	If ErrorLevel 
		run, wtFiles\TestBank.ini
return

ChooseEditor:
	;FileSelectFile, OutputVar , Options, RootDir\Filename, Title, Filter
	FileSelectFile, SelectedEditor, 3, , Choose favorite editor, Application (*.exe)
	if (SelectedEditor = "")
		MsgBox, 0x1000, WayText Settings, No app was selected.
	else
		IniWrite, %SelectedEditor%, wtFiles\Settings.ini, MainSettings, FaveEditor
	;run, WayText.exe ; Restart WayText.
ExitApp

Scite:
	if FileExist("SciTE\SciTE.exe") 
	{
		IniWrite, %A_ScriptDir%\SciTE\SciTE.exe, wtFiles\Settings.ini, MainSettings, FaveEditor
		;run, WayText.exe ; Restart WayText.	
	}
	else
		MsgBox, 0x1000, WayText Settings, Scintilla Text Editor (SciTE) not found bundled with WayText.
Reload

ButtonCancel:
GuiEscape:
GuiClose:
ExitApp

ColorPicker:
Loop, ;based on WhatColor.ahk, by Skrommel @2005
{
  MouseGetPos,cpx,cpy
  PixelGetColor,rgb,cpx,cpy,RGB
  StringTrimLeft,rgb,rgb,2
  ToolTip,Point at desired color.`nThen press [Shift] to copy the`ncolor code to the clipboard.`n`n         --> %rgb% <--`n`n
  if GetKeyState("Shift","P")
  {
    Clipboard=%rgb%
	ToolTip, Hexcode captured`nto Clipboard`n`n   *** %rgb% ***
    Sleep, 2000
	send {Shift up}
	ToolTip,
	Break	
  }
  Sleep,10
}
Image
Last edited by kunkel321 on 25 Dec 2021, 19:51, edited 11 times in total.
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 1118
Joined: 30 Nov 2015, 21:19

Re: Pretty specific text expansion tool.

Post by kunkel321 » 09 Mar 2021, 20:04

I mostly got rid of the redundant part by adding a couple of if statements.

I have a "cursor detector" to try to avoid accidentally activating it when a text field isn't ready (line 127). It doesn't work well though. Will replace it with something better later.
Last edited by kunkel321 on 21 Mar 2021, 20:49, edited 1 time in total.
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 1118
Joined: 30 Nov 2015, 21:19

Re: Pretty specific text expansion tool.

Post by kunkel321 » 12 Mar 2021, 21:09

Updates:
1-The "cursor detector" didn't work well because it doesn't always signify that an edit field is actually selected. Got rid of that. Now when the script is activated, it saves the window title. Then the text is not inserted until that window is active again.
RECOMMENDED: Launch the script via hotkey--not just by double-clicking the MultiTool.exe file.
2-A line of code Fixes most cases of a sentence starting with a lowercase replacement word. (see https://www.autohotkey.com/boards/viewtopic.php?f=76&t=87890)
3-Double-Clicking a Notice type or Test name now runs the text insertion.

Problem: I just noticed that if a "Test suffix" item starts with a space, the space gets truncated. Will work on that later.

Noobie Note: If there are any noobs like me, and they aren't clear on .ini files, see here https://en.wikipedia.org/wiki/INI_file In the download there are four text (.txt) files. But they must be formatted as .ini files for the thing to work.
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 1118
Joined: 30 Nov 2015, 21:19

Re: Pretty specific text expansion tool.

Post by kunkel321 » 21 Mar 2021, 21:23

Update 3-21-2021: (also pasted above)
-Rather than having 4 txt files formatted as ini files, there are simply 4 ini files.
-I've included a copy of the excellent SciTE4AHK.
-Clicking a button, from the MultTool, to edit one of the ini files, will open it in SciTE, giving it nice syntax highlighting.
-I noticed that, with the Tests Tab, if the suffix comboBox was blank, it caused a problem. That is fixed.
Last edited by kunkel321 on 25 Dec 2021, 16:50, edited 1 time in total.
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 1118
Joined: 30 Nov 2015, 21:19

Re: Pretty specific text expansion tool. -- WayText

Post by kunkel321 » 25 Dec 2021, 16:40

Latest (12-25-2021) version is attached to top post. I was calling it "MultiTool" but the tool is too much of a one-trick pony to be a multitool. It's for entering customized text, and "way" is listed as a synonym for "custom," therefore -- "WayText."

Merry Christmas and Happy Holidays Folks !!!
ste(phen|ve) kunkel

User avatar
kunkel321
Posts: 1118
Joined: 30 Nov 2015, 21:19

Re: Pretty specific text expansion tool. -- WayText

Post by kunkel321 » 30 Apr 2024, 20:25

This project has been recreated for AHK v2. Information is here:
viewtopic.php?f=83&t=129466

The AHK v1 version here will no longer be updated.
ste(phen|ve) kunkel

Post Reply

Return to “Scripts and Functions (v1)”