My goal is to simulate jumping to predefined delimiters in a window's typed text. This function is seen in applications like Dragon Naturally Speaking (next field command jumping to whatever text is in []) and in the Epic Electronic Medical Record (F2, if I remember correctly jumping to ***). The purpose is to have templates where I can jump to the predefined fields and either edit them or accept what is there. I have a functional way of doing this with the below code, but it is too slow. The code checks the active window's text and how many characters it is, puts it in a variable, RegExMatch's [] with any amount of text between the brackets and gets the first instances position and length, counts the number of return lines between that position, presses left enough times to put the caret at the start of the text to have a consistent starting position, then presses right enough to get placed just before the desired text, finally holding shift+right enough times to highlight the text.
While that is fast enough when trialing it in a Notepad document, when I connect to our very old system from home through Citrix, the delay with larger amount of texts while the computer presses right 500 times actually takes a couple of seconds, to the point where it's just be easier to look through and use the mouse to highlight what I want, defeating the purpose.
So, does anyone have a good way to hunt through editable text in programs that don't have an innate search function? It is also limited to the point where "Active Window" doesn't pull the specific text (uncertain if it is the program itself or accessing it through Citrix, but am using Ctrl+A/Ctrl+C to copy the text into a clipboard variable to work with it), and doesn't recognize Ctrl+down for skipping through paragraphs. I know there are AHK variables for the X and Y positions of the caret, but it appears those are read only. Or if there is a way to practically convert character position in a string to X and Y coordinates, then I could just have the mouse click at that spot. I'm fairly new to coding, but pick up things pretty quickly, so any pointers in possible directions would be useful.
V/r,
NiptheZephyr
Code: Select all
;Select next Field. Works in Notepad, but not in AHLTA through Citrix since AHLTA doesn't seem to let WinGetText, windowText, A work. May be able to get this working if I can dive into the HWND. Also need to check and see if this works on AHLTA that is accessed directly. Works with ^a,^c to set the clipboard as the windowText variable.
^+n:: ;jump to and highlight first delimiter
Sleep, 200 ;used to get rid of text if using a hotstring
WinGetText, windowText, A ;look for all the text in the active window, assign it to %windowText%
characterCount := StrLen(windowText) ;count number of characters to know how far back to set the cursor
RegExMatch(windowText, "O)\[.*?]", delimiter) ;search for the first occurance of [*], name stored in delimiter.Value, Position stored in delimiter.Pos, and length stored in delimiter.Len
NeedleAmount := 0 ;create variable with a value. The below few lines modified from a post by Leroxy: https://autohotkey.com/board/topic/26018-counting-characters-and-lines/
Loop % delimiter.Pos ;check all characters up through the delimiter for returns.
{
ReturnsBeforeDelimiter := InStr(windowText, Chr(13) ,false,A_index)
If A_index = %ReturnsBeforeDelimiter%
{
NeedleAmount := NeedleAmount + 1
}
}
Loop, %characterCount% ;set cursor at beginning of text
{
Send, {Left}
}
counter := delimiter.Pos - NeedleAmount - 1 ;count up the number of spaces needed to get to the start of the delimiter; NeedleAmount gets rid of 'r'n, and -1 sets you right before it.
Loop % counter ;move to just left of the delimiter
{
Send, {Right}
}
Loop % delimiter.Len ;highlight the delimiter
{
Send, +{right}
}
Return
+esc:: ExitApp