AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Terminal Script for commuication between scripts

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Invalid User



Joined: 14 Feb 2005
Posts: 442
Location: Texas, Usa

PostPosted: Thu Aug 18, 2005 3:18 am    Post subject: Terminal Script for commuication between scripts Reply with quote

Terminal Script:
Code:
;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.
Code:
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.
_________________
my lame sig Smile
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Guest






PostPosted: Tue Jul 24, 2007 11:03 am    Post subject: Reply with quote

intresting idea, i will look into it once i get into it Very Happy
Back to top
haichen



Joined: 05 Feb 2007
Posts: 101
Location: Osnabrück, Germany

PostPosted: Tue Jul 24, 2007 12:51 pm    Post subject: Reply with quote

Wow..
Beautiful idea and easy to understand. I like it!
Very Happy
Back to top
View user's profile Send private message
David Andersen



Joined: 15 Jul 2005
Posts: 85
Location: Denmark

PostPosted: Thu Jul 26, 2007 12:44 pm    Post subject: Reply with quote

I love the creativity behind this solution. Easy and simple. One could probably solve this problem in ways that are amazingly complex, but there is no reason to.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Helpy
Guest





PostPosted: Thu Jul 26, 2007 2:08 pm    Post subject: Reply with quote

A possible gotcha could be concurrent access/update, but I don't know if that's really an issue.
Anyway, it is a very creative idea!
Back to top
PFP
Guest





PostPosted: Thu Jul 26, 2007 2:19 pm    Post subject: Reply with quote

Hmm, that could be very useful at work. I will check it out in more details tomorrow.
Back to top
q455
Guest





PostPosted: Thu Mar 06, 2008 2:38 pm    Post subject: Reply with quote

I want to revive this topic.... IThe basic question is, besides (1) Clipboard (2) Write to File and (3) ControlSet on a hidden window, is there any other "Memory" where all scripts can access -- since we don't have access to direct memory? I'm sure there are more ways out there.

It seems like a nice idea to include into the next implementation of autohotkey -- virtual clipboards, registers, whatever.
Back to top
q335r49



Joined: 26 Oct 2005
Posts: 15

PostPosted: Thu Mar 06, 2008 2:44 pm    Post subject: Reply with quote

Really, the storage is no big deal. Any script can handle the storage as an array. But I don't know of any way to send like a long text string to another script, besides the above named methods.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group