I'm not exactly a pro with autohotkey, so I apologize if this is either obvious or impossible:
Is there any way to build a script that would allow me to select the next instance of a certain string of text (i.e. highlight the textso that I can type and replace it with something else)?
I want to create a hotkey that would allow me to select three asterisks in a row: ***
It would be very handy in filling out templates like this:
*** is a *** year old male with a past medical history of *** who presented for evaluation of ***
Any ideas where I could start?
Hotkey to select next instance of text Topic is solved
Re: Hotkey to select next instance of text
I use the following the search through AHK's main window, and select the search phrase. It relies on making a copy of the content of am edit control, so it won't work on controls used in Word or something. In that case, com object may be of use, or just send ^f to use the native search.
Code: Select all
#IfWinActive,ahk_exe AutoHotkey.exe
^f::SearchAHK(1)
f3::
SearchAHK(NewSearch:=0){
Static Needle, hWnd
If (Needle="" || NewSearch){
InputBox,Needle,Find text,Search string:,,300,130,,,,,% Needle
If ErrorLevel || Needle=""
Return Needle:=""
}
If !hWnd
ControlGet,hWnd,Hwnd ,,Edit1,ahk_exe AutoHotkey.exe
ControlGetText,HayStack,Edit1,ahk_exe AutoHotkey.exe
VarSetCapacity(SelectionStart, 4), VarSetCapacity(SelectionEnd, 4)
SendMessage, 0xB0, &SelectionStart, &SelectionEnd,, ahk_id %hWnd% ;EM_GETSEL
SelectionStart := NumGet(SelectionStart, 0, "UInt")
;SelectionEnd := NumGet(SelectionEnd, 0, "UInt")
Sel1:=InStr(HayStack,Needle,,SelectionStart+2)-1
If (Sel1=-1)
Sel1:=InStr(HayStack,Needle)-1
Sel2:=Sel1+StrLen(Needle)
If (Sel1=-1)
Sel1:=Sel2:=0
PostMessage, 0xB1,% Sel1,% Sel2,,ahk_id %hWnd% ;EM_SETSEL
PostMessage, 0xB7,,,,ahk_id %hWnd% ;EM_SCROLLCARET
}
Re: Hotkey to select next instance of text
Thanks for the reply! But I'm having troubles getting that to work in Microsoft Word. It doesn't come up with an error or anything when I load the script, just nothing happens when I actually try to use it.
How exactly would I change your code to search for a generic text string not within AHK?
Also, it doesn't even have to be within Microsoft word (I'm not sure if it's easier to specify the script within Word or not).
How exactly would I change your code to search for a generic text string not within AHK?
Also, it doesn't even have to be within Microsoft word (I'm not sure if it's easier to specify the script within Word or not).
Re: Hotkey to select next instance of text
This is not an answer to your question, but perhaps lintalist might be useful - https://autohotkey.com/boards/viewtopic.php?f=6&t=3378
If you add a snippet like so:
Apart from asking questions you can select items from a list, add dates (or date ranges) and other things including formatting (bold, italics) and images if you know a bit of HTML or Markdown.
Back to your question: Assuming your program(s) has ctrl-f as a shortcut to find text you can do something like this to simply start the search for ***
If you really need it only with MS Word using COM - you do need to to a bit of digging but this seems like a good start http://autohotkey.com/board/topic/91284 ... /?p=577302 (you can remove the bold & alignment lines of course - oWord.Selection.Find.Execute seems to be the magic command. )
If you add a snippet like so:
it will ask you the questions Name, Age, History and Evaluation and paste the sentence in your application such as Word.[[Input=Name]] is a [[Input=Age]] year old male with a past medical history of [[Input=History]] who presented for evaluation of [[Input=Evaluation]]
Apart from asking questions you can select items from a list, add dates (or date ranges) and other things including formatting (bold, italics) and images if you know a bit of HTML or Markdown.
Back to your question: Assuming your program(s) has ctrl-f as a shortcut to find text you can do something like this to simply start the search for ***
Code: Select all
F3::
Send ^f ; open search window
Sleep 100 ; wait for it to appear
Send ***{enter}
Return
Lintalist: website - source (github)