Preserving/restoring current control focus

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
robnicholson
Posts: 12
Joined: 07 May 2020, 07:38

Preserving/restoring current control focus

Post by robnicholson » 03 Jun 2023, 08:45

I've written a very useful pop-up dialogue that allows me to select text from a list and uses sendinput to write the selected text into the current control. It works a treat on Windows applications where the focus is restored to the original control, thus pasting into the right box.

However, it doesn't work in the web browser. In this screenshot, the focus was in the text box on the right. However, when the Gui window closes, the focus isn't in that window anymore. I suspect it's just of the overall web browser.

Is there anyway to query the current browser window/control and restore it afterwards?

Image

ntepa
Posts: 428
Joined: 19 Oct 2022, 20:52

Re: Preserving/restoring current control focus

Post by ntepa » 04 Jun 2023, 02:26

You could create a gui that can't be focused:

Code: Select all

WS_EX_NOACTIVATE := 0x08000000 ; prevent gui focus
myGui := Gui("+E" WS_EX_NOACTIVATE " +AlwaysOnTop")
LB := myGui.Add("ListBox", "w300", ["text1", "text2", "text3"])
LB.OnEvent("Change", LB_Click)
myGui.Show("NA w300")

LB_Click(guiCtrlObj, Info) {
    Send guiCtrlObj.Text
}

Post Reply

Return to “Ask for Help (v2)”