Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WinAPI.au3>
- #include <WindowsConstants.au3>
- Global $hHook, $hStub_KeyProc, $iEditLog, $Gui
- ; в AutoIt3 v3.3.6.1 and below these constants are not defined
- ; Global Const $WM_MBUTTONDBLCLK = 0x0209
- ; Global Const $WM_RBUTTONDBLCLK = 0x0206
- ; Global Const $WM_MOUSEHWHEEL = 0x020E ???
- _Main()
- Func _Main()
- OnAutoItExitRegister("Cleanup")
- Local $hmod
- $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
- $hmod = _WinAPI_GetModuleHandle(0)
- $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
- ; Esc to close the script
- $Gui=GUICreate('An example of interception with a hook', 700, 260, -1 , -1, $WS_OVERLAPPEDWINDOW)
- $iEdit = GUICtrlCreateEdit('', 5, 5, 290, 250)
- $iEditLog = GUICtrlCreateEdit('', 300, 5, 390, 250)
- GUISetState()
- Do
- Until GUIGetMsg()=-3
- EndFunc
- ;===========================================================
- ; callback function
- ;===========================================================
- Func _KeyProc($nCode, $wParam, $lParam)
- Local $tKEYHOOKS, $X, $Y, $tmp, $Delta
- If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ; переход к следующей цепочки хуков в очереди (не срабатывает)
- $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
- ; mouse coordinates X, Y
- $X = DllStructGetData($tKEYHOOKS, "vkCode")
- $Y = DllStructGetData($tKEYHOOKS, "scanCode")
- Switch $wParam
- Case $WM_MOUSEWHEEL ; if the mouse wheel is spinning
- $Delta = BitShift(DllStructGetData($tKEYHOOKS, "flags"), 16) ; определяет вниз или вврх
- If $Delta > 0 Then
- $tmp= 'the mouse wheel moved UP ^'
- Else
- $tmp= 'the mouse wheel shifted DOWN v'
- EndIf
- $tmp &= ' ('&$Delta&')'
- Case $WM_LBUTTONDOWN
- $tmp= 'Left-down'
- Case $WM_LBUTTONUP
- $tmp= 'Left-Up'
- Case $WM_MBUTTONDOWN
- $tmp= 'Middle Button Down'
- Case $WM_MBUTTONUP
- $tmp= 'Middle Button Up'
- Case $WM_RBUTTONDOWN
- $tmp= 'Right Button Down'
- Case $WM_RBUTTONUP
- $tmp= 'Right Button Up'
- Case $WM_XBUTTONDOWN
- $tmp= 'X-Button Down'
- Case $WM_XBUTTONUP
- $tmp= 'X-Button Up'
- #cs
- ; this block does not work
- Case $WM_LBUTTONDBLCLK ; does not work
- $tmp= 'Double click Left mouse button'
- Case $WM_MBUTTONDBLCLK ; does not work
- $tmp= 'Double click with the middle mouse button'
- Case $WM_RBUTTONDBLCLK ; does not work
- $tmp= 'Double-click Right mouse button'
- Case $WM_XBUTTONDBLCLK ; does not work
- $tmp= 'Double-click with the x-mouse button'
- Case $WM_NCLBUTTONDBLCLK
- $tmp= 'Double click Left on title'
- Case $WM_NCLBUTTONDOWN
- $tmp= 'Left Down on title'
- Case $WM_NCLBUTTONUP
- $tmp= 'Left Up on title'
- Case $WM_NCMBUTTONDBLCLK
- $tmp= 'Double click Middle on title'
- Case $WM_NCMBUTTONDOWN
- $tmp= 'Clicking Middle on the title'
- Case $WM_NCMBUTTONUP
- $tmp= 'Middle Clickout on title'
- Case $WM_NCRBUTTONDBLCLK
- $tmp= 'Double click Right on title'
- Case $WM_NCRBUTTONDOWN
- $tmp= 'Clicking Right on the title'
- Case $WM_NCRBUTTONUP
- $tmp= 'Right-click on title'
- Case $WM_NCMOUSEMOVE
- $tmp= 'Moving the mouse in the NOT client area'
- #ce
- ; Case $WM_MOUSEMOVE ; too much log writes
- ; $tmp= 'Moving the mouse in the client area'
- Case Else
- $tmp = ""
- WinSetTitle($Gui, '', "X: "&$X&", Y: "&$Y)
- Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ; transition to the next chain of hooks in the queue
- EndSwitch
- GUICtrlSetData($iEditLog, $tmp& @CRLF, 1)
- ; Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ; transition to the next chain of hooks in the queue
- EndFunc
- Func Cleanup()
- _WinAPI_UnhookWindowsHookEx($hHook)
- DllCallbackFree($hStub_KeyProc)
- EndFunc
Add Comment
Please, Sign In to add comment