Sign in to follow this  
Followers 0
Skitty

Mouse hook troubles

9 posts in this topic

#1 ·  Posted (edited)

So I was messing around with mouse hooks, seems to be a problem when you throw a GUI in the game and the script doesn't play well when its around.

My problem is that the script will randomly crash upon exiting the app.

Here's an example that replicates this behavior.

#include <WinAPI.au3>

AutoItSetOption("GUIOnEventMode", 1)

Global $hMouseHook = -1
Global $hMouseProc = -1
Global $Mouse

GUICreate("Test", 350, 300)
GUISetBkColor(0)
GUISetOnEvent(-3, "Terminate")
OnAutoItExitRegister("Terminate")
GUISetState()

$Lable = GUICtrlCreateLabel("", 0, 0, 350, 300)
GUICtrlSetFont(-1,225, 700)
GUICtrlSetColor(-1, 0xFFFF00)
_UI_SetMouseHook(1)

For $I = 10 To 0 Step -1
    GUICtrlSetData($Lable, $I)
    Sleep(1000)
Next

Exit

Func Terminate()
    OnAutoItExitUnRegister("Terminate")
    _UI_SetMouseHook()
    Exit
EndFunc

Func _UI_SetMouseHook($DoWhat = 0)
    If Not IsDeclared("DoWhat") Then $Dowhat = 1
    AdlibUnRegister("_UI_SetMouseHook")
    Switch $Dowhat
        Case 1
            If $hMouseProc = -1 Then
                $hMouseProc = DllCallbackRegister("WM_MOUSEMOVE", "int", "uint;wparam;lparam")
            EndIf
            If $hMouseHook = -1 Then
                Local $hM_Module = _WinAPI_GetModuleHandle(0)
                $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), $hM_Module, 0)
            EndIf

        Case 0

            If $hMouseHook <> -1 Then
                _WinAPI_UnhookWindowsHookEx($hMouseHook)
                $hMouseHook = -1
            EndIf

            If $hMouseProc <> -1 Then
                DllCallbackFree($hMouseProc)
                $hMouseProc = -1
            EndIf
    EndSwitch
EndFunc

Func WM_MOUSEMOVE($nCode, $wParam, $lParam)
    #forceref $nCode, $wParam, $lParam
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing
    EndIf

    Switch BitAND($wParam, 0xFFFF)
        Case 513
            Beep(800, 1)
        Case 514; mouse up
            Beep(5000, 1)
        Case 512; mouse moving
            $Mouse = MouseGetPos()
            ToolTip($Mouse[0] & "x" & $Mouse[1])
    EndSwitch

    Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing
EndFunc ;==>WM_MOUSEMOVE

I got the code from MrCreatoR and his MouseOnEvent UDF, it's basically a stripped down version of his UDF.

Also, take not of how the script seems to lag when clicking any of the command buttons.

Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites



ApudAngelorum

Hook_MOUSE

Hook_KEYBOAR

For $I = 3 To 1 Step -1
    GUICtrlSetData($Lable, $I)
    Sleep(1000)
Next
OnAutoItExitUnregister("Terminate")
_UI_SetMouseHook()

Exit
Ok, so this narrows it down to the real problem now.

#include 
#include 
; #include 

Global $hMouseHook, $hStub_KeyProc, $iEditLog, $Gui

;Global Const $WM_MBUTTONDBLCLK = 0x0209
;Global Const $WM_RBUTTONDBLCLK = 0x0206
; Global Const $WM_MOUSEHWHEEL = 0x020E ???
AutoItSetOption("GUIOnEventMode", 1)


_Main()

Func _Main()
OnAutoItExitRegister("Cleanup")

Local $hmod

