Check if an input field is active (v2 edition)

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Ross
Posts: 100
Joined: 13 Mar 2016, 00:27

Check if an input field is active (v2 edition)

Post by Ross » 10 Jun 2023, 15:36

Hi,
Sometime before I wrote this,when asking the following question for v1:
Is it possible to determine if an input field is active and ready to receive text? I mean, I have some hotstrings defined, and some applications that rely on sequences of keystrokes that could potentially conflict with hotstrings (trigger them). The most obvious example is the Vimium extension for the major web browsers, which allows navigation by keypresses instead of mouse scrolling.

Other example is Microsoft Word just as you press ALT to begin typing the combo keys to activate some functionality. If you look closely, the blinking cursor will disappear from the document at that very moment until you finish typing the key sequence.

Put simply, I'd like to know if AHK can detect whether there is a blinking cursor on screen, which means the interface is expecting some input text. in other words, to have hotstrings trigger only if the active field is an inputbox, like this writing area. That would be the ideal and only scenario for hotstrings to trigger, except if you define one specifically to perform some action other than expanding abbreviations.

Any clues?
Since migrating to v2, I've tried this...

Code: Select all

'::
{
CaretGetPos(&x, &y)
    if (x != "" && y != ""){
    MsgBox("TYPE AWAY! TEXT WILL BE INSERTED!")
}
    else {
    MsgBox("No input field is selected/active.")
    }

}
...but it's simply not reliable; it will report some situations as "type ready" when there is no input field active (caret is not visible). The opposite is also true.
I also suspect the CaretGetPos function will work differently in Windows "standard", "traditional" apps, and in "modern", "UWP" apps or those built with the Electron interface.

Does anyone have an idea for a different approach?

User avatar
Ross
Posts: 100
Joined: 13 Mar 2016, 00:27

Re: Check if an input field is active (v2 edition)

Post by Ross » 23 Jun 2023, 09:22

Anybody? :(


Post Reply

Return to “Ask for Help (v2)”