Jump to content

ALT + MouseWheel up/down to control volume up/down


EZG
 Share

Recommended Posts

Hey

I used to have a script for AHK to achieve this:

!WheelUp::Send {Volume_Up 1}
!WheelDown::Send {Volume_Down 1}

But in AutoIt I can't manage to make anything work. I've tried several things without any results. I need help to achieve the same result please.

Link to comment
Share on other sites

  • Moderators

@EZG our forum has a wonderful search function. If you search "volume control" you will doubtlessly find the many many times this has been asked and answered.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Sorry I'm probably very bad but I can't achieve what I want.

It took me like 5min to figure it our in AHK in the past when I did it, it's been years that I use this script. 

I wanted to switch to AutoIt but I already invested so much time trying to read and learn to achieve what I want but I can't figure it out. Kinda hard to find relevant info for what I need. 

I give up guys lol. Good night bye.

Link to comment
Share on other sites

  • Moderators

Wow, giving up after less than three hours - and after someone pointed you directly to a topic that would help you - I am sure you'll do wonderful things in the scripting world :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

A lot of the examples on the forums (found by using the Google search "mousewheel site:autoitscript.com") need the mouse hovering over a GUI to function.
This example does not require a GUI.  A Window's hook procedure monitors low-level mouse input events, and in particular, mouse wheel events which, together with the pressed "Alt" key, raises and lowers the volume.

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Misc.au3> ; Added for _IsPressed() function only.

; Modified from: https://www.autoitscript.com/forum/topic/98716-mouse-wheel-up-and-down-as-a-hotkey/?do=findComment&comment=709911

HotKeySet('{ESC}', '_Close') ; Press "Esc" key to exit.

;If Not IsDeclared('$WM_MOUSEWHEEL') Then Global Const $WM_MOUSEWHEEL = 0x020A  ; <----------- Commented out from original script
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) ; $WH_MOUSE_LL - Installs a hook procedure that monitors low-level mouse input events

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 _IsPressed("12") Then ; <----------- Added to original script ("12" for Alt key)
            If $iDelta < 0 Then
                $iCounter -= 1
                Send("{VOLUME_DOWN}") ; <----------- Added to original script
            Else
                $iCounter += 1
                Send("{VOLUME_UP}") ; <------------- Added to original script
            EndIf
        EndIf
        ConsoleWrite($iCounter & @LF)
    EndIf

    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc   ;==>_MouseProc

Func _Close()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hHook)
    Exit
EndFunc   ;==>_Close

 

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