$hStub_KeyProc = DllCallbackRegister("WM_MOUSEMOVE", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

; Esc - ??? ???????? ???????

$Gui=GUICreate('?????? ????????? ? ?????? ????', 700, 260, -1 , -1)
GUISetOnEvent(-3, "Cleanup")
$iEdit = GUICtrlCreateEdit('', 5, 5, 290, 250)
$iEditLog = GUICtrlCreateEdit('', 300, 5, 390, 250)
GUISetState()

Sleep(999999)
EndFunc
;===========================================================
; callback function
;===========================================================
Func WM_MOUSEMOVE($nCode, $wParam, $lParam)
#forceref $nCode, $wParam, $lParam
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing
EndIf

Switch $wParam
Case $WM_LBUTTONDOWN
Beep(800, 1)
Case $WM_LBUTTONUP; mouse up
Beep(5000, 1)
Case Else; mouse moving
Local $tMOUSE = DllStructCreate("uint x;uint y", $lParam)
ToolTip(DllStructGetData($tMOUSE, "x") & "x" & DllStructGetData($tMOUSE, "y"))
EndSwitch

Return ;_WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing
EndFunc ;==>WM_MOUSEMOVE

Func Cleanup()
_WinAPI_UnhookWindowsHookEx($hMouseHook)
DllCallbackFree($hStub_KeyProc)
Exit
EndFunc

Obviously the problem is when GuiOnEventMode is active.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Confirmed, the issue is due to some internal autoit conflict which maybe only the devs would know why.

Everything works flawlessly when "guioneventmode" is set to default.

All I had to do was rewrite the script to not use control events and manage everything through wm notify, comman and syscommand and the script no longer crashes, but there still is a short lag when clicking a title bar button.

http://www.autoitscript.com/forum/topic/96829-solved-how-to-detect-gui-close/#entry698605
Func WM_SYSCOMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam, $ilParam

    Switch BitAND($iwParam, 0xFFF0)
        Case $SC_MOVE
            ConsoleWrite("WM_Move" & @CR)
        Case $SC_SIZE
            ConsoleWrite("WM_Size" & @CR)
Case $SC_MINIMIZE
ConsoleWrite("WM_Minimize" & @CR)
Case $SC_MAXIMIZE
ConsoleWrite("WM_Maximize" & @CR)
Case $SC_RESTORE
ConsoleWrite("WM_Restore" & @CR)
        Case $SC_CLOSE
            ConsoleWrite("WM_Close" & @CR)
            _UI_Terminate()
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

You 2 times to call the same function. I seem to be offered to add this in the help file

OnAutoItExitRegister("Cleanup")
GUISetOnEvent(-3, "Cleanup")

#include <GUIConstantsEx.au3>
OnAutoItExitRegister("_Exit")
Opt("GUIOnEventMode", 1)
$hGui = GUICreate('My Program', 250, 260)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState()
While 1
    Sleep(1000)
WEnd

Func _Exit()
    MsgBox(64+4096, "<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />", 'Exit?')
    Exit
EndFunc

Share this post


Link to post
Share on other sites

You 2 times to call the same function. I seem to be offered to add this in the help file

OnAutoItExitRegister("Cleanup")
GUISetOnEvent(-3, "Cleanup")

#include <GUIConstantsEx.au3>
OnAutoItExitRegister("_Exit")
Opt("GUIOnEventMode", 1)
$hGui = GUICreate('My Program', 250, 260)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState()
While 1
    Sleep(1000)
WEnd

Func _Exit()
MsgBox(64+4096, "<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />", 'Exit?')
    Exit
EndFunc
Yes, I notice the function gets called twice, in the original script I posted you will notice I unset the on exit function to prevent it being called a second time. I did not do it to the second modified example of my issue because it was not something that is overly significant.

But for what it's worth, here is the method I'm using now to avoid the phenomena my initial script was displaying.

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>
#include <GUIConstantsEx.au3>

Global $hMouseHook = -1
Global $hMouseProc = -1
Global $Mouse


_UI_SetMouseHook(1)


GUICreate("Test", 350, 300)
GUISetBkColor(0)
GUISetOnEvent(-3, "Terminate")
OnAutoItExitRegister("Terminate")
GUISetState()

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

$Lable = GUICtrlCreateLabel("", 0, 0, 350, 300)
GUICtrlSetFont(-1,225, 700)
GUICtrlSetColor(-1, 0xFFFF00)

For $I = 10 To 1 Step -1
    GUICtrlSetData($Lable, $I)
    Sleep(1000)
Next

Exit

Func Terminate()
    OnAutoItExitUnRegister("Terminate")
    _UI_SetMouseHook()
    Exit
EndFunc

Func _UI_SetMouseHook($DoWhat = 0)
    If Not IsDeclared("DoWhat") Then $Dowhat = 1
    Switch $Dowhat
        Case 1
            If $hMouseProc = -1 Then
                $hMouseProc = DllCallbackRegister("WM_MOUSEMOVE", "long", "int;wparam;lparam")
            EndIf
            If $hMouseHook = -1 Then
                Local $hM_Module = _WinAPI_GetModuleHandle(0)
                $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), $hM_Module)
            EndIf

        Case 0

            If $hMouseHook <> -1 Then
                _WinAPI_UnhookWindowsHookEx($hMouseHook)
                $hMouseHook = -1
            EndIf

            If $hMouseProc <> -1 Then
                DllCallbackFree($hMouseProc)
                $hMouseProc = -1
            EndIf
    EndSwitch
