With help from this forum, I have made each key on the keyboard a context-sensitive hotkey. With each entered letter, the script clicks the search button and returns cursor focus to the search text box using a Controlclick command. When this happens, the entire entry is highlighted. To get the cursor to the end of the entry in the textbox, I have to send right clicks so that the cursor is properly positioned for the next keystroke.
It works fine if the user types slowly. The problem comes when the user types too fast. What happens is that the second hotkey is sent while the entry is still highlighted, before the "SendInput {right 20}" is executed. So if I type slowly A-N-D-E-R-S-O-N it properly searches for "Anderson." But if I type slowly A-N-D-E-R then type S-O-N really fast, the "O" hotkey is sent while the "ANDERS" is still highlighted. So "ANDERS" is replaced by "ON" and the script searches for last names starting with "ON."
I have tried making the subroutine Critical, that didn't help. Any suggestions are welcome. This is an addon I wrote for an electronic health record and some docs would like the functionality improved. Thanks in advance.
The hotkeys:
string = ; I think this is a legacy from an older script
length = 0
k_n = 1
k_ASCII = 45
Hotkey, IfWinActive, Patient Lookup ; makes hotkeys context-sensitive Diagnosis Code window
Hotkey, ~*Enter, k_LookupEnter, on
Hotkey, ~*Backspace, k_Lookup, on
Hotkey, ~*Delete, k_Lookup, on
Hotkey, ~*numpad0, k_Lookup, on
Hotkey, ~*numpad1, k_Lookup, on
Hotkey, ~*numpad2, k_Lookup, on
Hotkey, ~*numpad3, k_Lookup, on
Hotkey, ~*numpad4, k_Lookup, on
Hotkey, ~*numpad5, k_Lookup, on
Hotkey, ~*numpad6, k_Lookup, on
Hotkey, ~*numpad7, k_Lookup, on
Hotkey, ~*numpad8, k_Lookup, on
Hotkey, ~*numpad9, k_Lookup, on
Loop
{
Transform, k_char, Chr, %k_ASCII%
StringUpper, k_char, k_char
if k_char not in <,>,^,~,,`,
Hotkey, ~*%k_char%, k_Lookup, on
; In the above, the asterisk prefix allows the key to be detected regardless
; of whether the user is holding down modifier keys such as Control and Shift.
if k_ASCII = 93
break
k_ASCII++
}
Hotkey, IfWinActive ; turn off context sensitivityThe subroutine:
k_LookupEnter:
ControlClick, ThunderRT6CommandButton18, ahk_class ThunderRT6FormDC,,,2
return
k_Lookup:
ControlGetFocus, focus, Patient Lookup
If ((focus <> "ThunderRT6TextBox18") && (focus <> "ThunderRT6TextBox19"))
{
return
}
ControlClick, ThunderRT6CommandButton5, ahk_class ThunderRT6FormDC,,,2 ; clicks search
If (focus = "ThunderRT6TextBox18")
{
ControlClick, ThunderRT6TextBox18, ahk_class ThunderRT6FormDC,,,2 ; returns focus to the last name textbox
}
If (focus = "ThunderRT6TextBox19")
{
ControlClick, ThunderRT6TextBox19, ahk_class ThunderRT6FormDC,,,2 ; returns focus to the first name textbox
}
SendInput {right 20} ; textboxes are highlighted, so it is necessary to send right to move cursor to the end
return




