Send and receive strings between AHK scripts

Post your working scripts, libraries and tools for AHK v1.1 and older
DJAnonimo
Posts: 3
Joined: 11 Feb 2018, 17:36

Send and receive strings between AHK scripts

22 Mar 2018, 11:12

Hello,

here is my version of communicating between scripts.
Simple and easy :)

Send function:

Code: Select all

SendToAHK(String)
{
	Prev_DetectHiddenWindows := A_DetectHiddenWindows
	DetectHiddenWindows On
	StringLen := StrLen(String)
	Loop, %StringLen%
	{
	AscNum := Asc(SubStr(String, A_Index, 1))
	if (A_Index = StringLen)
		LastChar := 1
	PostMessage, 0x5555, AscNum,LastChar,,AHK
	}
	DetectHiddenWindows %Prev_DetectHiddenWindows%
}

Code: Select all

gui, new,, AHK
OnMessage(0x5555, "Func")
SetTimer, MyTimer, 100


MyTimer:
if receivedVar
{
Received_String := receivedVar, receivedVar := ""
Msgbox "%Received_String%"
}
return

func(wParam, lParam, Msg){
global tempVar
global receivedVar
	if (Msg = 0x5555)
		{
		tempVar .= Chr(wParam)
		if lParam
			receivedVar := tempVar, tempVar := ""
		}
}

Send string example:

Code: Select all

SendToAHK("Hello World!")
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Send and receive strings between AHK scripts

22 Mar 2018, 19:01

Thanks, DJAnonimo! Works perfectly for me. I like it.
drozdman
Posts: 78
Joined: 05 Dec 2015, 01:07

Re: Send and receive strings between AHK scripts

24 Mar 2018, 11:02

Cool idea.
I've been using Receive_WM_COPYDATA(wParam, lParam), but it requires this function included.
elbitjusticiero
Posts: 78
Joined: 06 May 2017, 11:07

Re: Send and receive strings between AHK scripts

23 Jan 2019, 09:59

Does this work for sharing information between AHK1 and AHK2 scripts? Because that would be the best way for me to adopt v2.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Send and receive strings between AHK scripts

23 Jan 2019, 10:23

Great idea and script.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Send and receive strings between AHK scripts

23 Jan 2019, 12:01

If the goal is to share data this function should probably be used:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6148
Recommends AHK Studio

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 254 guests