Jump to content

MouseHook xbuttons


Go to solution Solved by j0kky,

Recommended Posts

Posted

Good morning all,

As stated above in the title, I'm curious if it's even possible to have a mousehook strictly on the xbutton1 and xbutton2 so i can basically remap the entire function in my tool without it still responding and trying to go to the next or last page in explorer...

Also obviously if it's possible how >.< been searching my ... off

With regards,

Hawkysoft

Posted

What is xbutton1 and xbutton2? Are these variables defined by you? What exactly are you trying to do? I dont understand the request.

Xbutton1 and 2 are the side buttons on the mouse mate.

Basically I assigned new functions to them, however they still have their original functions (page back and foreward) I would like to know how to make en hook for this so I'd be capable to block it's normal function.

Hope this makes more sense :)

Posted (edited)

You can disable mouseclicks or you can add a function to the existent click. But you can't block the normal click function and replace it with yours.

But maybe there is a workaround:

#include <GUIConstantsEx.au3>

HotKeySet("{ESC}", "_Exit")
Opt("GUIOnEventMode", 1)
WinSetTrans(GUICreate("some"), "", 1)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_PrimaryDown")
GUISetState(@SW_MAXIMIZE)
While 1
    Sleep(1000)
WEnd

Func _PrimaryDown()
    ConsoleWrite("The primary mouse button was pressed." & @CRLF)
EndFunc

Func _Exit()
    Exit
EndFunc
Edited by j0kky
Posted

I've to correct myself: you can block the normal click function and replace it with yours.

Here is how you can do it:

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

HotKeySet("{ESC}", "Cleanup")
Global $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "LRESULT", "int;wparam;lparam")
$hMod = _WinAPI_GetModuleHandle(0)
Global $g_hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)

While 1
    Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndIf
    Switch $wParam
        Case $WM_LBUTTONDOWN, $WM_LBUTTONUP, $WM_RBUTTONDOWN, $WM_RBUTTONUP
            ConsoleWrite("something" & @CRLF)
            Return 1
        Case Else
            Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndSwitch


EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_KeyProc)
    Exit
EndFunc   ;==>Cleanup
Posted

Here it is for Xbuttons

#include <winapi.au3>
#include <WindowsConstants.au3>
HotKeySet('{ESC}', '_Close')

Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
Global $hHook
Local $hFunc, $pFunc, $hMod

$hFunc = DllCallbackRegister('_MouseProc', 'long', 'int;wparam;lparam')
$pFunc = DllCallbackGetPtr($hFunc)
$hMod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pFunc, $hMod)

While 1
    Sleep(20)
WEnd

Func _MouseProc($iCode, $iwParam, $ilParam)
    If $iCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)

    Local $info = DllStructCreate($MSLLHOOKSTRUCT, $ilParam) 
    Switch $iwParam
        Case $WM_XBUTTONDOWN
            MsgBox(4096, "", "XButton " & _WinAPI_HiWord(DllStructGetData($info, "mouseData")))
    EndSwitch
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc

Func _Close()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hHook)
    Exit
EndFunc
Posted

@Mikell: I didn't read for XButtons. However if you want to block the default click function you need to Return something different from 0.

 

Thanks so far for the help mate, however it's not actually blocking the function yet ;/

#include <winapi.au3>
#include <WindowsConstants.au3>
HotKeySet('{ESC}', '_Close')

Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
Global $hHook
Local $hFunc, $pFunc, $hMod

$hFunc = DllCallbackRegister('_MouseProc', 'long', 'int;wparam;lparam')
$pFunc = DllCallbackGetPtr($hFunc)
$hMod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pFunc, $hMod)

While 1
    Sleep(20)
WEnd

Func _MouseProc($iCode, $iwParam, $ilParam)
    If $iCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)

    Local $info = DllStructCreate($MSLLHOOKSTRUCT, $ilParam)
    Switch $iwParam
    Case $WM_XBUTTONDOWN
       Local $test = _WinAPI_HiWord(DllStructGetData($info, "mouseData"))
            If $test = "1" Then
               Beep(500,500) ;also tried to Return 0 under it but didnt do the job either ;/
            EndIf
    EndSwitch
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc

Func _Close()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hHook)
    Exit
EndFunc
  • Solution
Posted (edited)

however it's not actually blocking the function yet ;/

Because, as I wrote, you don't Return the correct value.

This is the right version of the script:

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

HotKeySet("{ESC}", "Cleanup")
Global $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "LRESULT", "int;wparam;lparam")
$hMod = _WinAPI_GetModuleHandle(0)
Global $g_hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)
Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"

While 1
    Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndIf
    Local $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam)
    Switch $wParam
        Case $WM_XBUTTONDOWN, $WM_XBUTTONUP, $WM_XBUTTONDBLCLK, $WM_NCXBUTTONDOWN, $WM_NCXBUTTONUP, $WM_NCXBUTTONDBLCLK
            If _WinAPI_HiWord(DllStructGetData($info, "mouseData")) = 1 Then
                ConsoleWrite("The first X button was pressed or released." & @CRLF)
            Else
                ConsoleWrite("The second X button was pressed or released." & @CRLF)
            EndIf
            Return 1
        Case Else
            Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndSwitch


EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_KeyProc)
    Exit
EndFunc   ;==>Cleanup
Edited by j0kky
Posted

 

Because, as I wrote, you don't Return the correct value.

This is the right version of the script:

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

HotKeySet("{ESC}", "Cleanup")
Global $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "LRESULT", "int;wparam;lparam")
$hMod = _WinAPI_GetModuleHandle(0)
Global $g_hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)
Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"

While 1
    Sleep(10)
WEnd

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndIf
    Local $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam)
    Switch $wParam
        Case $WM_XBUTTONDOWN, $WM_XBUTTONUP, $WM_XBUTTONDBLCLK, $WM_NCXBUTTONDOWN, $WM_NCXBUTTONUP, $WM_NCXBUTTONDBLCLK
            If _WinAPI_HiWord(DllStructGetData($info, "mouseData")) = 1 Then
                ConsoleWrite("The first X button was pressed or released." & @CRLF)
            Else
                ConsoleWrite("The second X button was pressed or released." & @CRLF)
            EndIf
            Return 1
        Case Else
            Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndSwitch


EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_KeyProc)
    Exit
EndFunc   ;==>Cleanup

Thank you so much!!!

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
  • Recently Browsing   0 members

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