Abort Send for long text

Helpful script writing tricks and HowTo's
User avatar
joedf
Posts: 7898
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Abort Send for long text

12 Feb 2021, 10:34

I have written this to help another user from email, thought it might be helpful to others so I decided to share this here. I am sure there are likely precedents, but...
Share your comments, improvements, suggestions, different implementations :+1:

Method: Keeps track of all child PIDs in a temporary file, creates the child script and temporary file accordingly.
The example has a parent script managing child scripts. The ESC key terminates any text sending/child scripts. Shift+Esc terminates the parent and child scripts.
The "b" sends long example text (lorem ipsum). You can change these key bindings near the bottom of the script.

Code: Select all

; Testing Another method to abort the script while it sends long text
; Requires AHK v1.1.20+
; Created 10:14 AM 2/12/2021
; by joedf 

#SingleInstance, Off

OnExit("ExitFunc")
G_LockFile := A_Temp . "/" . A_ScriptName . ".pids"
IsParent := IsParent_Check()

if (IsParent) {
	FileDelete, %G_LockFile%
	NewChild()
} else {
	sPID := DllCall("GetCurrentProcessId")
	FileAppend, %sPID%`n, %G_LockFile%	
}
return

IsParent_Check() {
	IsParent := true
	for n, param in A_Args  ; For each parameter:
	{
		if (InStr(param,"NOT_PARENT")) {
			IsParent := false
			break
		}
	}
	return IsParent	
}

NewChild() {
	Run, %A_ScriptFullPath% NOT_PARENT,,,outPID
}

Terminate(Make_NewChild:=true) {
	global G_LockFile
	Loop, Read, %G_LockFile%
	{
		Process, Close, %A_LoopReadLine%
	}
	FileDelete, %G_LockFile%
	if (Make_NewChild) {
		NewChild()
	}
}

ExitFunc(ExitReason, ExitCode) {
    Terminate(false)
}

#If (IsParent)
Esc::Terminate() ;Terminates all child scripts only.
+Esc::ExitApp ;Terminates Parent and all child scripts


; Here goes the child script's hotkeys, hotstrings, etc. 
#If (!IsParent)
b::Send, 
(
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam,
eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam
voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione
voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci
velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut
enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi
consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur,
vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
)

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 6 guests