Jump to content

Mouse wheel up and down as a hotkey


Recommended Posts

Hey guys, I've been searching around but I can't seem to find exactly what I'm looking for (or maybe I don't understand what I've been reading).

I'm looking to write a script that will detect my mouse wheel being moved up or down and then either increase or decrease a variable accordingly.

Thanks for the help!

Link to comment
Share on other sites

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

If Not IsDeclared('WM_MOUSEWHEEL') Then Global Const $WM_MOUSEWHEEL = 0x020A
Global Const $tagMSLLHOOKSTRUCT = _
    $tagPOINT & _
    ';uint mouseData;' & _
    'uint flags;' & _
    'uint time;' & _
    'ulong_ptr dwExtraInfo;'

Global $hFunc, $pFunc
Global $hHook, $hMod
Global $iCounter = 0 ; The variable in question.

$hFunc = DllCallbackRegister('_MouseProc', 'lresult', 'int;int;int')
$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)
    Local $tMSLL, $iDelta
    
    If $iCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
    
    $tMSLL = DllStructCreate($tagMSLLHOOKSTRUCT, $ilParam)
    
    If $iwParam = $WM_MOUSEWHEEL Then
        $iDelta = BitShift(DllStructGetData($tMSLL, 'mouseData'), 16)
        If $iDelta < 0 Then
            $iCounter -= 1
        Else
            $iCounter += 1
        EndIf
        
        ConsoleWrite($iCounter & @LF)
    EndIf
    
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc

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

Link to comment
Share on other sites

  • 11 months later...

Hi, Im getting an error...

D:\Program Files (x86)\AutoIt3\RapidMacroReleaseSource\Sprint1.2.au3(42,77) : ERROR: $WM_MOUSEWHEEL previously declared as a 'Const'

If Not IsDeclared('WM_MOUSEWHEEL') Then Global Const $WM_MOUSEWHEEL = 0x020A

How do I call the function?

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