hello,
If ".hi" is written,
"hello, Thank you for your inquiry." I want to write less.
I can use the OnEvent function to assign a hotkey to a specific key,
but this is not boilerplate. Is there any way to solve this?
how to boilerplate macros
Moderators: JRL, Dorian (MJT support)
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: how to boilerplate macros
I hope I'm understanding correctly. I think it would be difficult to cover all eventualities, but maybe something like this with all your commonly typed sentences. These are the kind of script that tend to grow in time...
..and of course you could even write it to present a different set of options depending on window title.
Assign to a hotkey. Even better, assign to a hotkey on a programmable mouse.
Another more convoluted method might be to highlight .hi and then have a macro determine what's highlighted - then paste appropriate text in it's place.
I'd be interested to hear how others may do this.
..and of course you could even write it to present a different set of options depending on window title.
Assign to a hotkey. Even better, assign to a hotkey on a programmable mouse.
Code: Select all
//Test in Notepad
RunProgram>Notepad.exe
WaitWindowOpen>Untitled*
wait>0.1
//Set up your options
Let>Opt1=Hello
Let>Opt2=Goodbye
Let>Opt3=Yesterday
Let>Opt4=Today
//Get the current window title
GetActiveWindow>title,xx,yy,ww,hh
//User input
input>res,1.%Opt1%%CRLF%2.%Opt2%%CRLF%3.%Opt3%%CRLF%4.%Opt4%
//Output according to chosen option
if>res>0
SetFocus>title
Send>Opt%res%
endif
Code: Select all
//Get Active Window Details
GAW>Win,x,y,w,h
//Copy selected text
Press Ctrl
Wait>0.05
Send>c
Wait>0.05
Release Ctrl
Wait>0.05
//Get the cipboard
GetClipBoard>NewClip,0
//Is the word ".hi" selected?
Let>Search=.hi
Pos>{Lower(%Search%)},{Lower(%NewClip%)},1,PosHi,
if>PosHi>0
Setfocus>Win
PutClipBoard>hello, Thank you for your inquiry.
Setfocus>Win
//Paste (instead of using sendtext - faster for sending longer text snippets)
Press Ctrl
Wait>0.05
Send>v
Wait>0.05
Release Ctrl
Wait>0.05
Endif
//Is the word ".order" selected?
Let>Search=.order
Pos>{Lower(%Search%)},{Lower(%NewClip%)},1,PosOrder,
if>PosOrder>0
Setfocus>Win
PutClipBoard>Thank you for your order, we will be processing it today
Setfocus>Win
//Paste (instead of using sendtext - faster for sending longer text snippets)
Press Ctrl
Wait>0.05
Send>v
Wait>0.05
Release Ctrl
Wait>0.05
Endif
Re: how to boilerplate macros
Dear Dorian, thank you as always.
The method you gave above gave me an idea.
Currently in testing, I am looking for a way to recognize ".hi" using the OnEvent function.
I tried the above code but
OnEvent>KEY_DOWN,VK72,0,I
line doesn't work. Can you tell me why?
And I tried this too, but it failed because WaitKeyDown works too slow.
Looking forward to your good ideas. thank you.
The method you gave above gave me an idea.
Currently in testing, I am looking for a way to recognize ".hi" using the OnEvent function.
Code: Select all
Repeat>
OnEvent>KEY_DOWN,VK190,0,H
Until>
SRT>H
Repeat>
OnEvent>KEY_DOWN,VK72,0,I
Until>
End>H
SRT>I
Repeat>
OnEvent>KEY_DOWN,VK73,0,MyText
Until>
End>I
SRT>MyText
MDL>Done
End>MyText
OnEvent>KEY_DOWN,VK72,0,I
line doesn't work. Can you tell me why?
And I tried this too, but it failed because WaitKeyDown works too slow.
Code: Select all
Repeat>
OnEvent>KEY_DOWN,VK190,0,HI
Until>
SRT>HI
WaitKeyDown>h
WaitKeyDown>i
MDL>Done
End>HI
- Dorian (MJT support)
- Automation Wizard
- Posts: 1415
- Joined: Sun Nov 03, 2002 3:19 am
Re: how to boilerplate macros
You have the OnEvent in an endless loop which doesn't seem like a good idea as you only need that to run once. It didn't work for me either so I changed it so it will look for ., then move on to look for the h, then the i.
tbh this approach doesn't make much sense to me as I have a feeling it could get a bit unwieldy and confusing, but here is what you asked for. You can add another endless loop at the end if you want it to run constantly :
Run it through step by step in the debugger for better understanding (if needed).
tbh this approach doesn't make much sense to me as I have a feeling it could get a bit unwieldy and confusing, but here is what you asked for. You can add another endless loop at the end if you want it to run constantly :
Code: Select all
//.
OnEvent>KEY_DOWN,VK190,0,HH
repeat>hhh
Until>hhh,1
//h
OnEvent>KEY_DOWN,VK190,0,
OnEvent>KEY_DOWN,VK72,0,II
repeat>iii
Until>iii,1
//i
OnEvent>KEY_DOWN,VK72,0,
OnEvent>KEY_DOWN,VK73,0,MyText
repeat>jjj
Until>jjj,1
srt>HH
let>hhh=1
END>HH
srt>II
let>iii=1
END>II
srt>MyText
let>jjj=1
Send>This is some text
END>MyText
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: how to boilerplate macros
Ok, this isn't working because of the bug with passing variables from OnEvent but I think this is kinda how mhcha want to roll. I could see a use for this type of script. I would imagine you may want to flush the "buffer string" after x amount of seconds. Also you would probably want to add some more "awareness" of the script's surroundings (maybe only trigger if notepad is active etc.). But I do like the idea presented by mhcha.
Code: Select all
Let>MAX_STRING_LENGTH=12
//just some different trigger combinations..
Let>TRIGGER_STRINGS=.hi|h.i|.hh
Let>BUFFER_STRING=
StringReplace>TRIGGER_STRINGS,.,\.,TRIGGER_STRINGS
StringReplace>TRIGGER_STRINGS,+,\+,TRIGGER_STRINGS
Let>REGEX_PATTERN=^(%TRIGGER_STRINGS%)
OnEvent>KEY_DOWN,VK190,0,COUNT_LETTERS,{"."}
OnEvent>KEY_DOWN,VK72,0,COUNT_LETTERS,{"h"}
OnEvent>KEY_DOWN,VK73,0,COUNT_LETTERS,{"i"}
//ESC=close app
OnEvent>KEY_DOWN,VK27,0,CLOSE_APP
Label>RESTART_LOOP
Wait>0.02
Goto>RESTART_LOOP
SRT>CLOSE_APP
Exit>
END>CLOSE_APP
SRT>COUNT_LETTERS
Let>BUFFER_STRING=%COUNT_LETTERS_Var_1%%BUFFER_STRING%
MidStr>BUFFER_STRING,1,MAX_STRING_LENGTH,BUFFER_STRING
RegEx>REGEX_PATTERN,BUFFER_STRING,0,TEMP_found,TEMP_count,0,,
If>TEMP_count>0
MessageModal>TEMP_found_1
Endif>
END>COUNT_LETTERS
Re: how to boilerplate macros
Thank you Dorian and Grovkillen for responding to my post.
I just checked my post.
Dorian's method worked for me and is currently being used with some minor modifications. Thank you.
Grovkillen's idea was what I needed, but unfortunately it doesn't work as a bug.
I hope you both have a good day.
Thank you.
I just checked my post.
Dorian's method worked for me and is currently being used with some minor modifications. Thank you.
Grovkillen's idea was what I needed, but unfortunately it doesn't work as a bug.
I hope you both have a good day.
Thank you.