Jump to content
Sign in to follow this  
geekycoder

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

Recommended Posts

geekycoder

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

How can autoit register listener for Window's focus and lost focus ? Or do I need to implement it myself.

GUIGetMsg() support only certain window events but not focus and lost focus.

thk :)

Share this post


Link to post
Share on other sites
geekycoder

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 ?

Share this post


Link to post
Share on other sites
CodyBarrett

#Include <WinAPI.au3>

_WinAPI_RegisterWindowMessage($sMessage)

is that what you are looking for?

Share this post


Link to post
Share on other sites
Yashied

#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

Share this post


Link to post
Share on other sites
geekycoder

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

Share this post


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

Share this post


Link to post
Share on other sites
JLogan3o13

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
VAN0

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.

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  

×