Jump to content

Detect program lose or gain focus/active window


Go to solution Solved by Zedna,

Recommended Posts

Posted (edited)

Hi there,

I wonder how to check if the current Autoit program is losing the focus because the user swaps to another program, or gains the focus again.

Infact I want to check this to disable/enable a bunch of hotkeys that I want to be available only when my Autoit program has focus...

(a solution in form of an event would be preferable, because I'm in GUIOnEventMode 1)

Edited by binbinhfr
Posted (edited)
  On 10/29/2021 at 9:44 PM, Zedna said:

Look at these functions in helpfile:

WinGetState()

ControlGetFocus()

 

Expand  

Thanks !

Maybe ControlGetFocus is not for my precise case, but WinGetState is the solution.

Is there a way to trigger the WinGetState() test using an event that detects some changes in the window ?

Or should I check it regularly based on a timer ?

Edited by binbinhfr
  • Solution
Posted (edited)
  On 10/29/2021 at 9:02 PM, binbinhfr said:

Infact I want to check this to disable/enable a bunch of hotkeys that I want to be available only when my Autoit program has focus...

Expand  

 

In this case use GUISetAccelerators() instead of HotkeySet().

Such accelerators are active only in your GUI by default.

Edited by Zedna
Posted
  On 10/30/2021 at 12:06 PM, Zedna said:

 

In this case use GUISetAccelerators() instead of HotkeySet().

Such accelerators are active only in your GUI by default.

Expand  

oh great, I did not know this one !

but as I see, you can only attach keys to existing Controls. Not possible to have a key attached to a function (or maybe with a trick using hidden controls ?). But it's already a big help ! Thanks.

Posted (edited)

So I tried the accelerators, but they works randomly, very strange.

Infact, it seems that I need to click the button once before being able to use the accelerator bound to this button...

Do I miss something ?

Note that my hotkeys worked fine directly calling the callback of the same button.

Forget it, I made an error with the array size, that must be precise....

 

Edited by binbinhfr

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...