Curious if Fastkeys can do this...

Share your favorite FastKeys commands
User avatar
travibe
Posts: 15
Joined: Nov 2nd, ’20, 23:29

Post by travibe » Feb 8th, ’25, 10:25

I'm wondering if Fastkeys can accomplish the following actions, and if so, what would the code look like?

Search an open document in a program (notepad, wordpad, word, etc.)
find a specified word, then replace all instances of the word with a randomly selected choice given by a premade list.

For example:
Within word, I'd like to be able to search an open document for the word Goodbye, and randomly replace all instances of Goodbye with any of the choices I provide in a premade list: So long, fare well, bye bye.

Is this something Fastkeys can accomplish?
User avatar
Marko
Posts: 1860
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Feb 9th, ’25, 11:13

This code will replace all instances of the word in the selected text with one of the random choices. Create a shortcut, Type: Command

Code: Select all

Word:="Goodbye"
List:= ["So long", "Fare well", "Bye bye"]
send, ^c
sleep 100
text:=clipboard
while InStr(text, word)
{
	Random, selected, 1, List.maxindex()
	stringreplace, text, text, %word%, % List[selected]
}
sendinput % text
return
User avatar
travibe
Posts: 15
Joined: Nov 2nd, ’20, 23:29

Post by travibe » Feb 10th, ’25, 13:06

Dude, you are impressive as hell. Don't ever let someone tell you that you don't know what you are talking about, or that someone could do this better than you, because they would simply just be plain ol' wrong. You, sir... touché.

Quick point of interest - Is there any way this could be made so that I press shortcut to run this command, and a dialog box appears asking for the word to find and the words to use for the list?
User avatar
travibe
Posts: 15
Joined: Nov 2nd, ’20, 23:29

Post by travibe » Feb 12th, ’25, 05:46

Word:= "%INPUT_Word%"
List:= ["%INPUT_Random1%", "%INPUT_Random2%", "%INPUT_Random3%"]
send, ^c
sleep 100
text:=clipboard
while InStr(text, word)
{
Random, selected, 1, List.maxindex()
stringreplace, text, text, %word%, % List[selected]
}
sendinput % text
return



I have tried the above to allow me to have inputs to modify the process on the fly, but no success. each of the "INPUT" parameters is just a manual text input. This is about what i'm looking for if i can get this to work, it provides one popup upon button push where input the word im trying to replace, and 3 fields that i can fill to be up to the 3 random choices I want to use to replace the given word. How can i get his format to work properly?
User avatar
Marko
Posts: 1860
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Feb 13th, ’25, 14:04

This maybe?

Code: Select all

InputBox, Word,, Word,,, 130
InputBox, ListE,, Comma delimited list,,, 130

List:=[]
loop, parse, ListE, `,
	List[A_Index]:=A_LoopField
send, ^c
sleep 100
text:=clipboard
stringreplace, text, text, `r,, all
while InStr(text, word)
{
	Random, selected, 1, List.maxindex()
	stringreplace, text, text, %word%, % List[selected]
}
sendinput % text
return
User avatar
travibe
Posts: 15
Joined: Nov 2nd, ’20, 23:29

Post by travibe » Feb 13th, ’25, 18:47

I have that copied and pasted directly into fast keys, set as a command. I'm not getting any action on the execution of the code. I tried it in Textpad, both with all the text highlighted and not highlighted. nothing appears to be happening. What am I doing incorrectly?
User avatar
Marko
Posts: 1860
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Feb 15th, ’25, 10:46

It works as the previous code, it only asks you for the input first. Make sure you have a shortcut set correctly and there are no Window limitations.
User avatar
travibe
Posts: 15
Joined: Nov 2nd, ’20, 23:29

Post by travibe » Mar 4th, ’25, 21:35

i really need some help here. I've been trying desperately to get this code to work for me and it just doesn't. I will describe exactly what I'm doing so you can please tell me what I am doing wrong.

I have the text open in notepad. I have tried selecting all the text as well as selecting no text. I press my shortcut for the script to run, and the first window pops up asking for the word i wish to replace. I enter in "chair" for example. I click OK, and the next window appears. I type in "couch, lazy boy, sofa" exactly like that without the quotes, using a comma then space then word then comma space etc. I click OK and nothing happens. No text changes in the text at all. I am unable to run the shortcut again using my shortcut keys, it just wont run a second time. Does that mean its "thinking" so to say? Or has it just failed?

I've checked my settings and from what I can tell everything appears to be set properly. Can you please help me figure this out?
User avatar
Marko
Posts: 1860
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Mar 6th, ’25, 19:11

I tried again and it works for me. Have you copied the code correctly (Select All)? I understand the previous code worked... Can you try in another editor or Word? Do you perhaps use another software which may control the clipboard?
User avatar
travibe
Posts: 15
Joined: Nov 2nd, ’20, 23:29

Post by travibe » Mar 7th, ’25, 18:49

I am using it in multiple programs and not having any luck. Could the problem be that I am using a word i am tryin to replace in the word list? For instance:

Word to replace: Tree
List: Big Tree, Huge Tree, Massive Tree

Would that be part of the problem? I'm just not having any luck
Post Reply