EndFunc

Func WM_MOUSEMOVE($nCode, $wParam, $lParam)
    #forceref $nCode, $wParam, $lParam
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing
    EndIf

    Switch $wParam
        Case $WM_LBUTTONDOWN
            Beep(800, 1)
        Case $WM_LBUTTONUP; mouse up
            Beep(5000, 1)
        Case Else; mouse moving
            Local $tMOUSE = DllStructCreate("uint x;uint y", $lParam)
            ToolTip(DllStructGetData($tMOUSE, "x") & "x" & DllStructGetData($tMOUSE, "y"))
    EndSwitch

    Return ;_WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing
EndFunc ;==>WM_MOUSEMOVE

Func WM_SYSCOMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam

    Switch BitAND($iwParam, 0xFFF0)
        Case $SC_MOVE
            ConsoleWrite("WM_Move" & @CR)
        Case $SC_SIZE
            ConsoleWrite("WM_Size" & @CR)
        Case $SC_MINIMIZE
            ConsoleWrite("WM_Minimize" & @CR)
        Case $SC_MAXIMIZE
            ConsoleWrite("WM_Maximize" & @CR)
        Case $SC_RESTORE
            ConsoleWrite("WM_Restore" & @CR)
        Case $SC_CLOSE
            ConsoleWrite("WM_Close" & @CR)
            Terminate()
        Case $SC_SCREENSAVE
            ConsoleWrite("SC_SCREENSAVE" & @CR)
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SYSCOMMAND

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#include <WinAPI.au3>

#include <WindowsConstants.au3>

#include <MenuConstants.au3>

#include <GUIConstantsEx.au3>



Global $hMouseHook = -1

Global $hMouseProc = -1

Global $Mouse





_UI_SetMouseHook(1)





GUICreate("Test", 350, 300)

GUISetBkColor(0)

OnAutoItExitRegister("Terminate")



GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")



$Lable = GUICtrlCreateLabel("", 0, 0, 350, 300)

GUICtrlSetFont(-1,225, 700)

GUICtrlSetColor(-1, 0xFFFF00)



GUISetState()



For $I = 3 To 1 Step -1

    GUICtrlSetData($Lable, $I)

    Sleep(1000)

Next



Exit



Func Terminate()

    _UI_SetMouseHook()

    Exit

EndFunc



Func _UI_SetMouseHook($DoWhat = 0)

    If Not IsDeclared("DoWhat") Then $Dowhat = 1

    Switch $Dowhat

        Case 1

            If $hMouseProc = -1 Then

                $hMouseProc = DllCallbackRegister("WM_MOUSEMOVE", "long", "int;wparam;lparam")

            EndIf

            If $hMouseHook = -1 Then

                Local $hM_Module = _WinAPI_GetModuleHandle(0)

                $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), $hM_Module)

            EndIf



        Case 0



            If $hMouseHook <> -1 Then

                _WinAPI_UnhookWindowsHookEx($hMouseHook)

                $hMouseHook = -1

            EndIf



            If $hMouseProc <> -1 Then

                DllCallbackFree($hMouseProc)

                $hMouseProc = -1

            EndIf

    EndSwitch

EndFunc



