Jump to content

MouseHook xbuttons


Hawkysoft
 Share

Go to solution Solved by j0kky,

Recommended Posts

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_UnhookWindowsHookEx.htm is all I could find. Is there a utility for your mouse that would allow you to modify the actions of the buttons?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

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

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

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

@Mikell: your function doesn't block the default click, also it's not good using a blocking function as MsgBox in a processing-message function.

Edited by j0kky
Link to comment
Share on other sites

@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
Link to comment
Share on other sites

  • Solution

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

 

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!!!

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