Jump to content

Detect program lose or gain focus/active window


Go to solution Solved by Zedna,

Recommended Posts

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
Link to post
Share on other sites
1 hour ago, Zedna said:

Look at these functions in helpfile:

WinGetState()

ControlGetFocus()

 

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
Link to post
Share on other sites
  • Solution
15 hours ago, 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...

 

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

Such accelerators are active only in your GUI by default.

Edited by Zedna
Link to post
Share on other sites
46 minutes ago, Zedna said:

 

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

Such accelerators are active only in your GUI by default.

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.

Link to post
Share on other sites

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
Link to post
Share on other sites

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...