/* LegalTerms.ahk demonstrates the use of an INI data table combined with the Input command to produce tools for locating and inserting Latin legal terms into documents either by entering an acronym Hotstring of popping up a menu of terms. May 9, 2018 Currently the Hotkey CTRL+ALT+O initiate the Input command for entering a four-letter acronym. If found in the MatchList, AutoHotkey displays a MsgBox showing the information from the data table. If not found, AutoHotkey opens a pop-up menu of terms starting with the entered letters. May 18, 2018 This version of the script now includes the option to italicize the Latin legal term(s) by terminating the Input command with the TAB rather than the ENTER key. Use ENTER as the terminating key for plain text. At the end of this file, find a Hotstring which converts plain text into italics for particular word processors. */ LegalAutoExec: Loop, Read, LegalInput.ini { If A_Index = 1 Continue Input_Array := StrSplit(A_LoopReadLine, "=") Input_String := Input_String . Input_Array[1] . "," } Return ^!o:: SplashTextOn,100, 40, Enter legal code!, Waiting for Input! Input , OutputVar, L4 T10, {Enter}{Tab}, %Input_String% EndKey := ErrorLevel SplashTextOff If (ErrorLevel = "Match") { IniRead, LegalTerm, LegalInput.ini, InputKey, %OutputVar% ; MsgBox %OutputVar% matches! Legal_Array := StrSplit(LegalTerm, "|") MsgBox, , Hotstring %OutputVar%, % Legal_Array[1] . "`r`r" . Legal_Array[2] . "`r`r" . Legal_Array[3] } Else ; MsgBox No match! %ErrorLevel% %OutputVar% LatinList() Return LegalAction: If (EndKey = "EndKey:Tab") { SendInput %A_ThisMenuItem%{raw} Length := StrLen(A_ThisMenuItem) SendInput, {Shift down}{Left %Length%}{Shift up}^i{Right}^i{Space} /* SendInput, {Shift down} ; Hold SHIFT key down SendInput, {Left %Length%} ; Select phrase SendInput, {Shift up} ; Release SHIFT key SendInput, ^i ; Issue italicize command SendInput, {Right} ; Deselect phrase SendInput, ^i ; Deselect italics SendInput, {Space} ; Add space to end ; SendInput, % "{Shift down}{Left " . Length . "}{Shift up}^i" ; Alternative force expression format */ } Else SendInput %A_ThisMenuItem%{Space}{raw} Return LatinList() { Global ItemCount := 0 Loop, read, LegalInput.ini { Legal := StrSplit(A_LoopReadLine , "|") { If (Legal[2] ~= "i)^" . OutputVar) { If ItemCount = 20 { Menu, LegalLatin, add, % Legal[2], LegalAction, +BarBreak ItemCount := 1 } Else { Menu, LegalLatin, add, % Legal[2], LegalAction ItemCount++ } ; MsgBox, % "Field number " . A_Index . " is " . Legal[2] . "." } } } Menu_item_count := DllCall("GetMenuItemCount", "ptr", MenuGetHandle("LegalLatin")) If Menu_item_count >= 1 Menu, LegalLatin, Show Else MsgBox, No matches found for %OutputVar%! If Menu_item_count >= 1 Menu, LegalLatin, DeleteAll } /* This next Hotstring converts the French phrase "je ne sais quoi" into italics. After typing "jq" plus a space or punctuation, AutoHotkey inserts the phrase and, for the appropriate programs, sets it to italics. The first option works with Google Chrome and Windows WordPad. The second option works in LibreOffice Writer. Otherwise, AutoHotkey inserts plain text. The routine uses AutoHotkey line continuation techniques to shorten line lengths. */ ::jq:: If WinActive("ahk_class Chrome_WidgetWin_1") or WinActive("ahk_class WordPadClass") SendInput , je ne sais quoi{Shift down}{Left 15}{Shift up}^i{Right}^i{Space} Else If WinActive("ahk_class SALFRAME") { SendInput , je ne sais quoi{Shift down}{Left 15}{Shift up}^i{Right 15}^i{Space} } Else SendInput, je ne sais quoi{space} Return