;Msg Terminal Script, used for passing msgs with ;ControlSetText ;ControlGetText #NoTrayIcon ;Port Amount, How many ports should this terminal have? P_Amt = 300 TerminalName = Msg_Terminal ;Text used as for Identifying the script gui, add, text, , %TerminalName% Loop, %P_Amt% { Gui, Add, Edit, vMsg%A_Index% -wantreturn } SetTimer, WatchExit Return WatchExit: Gui, Submit If Msg1 = Exit ExitApp If Msg1 = Reload Reload Return
Function for sending and retrieving from the terminal script.
DetectHiddenWindows, On SetTitleMatchMode, 3 Var := Msg("s", 2, "Msg_Terminal", "SomeTextToSendToTheTerminal") MsgBox %Var% Return ; Dir = Direction of msg, S for Send, R for Recieve ; Port = The number of the port to call upon. ; Terminal Name = The name of the terminal to accept call ; MsgText = The Text to be sent. Msg(Dir,Port,TerminalName,MsgText) { ;Checks if terminal window exists IfWinNotExist, ahk_class AutoHotkeyGUI, %TerminalName% MsgBox Error! `nTerminal does not exist. ;Checks if port exists ControlGetPos, Xpos_,,,, Edit%Port%, ahk_class AutoHotkeyGUI, %TerminalName% If XPos_ = Msgbox Error! `nPort may not exist. ;Send If Dir = S ControlSetText, Edit%Port%, %MsgText%, ahk_class AutoHotkeyGUI, %TerminalName% ;Recieve If Dir = R ControlGetText, ReturnText, Edit%Port%, ahk_class AutoHotkeyGUI, %TerminalName% Return %ReturnText% }
Function Syntax
Msg("S/R", PortNumber, "TerminalName", "Text")
The Terminal script has two options, the amount of ports that will hold information(Text only) and the name of the Terminal. The name of the terminal is used when calling it in the function, so that multiple terminals may exist, each must have a seperate name. The amount of ports affects the size of the script. This one has 300, and you may not need that many. The maximum is 10,999, and use caution with amounts greater than 4999.
The First port is reserved for handling 'commands' sent to the terminal via the function. The following are supported and explained. More may be added later on.
Exit -exits the terminal and closes it.
Reload - Restarts the terminal(clearing the contents of all ports)
Example For Closing the Terminal Script
Msg("s", 1, "Msg_Terminal", "Exit")
The terminal script should be run alone, while its calling function can be used in any seperate script. I find this method useful for notifying other scripts of status changes among themselves. It also seems to be an easy way for a new user to communicate between script as I have so many threads asking about it.