Sign in to follow this  
Followers 0
gsb

Is there a GUI window event for 'onFocus'

10 posts in this topic

I am still to new to know all that's in the help files.

And my search failed to get me going.

The question is for the control to "know" when it is given system focus.

An example would be when top most window is deleted and the control underneath now gains focus.

Is there an event I could capture and use at this time?

Thanks. All here are a great help in my learning how to use AutoIt.

gsb


"Did you ever stop to think? ...and forget to restart!"

Share this post


Link to post
Share on other sites



Not exactly what you mean, but you can use $GUI_FOCUS. Example:

#include <GUIConstants.au3>
GUICtrlSetState($control, $GUI_FOCUS) ;Will give focus to a control

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites

Check out GUIGetCursorInfo in the help file and look at the 4th element the array returns. You could stick that in a loop and watch that.

Share this post


Link to post
Share on other sites

Check out GUIGetCursorInfo in the help file and look at the 4th element the array returns. You could stick that in a loop and watch that.

That or use GUIRegisterMsg() with it.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks both of you but... I think they are not quite it.

I do not need to give it focus but rather find out when the system gives focus to the window.

Like in a "tag, your it!" kind of way.

Any more ideas? ...thanks.

***EDIT: Sorry SmOke_N. I over posted... slow at typing here.

But looks like that may be it with WM_ACTIVATE perhaps.

I will try when I get home... Work calls just now. :whistle:

gsb

Edited by gsb

"Did you ever stop to think? ...and forget to restart!"

Share this post


Link to post
Share on other sites

Thanks both of you but... I think they are not quite it.

I do not need to give it focus but rather find out when the system gives focus to the window.

Like in a "tag, your it!" kind of way.

Any more ideas? ...thanks.

gsb

If it's a window and not a control... If WinActive() Then...

Tag... you're it.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

So here is what I ended up with and it works just fine, TYVM:

$myWinTitle = "gsb Test GUI"

$Main = GUICreate( $myWinTitle, 200, 100)

GUISetState()

$lastWinActive = 1


While 1

    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch

    $currentWinActive = WinActive( $myWinTitle )
    If ($currentWinActive == 1) AND ($lastWinActive == 0) Then
    MsgBox(64,"Win Active", $myWinTitle & " went active.  ", 3)
    EndIf
    $lastWinActive = $currentWinActive

WEnd

Any improvements are welcomed.

Again, thanks all. :whistle:

gsb


"Did you ever stop to think? ...and forget to restart!"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

gsb

Any improvements are welcomed.

Just litle shorter :whistle: :

$myWinTitle = "gsb Test GUI"

$Main = GUICreate( $myWinTitle, 200, 100)

GUISetState()

While GUIGetMsg() <> -3
    If WinActive($myWinTitle) Then MsgBox(64,"Win Active", $myWinTitle & " went active.  ", 3)
    Sleep(10)
WEnd
Edited by MsCreatoR

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Or if i understand right, this will be more correct for you mission :whistle:

$myWinTitle = "gsb Test GUI"

$Main = GUICreate( $myWinTitle, 200, 100)

GUISetState()

$lastWinActive = 1


While GUIGetMsg() <> -3
    $currentWinActive = WinActive( $myWinTitle )
    If $currentWinActive AND Not $lastWinActive Then MsgBox(64,"Win Active", $myWinTitle & " went active.  ", 3)
    $lastWinActive = $currentWinActive
WEnd

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Thanks MsCreatoR,

Your second example is more what I am doing.

But I do need the switch for in the application I have many other events to respond to.

I stripped it here for the essentials.

The shorthand code for the if I will use, Thank you.

gsb


"Did you ever stop to think? ...and forget to restart!"

Share this post


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
Sign in to follow this  
Followers 0