binbinhfr Posted October 29, 2021 Share Posted October 29, 2021 (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 October 29, 2021 by binbinhfr Link to comment Share on other sites More sharing options...
Zedna Posted October 29, 2021 Share Posted October 29, 2021 (edited) Look at these functions in helpfile: WinGetState() ControlGetFocus() Edited October 29, 2021 by Zedna binbinhfr 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
binbinhfr Posted October 29, 2021 Author Share Posted October 29, 2021 (edited) 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 October 29, 2021 by binbinhfr Link to comment Share on other sites More sharing options...
Solution Zedna Posted October 30, 2021 Solution Share Posted October 30, 2021 (edited) 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 October 30, 2021 by Zedna binbinhfr 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
binbinhfr Posted October 30, 2021 Author Share Posted October 30, 2021 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 comment Share on other sites More sharing options...
Zedna Posted October 30, 2021 Share Posted October 30, 2021 (edited) Look here - solution for this using GUICtrlCreateDummy() Edited October 30, 2021 by Zedna binbinhfr 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
binbinhfr Posted October 30, 2021 Author Share Posted October 30, 2021 16 minutes ago, Zedna said: Look here - solution for this using GUICtrlCreateDummy() 😃 nice ! Thanks Link to comment Share on other sites More sharing options...
binbinhfr Posted October 30, 2021 Author Share Posted October 30, 2021 (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 October 30, 2021 by binbinhfr Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now