Func WM_MOUSEMOVE($nCode, $wParam, $lParam)

    #forceref $nCode, $wParam, $lParam

    If $nCode < 0 Then

        Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing

    EndIf



    Switch $wParam

        Case $WM_LBUTTONDOWN

            Beep(800, 1)

        Case $WM_LBUTTONUP; mouse up

            Beep(5000, 1)

        Case Else; mouse moving

            Local $tMOUSE = DllStructCreate("uint x;uint y", $lParam)

            ToolTip(DllStructGetData($tMOUSE, "x") & "x" & DllStructGetData($tMOUSE, "y"))

    EndSwitch



    Return ;_WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing

EndFunc ;==>WM_MOUSEMOVE



Func WM_SYSCOMMAND($hWnd, $iMsg, $iwParam, $ilParam)

    #forceref $hWnd, $iMsg, $iwParam, $ilParam



    Switch BitAND($iwParam, 0xFFF0)

        Case $SC_MOVE

            ConsoleWrite("WM_Move" & @CR)

        Case $SC_SIZE

            ConsoleWrite("WM_Size" & @CR)

        Case $SC_MINIMIZE

            ConsoleWrite("WM_Minimize" & @CR)

        Case $SC_MAXIMIZE

            ConsoleWrite("WM_Maximize" & @CR)

        Case $SC_RESTORE

            ConsoleWrite("WM_Restore" & @CR)

        Case $SC_CLOSE

            ConsoleWrite("WM_Close" & @CR)

            Terminate()

        Case $SC_SCREENSAVE

            ConsoleWrite("SC_SCREENSAVE" & @CR)

    EndSwitch



    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_SYSCOMMAND

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>
#include <GUIConstantsEx.au3>

Global $hMouseHook = -1
Global $hMouseProc = -1
Global $Mouse


_UI_SetMouseHook(1)


GUICreate("Test", 350, 300)
GUISetBkColor(0)
OnAutoItExitRegister("Terminate")

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

$Lable = GUICtrlCreateLabel("", 0, 0, 350, 300)
GUICtrlSetFont(-1,225, 700)
GUICtrlSetColor(-1, 0xFFFF00)

GUISetState()

For $I = 3 To 1 Step -1
GUICtrlSetData($Lable, $I)
Sleep(1000)
Next

Exit

Func Terminate()
_UI_SetMouseHook()
Exit
EndFunc

Func _UI_SetMouseHook($DoWhat = 0)
If Not IsDeclared("DoWhat") Then $Dowhat = 1
Switch $Dowhat
Case 1
If $hMouseProc = -1 Then
$hMouseProc = DllCallbackRegister("WM_MOUSEMOVE", "long", "int;wparam;lparam")
EndIf
If $hMouseHook = -1 Then
Local $hM_Module = _WinAPI_GetModuleHandle(0)
$hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), $hM_Module)
EndIf

Case 0

If $hMouseHook <> -1 Then
_WinAPI_UnhookWindowsHookEx($hMouseHook)
$hMouseHook = -1
EndIf

If $hMouseProc <> -1 Then
DllCallbackFree($hMouseProc)
$hMouseProc = -1
EndIf
EndSwitch
EndFunc

Func WM_MOUSEMOVE($nCode, $wParam, $lParam)
#forceref $nCode, $wParam, $lParam
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing
EndIf

Switch $wParam
Case $WM_LBUTTONDOWN
Beep(800, 1)
Case $WM_LBUTTONUP; mouse up
Beep(5000, 1)
Case Else; mouse moving
Local $tMOUSE = DllStructCreate("uint x;uint y", $lParam)
ToolTip(DllStructGetData($tMOUSE, "x") & "x" & DllStructGetData($tMOUSE, "y"))
EndSwitch

Return ;_WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing
EndFunc ;==>WM_MOUSEMOVE

Func WM_SYSCOMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam, $ilParam

