I think that's happening because changing the clipboard through your program also calls the clipboard change event, so you are catching yourself in a loop, I'm not sure the best way to go about it, but adding a time check seems to work for me
Code: Select all
#persistent
OnClipboardChange("ClipChanged")
clipboard := "letters and numbers 1234 gs words gs gs gsgsgs gs jr jr jrjrjr gs"
;the clipboard now contains the corrected information
return
ClipChanged(dataType) {
static last := 0,replacements := []
if (last = 0) { ;last will serve 2 functions, to determine first run and determine last clipboard change
replacements["gs"] := "GSW" ;define replacements here
replacements["jr"] := "Jr."
last := 1 ;set last to any value above 0 so this code only runs once
}
if (dataType = 1 and a_tickcount > last) { ;clipboard is not empty and does not contain non text data
data := clipboard
for k,v in replacements
data := StrReplace(data,k,v)
clipboard := data
last := a_tickcount + 50 ;any clipboard event in the next 50ms is ignored
}
}
Edit: Woops, when I copied the script over to here I still had it running and it changed stuff XD, fixed that.