Jump to content

How to watch special mouse buttons (event-based)?


 Share

Recommended Posts

Hi,

I have an old Logitech PS/2 mouse, which I like very much due to it's eronomic design. It's software is not working properly on Windows XP (never was), so I'd like to code my own, to re-activate it's thumb-button.

Earlier, in Win2k, this button did the double-click, which was very comfortable.

My question is now, is there a way in AutoIt to read-out the state of that special mouse key?

The only thing I've seen were tools to read-out the state of mouse button left and right, not even the button function of the mouse wheel (like mousewheelup/mousewheeldown, which actually sould be standard, too.

I'd prefer an event-based solution.

Zoli

Link to comment
Share on other sites

Thanks a lot! Unfortunately, there is no exaple, how it works, and I don't see how I can bind such an event to a user-defined function. Seems to me too, that this one only generates mouse events, instead of waiting for them, right? Found some according info on another thread.

I also tried _IsPressed() with values "05" and "06" for X1 and X2 mouse buttons (whatever they are?), didn't do anything.

So, can you give me another hint?

Zoli

Link to comment
Share on other sites

Try this little script:

#RequireAdmin
#include <WinAPI.au3>
#include <WindowsConstants.au3>
HotKeySet("^q", "_Close") ; Ctrl + q to exit

Local $hFunc = DllCallbackRegister("_LowLevelMouseProc", "int", "int;wparam;lparam")
Local $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hFunc), _WinAPI_GetModuleHandle(0))

While 1
    Sleep(20)
WEnd

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

Func _LowLevelMouseProc($iCode, $iwParam, $ilParam)
    If $iCode < 0  Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
    
    If $iwParam <> $WM_MOUSEMOVE Then ConsoleWrite("Mouse Message: 0x" & Hex($iwParam, 4) & @CRLF)
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc

It'll output the button's hex value so you can see what value it sends, then use this value like:

Func _LowLevelMouseProc($iCode, $iwParam, $ilParam)
    If $iCode < 0  Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
    
    Local $tMSLLHS = DllStructCreate($tagPOINT & ";uint mouseData;uint flags;uint time;ulong_ptr dwExtraInfo;", $ilParam)
    Local $iX, $iY
    
    $iX = DllStructGetData($tMSLLHS, "X")
    $iY = DllStructGetData($tMSLLHS, "Y")
    
    ; $iValue will be the value of the message posted when clicking that button.
    If $iwParam = $iValue Then MouseClick("left", $iX, $iY, 2)
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc
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...