Make a GUI that disappears when a Window isn't in focus anymore

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AtleastItried
Posts: 51
Joined: 03 Mar 2017, 04:51

Make a GUI that disappears when a Window isn't in focus anymore

01 May 2018, 11:20

I have made some code that only appears ontop of OneNote and offers some buttons. The problem I have with it is that when I press the button it gets focus so the GUI
disappears. I have found two possible solutions, but I'm not sure how to implement them.

My first idea would be to make the GUI unfocusable, but as stated I don't how that would work.

The second thought is that I could make

Code: Select all

WinWaitNotActive  ‎- OneNote
Only pass when neither the OneNote nor the GUI are active, but I also don't know how to pass two possible programs into the command.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force
#Notrayicon

    SetTitleMatchMode 2

    Gui +LastFound -Caption +ToolWindow +Border + AlwaysOnTop
    Gui Add, Button, gDublicate x-1 y-1 w60 h25, Dublicate
    Gui Add, Button, gDelete x57 y-1 w60 h25, Delete
    Gui Add, Button, gBackwards x115 y-1 w25 h25, ←
    Gui Add, Button, gForwards x138 y-1 w25 h25, →

    Loop{
        WinWaitActive  ‎- OneNote
        Gui, Show, xCenter y35 NoActivate h23 w162
        WinWaitNotActive  ‎- OneNote
        Gui Hide
    }

    return:

    Dublicate:
        WinActivate  ‎- OneNote
        SendInput ^c
        Sleep 50
        SendInput ^v
    return

    Delete:
        WinActivate  ‎- OneNote   
        SendInput {Del}
    return

    Backwards:
        WinActivate  ‎- OneNote   
        SendInput ^z
    return

    Forwards:
        WinActivate  ‎- OneNote   
        SendInput ^y
    return
softwareeater
Posts: 42
Joined: 31 Aug 2015, 11:33

Re: Make a GUI that disappears when a Window isn't in focus anymore

01 May 2018, 11:33

WinWaitNotActive can accept window groups: https://autohotkey.com/docs/misc/WinTitle.htm#ahk_group
I'm guessing you could add both OneNote and your GUI to a group and use that.
AtleastItried
Posts: 51
Joined: 03 Mar 2017, 04:51

Re: Make a GUI that disappears when a Window isn't in focus anymore

01 May 2018, 11:55

softwareeater wrote:WinWaitNotActive can accept window groups: https://autohotkey.com/docs/misc/WinTitle.htm#ahk_group
I'm guessing you could add both OneNote and your GUI to a group and use that.
I will try, but wouldn't it then wait until either is Not Active instead of both and as such immediately pass?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], macromint, peter_ahk, Spawnova and 268 guests