Switch BitAND($iwParam, 0xFFF0)
Case $SC_MOVE
ConsoleWrite("WM_Move" & @CR)
Case $SC_SIZE
ConsoleWrite("WM_Size" & @CR)
Case $SC_MINIMIZE
ConsoleWrite("WM_Minimize" & @CR)
Case $SC_MAXIMIZE
ConsoleWrite("WM_Maximize" & @CR)
Case $SC_RESTORE
ConsoleWrite("WM_Restore" & @CR)
Case $SC_CLOSE
ConsoleWrite("WM_Close" & @CR)
Terminate()
Case $SC_SCREENSAVE
ConsoleWrite("SC_SCREENSAVE" & @CR)
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SYSCOMMAND
Yeah, that's what I meant to post :P

I'm a little high right now, or a lot...

Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#include <WinAPI.au3>

#include <WindowsConstants.au3>

#include <MenuConstants.au3>

#include <GUIConstantsEx.au3>



Global $hMouseHook = -1

Global $hMouseProc = -1

Global $Mouse





_UI_SetMouseHook(1)





GUICreate("Test", 350, 300)

GUISetBkColor(0)

; GUISetOnEvent(-3, "_Exit")

OnAutoItExitRegister("Terminate")



GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")



$Lable = GUICtrlCreateLabel("", 0, 0, 350, 300)

GUICtrlSetFont(-1,225, 700)

GUICtrlSetColor(-1, 0xFFFF00)



GUISetState()



For $I = 13 To 1 Step -1

    GUICtrlSetData($Lable, $I)

    Sleep(1000)

Next



Exit



Func Terminate()

    _UI_SetMouseHook()

EndFunc



Func _Exit()

    Exit

EndFunc



Func _UI_SetMouseHook($DoWhat = 0)

    If Not IsDeclared("DoWhat") Then $Dowhat = 1

    Switch $Dowhat

        Case 1

            If $hMouseProc = -1 Then

                $hMouseProc = DllCallbackRegister("WM_MOUSEMOVE", "long", "int;wparam;lparam")

            EndIf

            If $hMouseHook = -1 Then

                Local $hM_Module = _WinAPI_GetModuleHandle(0)

                $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), $hM_Module)

            EndIf



        Case 0



            If $hMouseHook <> -1 Then

                _WinAPI_UnhookWindowsHookEx($hMouseHook)

                $hMouseHook = -1

            EndIf



            If $hMouseProc <> -1 Then

                DllCallbackFree($hMouseProc)

                $hMouseProc = -1

            EndIf

    EndSwitch

EndFunc



Func WM_MOUSEMOVE($nCode, $wParam, $lParam)

    #forceref $nCode, $wParam, $lParam

    If $nCode < 0 Then

        Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing

    EndIf



    Switch $wParam

        Case $WM_LBUTTONDOWN

            Beep(800, 1)

        Case $WM_LBUTTONUP; mouse up

            Beep(5000, 1)

        Case Else; mouse moving

            Local $tMOUSE = DllStructCreate("uint x;uint y", $lParam)

            ToolTip(DllStructGetData($tMOUSE, "x") & "x" & DllStructGetData($tMOUSE, "y"))

    EndSwitch



    Return ;_WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ;Continue processing

EndFunc ;==>WM_MOUSEMOVE



