Jump to content

Does autoit support Event handling for Window's focus and lost focus


geekycoder
 Share

Recommended Posts

You want GUIRegisterMsg(), see helpfile for syntax and examples.

Hi,

thank for reply.

GUIRegisterMsg seems to work only with windows create with GUICreate (as I find from most examples) ?

If I have existing app like Notepad, how do I use GUIRegisterMsg to listen for window focus event of Notepad ?

Link to comment
Share on other sites

#Include <WinAPI.au3>

_WinAPI_RegisterWindowMessage($sMessage)

is that what you are looking for?

Link to comment
Share on other sites

#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hForm

$hForm = GUICreate('')
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), '_ShellHookProc')
_WinAPI_RegisterShellHookWindow($hForm)

While 1
    Sleep(100)
WEnd

Func _ShellHookProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hForm
            Switch $wParam
                Case $HSHELL_WINDOWACTIVATED
                    ConsoleWrite('Activated: ' & WinGetHandle($lParam) & @CR)
            EndSwitch
    EndSwitch
EndFunc   ;==>_ShellHookProc

Func OnAutoItExit()
    _WinAPI_DeregisterShellHookWindow($hForm)
EndFunc   ;==>OnAutoItExit

WinAPIEx.au3

Link to comment
Share on other sites

#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hForm

$hForm = GUICreate('')
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), '_ShellHookProc')
_WinAPI_RegisterShellHookWindow($hForm)

While 1
    Sleep(100)
WEnd

Func _ShellHookProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hForm
            Switch $wParam
                Case $HSHELL_WINDOWACTIVATED
                    ConsoleWrite('Activated: ' & WinGetHandle($lParam) & @CR)
            EndSwitch
    EndSwitch
EndFunc   ;==>_ShellHookProc

Func OnAutoItExit()
    _WinAPI_DeregisterShellHookWindow($hForm)
EndFunc   ;==>OnAutoItExit

WinAPIEx.au3

Yashied,

thank for the solution. It is very useful.

thank all for the help.

Link to comment
Share on other sites

  • 4 years later...
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hForm

$hForm = GUICreate('')
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), '_ShellHookProc')
_WinAPI_RegisterShellHookWindow($hForm)

While 1
    Sleep(100)
WEnd

Func _ShellHookProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hForm
            Switch $wParam
                Case $HSHELL_WINDOWACTIVATED
                    ConsoleWrite('Activated: ' & WinGetHandle($lParam) & @CR)
            EndSwitch
    EndSwitch
EndFunc   ;==>_ShellHookProc

Func OnAutoItExit()
    _WinAPI_DeregisterShellHookWindow($hForm)
EndFunc   ;==>OnAutoItExit
WinAPIEx.au3

 

Hello.

Can someone please help make this work with AU 3.3.10.2 on W8 x64?

Nothing happens when I run the script and change focus on different windows.

Thank you

Link to comment
Share on other sites

  • Moderators

Van0, there is a reason we don't resurrect 5 year old posts. As you have learned, what worked in 2009 is likely not valid in 2014. You would be better off creating a new topic to ask your question, and linking here if you feel it absolutely necessary.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Sure things. Will do that.

Thanks

P.S.

Perhaps automatic locking or archiving old topics could be implemented?

P.P.S.

a few years back there was a nazi moderator who was giving temp bans left and right to people who asked questions that were previously discussed...and don't you dare complain about it or even worse - create a new account - instant perm ban right there.

Link to comment
Share on other sites

  • Moderators

VAN0,

 

temp bans left and right to people who asked questions that were previously discussed

That does not happen now - but as explained, we would prefer that you open a new thread. ;)

 

even worse - create a new account - instant perm ban right there

But if you were to try to evade a ban in that way, you would still suffer the same penalty. :naughty:

So the best advice is - do not get banned in the first place! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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