Func WM_SYSCOMMAND($hWnd, $iMsg, $iwParam, $ilParam)

    #forceref $hWnd, $iMsg, $iwParam, $ilParam



    Switch BitAND($iwParam, 0xFFF0)

        Case $SC_MOVE

            ConsoleWrite("WM_Move" & @CR)

        Case $SC_SIZE

            ConsoleWrite("WM_Size" & @CR)

        Case $SC_MINIMIZE

            ConsoleWrite("WM_Minimize" & @CR)

        Case $SC_MAXIMIZE

            ConsoleWrite("WM_Maximize" & @CR)

        Case $SC_RESTORE

            ConsoleWrite("WM_Restore" & @CR)

        Case $SC_CLOSE

            ConsoleWrite("WM_Close" & @CR)

            _Exit()

        Case $SC_SCREENSAVE

            ConsoleWrite("SC_SCREENSAVE" & @CR)

    EndSwitch



    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_SYSCOMMAND

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

  • Similar Content

    • careca
      By careca
      Hi, so i got this code to detect mouse wheel movement, and i noticed that if i have it running in some application, and then try to use it elsewhere, previous one will stop working.
      Any way to use it on multiple scripts?
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData" $hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr") $hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) $hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE OnAutoItExit() Exit EndSwitch $hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0) Sleep(100) WEnd Func _Mouse_Proc($nCode, $wParam, $lParam) Local $info, $mouseData $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) $mouseData = DllStructGetData($info, 3) Select Case $wParam = $WM_MOUSEWHEEL If _WinAPI_HiWord($mouseData) > 0 Then ConsoleWrite(' - Up - '&@CRLF) ToolTip('Up') Else ConsoleWrite(' - Down - '&@CRLF) ToolTip('Dn') EndIf EndSelect EndFunc ;==>_Mouse_Proc Func OnAutoItExit() DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0]) $hM_Hook[0] = 0 DllCallbackFree($hKey_Proc) $hKey_Proc = 0 EndFunc ;==>OnAutoItExit  
       
    • OldCoder
      By OldCoder
      I had created a hook to get the values of the mouse wheel and button a while back, but have recently wanted more from this small function. I wanted to be able to disable or reroute mouse events by simply placing values into variables, without the need for calling functions. The following is the result.




      #cs MOUSE HOOK This function hooks, (captures), all mouse events and can programmatically disable or redirect them to other functions. Call MWHL_INIT() to initialize. The following variables either offer information or control the flow of mouse events: $MWHL = Wheel turned up or down, (1=up, -1=down, 0=idle) $MBUT = Middle Button, (1=click, 0=not) $BM, (Block Mouse), variables disable or control flow. By making them 1, they will disable an event, (ie. $BMMM=1 disables all Mouse Movement). By placing a function name in them, you can redirect the event to a function, (ie. $BMRD="CapRite" captures the right mouse button and sends it to the CapRite() function): $BMMM = Mouse Move $BMLD = Left Down $BMLU = Left Up $BMRD = Right Down $BMRD = Right Up $BMMD = Middle Down $BMMU = Middle Up $BMMS = Middle Scroll Be sure to set $BM variables to zero to re-enable normal functioning. Finally, to disable the hook, call MWHL(-1,-1,-1). #ce Func MWHL_INIT() Global $MWHL,$BMMS=0,$BMLD=0,$BMLU=0, $BMRD=0, $BMRU=0, $BMMD=0,$BMMU=0,$BMMM=0,$MBUT,$mwhl_call=DllCall("kernel32.dll","hwnd","GetModuleHandle","ptr",0),$mwhl_back=DllCall("user32.dll","hwnd","SetWindowsHookEx","int",14,"ptr",DllCallbackGetPtr(DllCallbackRegister("MWHL","int","hwnd;uint;long")),"hwnd",$mwhl_call[0],"dword",0),$MVAR[12]=["","$BMMM","$BMLD","$BMLU","","$BMRD","$BMRU","","$BMMD","$BMMU","","$BMMS"] EndFunc Func MWHL($h,$m,$l) If $h=-1 AND $m=-1 AND $l=-1 Then Return DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $mwhl_back[0]) Global $MWHL=BitShift(DllStructGetData(DllStructCreate("int X;int Y;dword mouseData",$l),3),16)/120, $MBUT=($m=0x208),$MEVENT=BitAND($m, 0xFFFF) If $MEVENT<512 OR $MEVENT>522 Then Return Local $MV=Execute($MVAR[$MEVENT-511]) If IsString($MV) Then Call($MV) Return 1 EndIf Return $MV EndFunc

      I have tested this a fair amount and then searched the forum for anything just like this, and yes, I know there are other mouse hooks out there, but one of them doesn't seem to get the direction of the mouse wheel, and I just like the simplicity of this one. It's format may seem a bit tight, but I love things that have a lot of power and occupy a little space. Hope someone finds it useful.

      Cheers,

      EDIT: BTW, yes, I know I didn't change the names of the calls from my old, original post, but I felt a bit nostalgic about the original functions and decided to leave their names as they are. If you like, change them to whatever you want.


      *Formatting care of "BrewManNH" Limited. For all your code formatting needs, call BrewManNH's.