Jump to content

Mouse Hook DLL - Block Input


Recommended Posts

The code below is taken from AZJIO from http://www.autoitscript.com/forum/topic/119804-volume-control
Sense the Topic was over 3 years old, i felt i should make a new topic to ask my question.

The code allows a user to control the volume control by simily scrolling up and down with his mouse. An extremely cool idea (with some nice visuals i might add) though it is a little problematic as the scrolling itself is not blocked. So you end up at the bottom of a page when you just wanted to turn the volume down.

#include <GUIConstantsEx.au3>

Const $WH_MOUSE = 7
Const $WM_AUTOITMOUSEWHEELUP = 0x1400 + 0x0D30
Const $WM_AUTOITMOUSEWHEELDOWN = 0x1400 + 0x0D31

Global $tr = 0, $setico='', $TrGui=0, $iniTrn, $iniX, $iniY, $iniAtSt, $iniDV, $iniColBk, $iniColVol, $a, $iniHK='', $iniHKM=''
$gui = GUICreate("", 30, 135, 0, 0)

Global $DLLinst = DllCall("kernel32.dll", "hwnd", "LoadLibrary", "str", ".\hook.dll")
Global $mouseHOOKproc = DllCall("kernel32.dll", "hwnd", "GetProcAddress", "hwnd", $DLLinst[0], "str", "MouseProc")
Global $hhMouse = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE, "hwnd", $mouseHOOKproc[0], "hwnd", $DLLinst[0], "int", 0)

DllCall(".\hook.dll", "int", "SetValuesMouse", "hwnd", $gui, "hwnd", $hhMouse[0])
GUIRegisterMsg($WM_AUTOITMOUSEWHEELUP, "myfunc")
GUIRegisterMsg($WM_AUTOITMOUSEWHEELDOWN, "myfunc")

While sleep(500)
WEnd

Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam)
   ConsoleWrite("A")
EndFunc

hook.rar

 

Code above, along with the dll, is what i found is needed for seeing if the scroll wheel has been used. 

So does anyone know a way i could use this code but also block the scrolling when its detected?

Ian

*Extra

I am aware i could do the same thing with a _API_WindowsSetHookEx but i found using this type of hook makes the mouse laggy. I thought it was just me being weird but after doing some research online it seams that's not the case.

Edited by IanN1990
Link to comment
Share on other sites

Depends on how you call _WinAPI_WindowsSetHookEx, I've had zero problems with it so far.  There is a UDF by MrCreatoR in the examples section that might be of interest.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

i'm usually keen on learning stuff, but how exactly does the code above manipulates the volume control? what are the commands used?

and, if you do get it to work, how will your script know if your intent is to change the volume when you scroll, instead of scrolling? i.e. what do you do if you want to scroll?

FYI there is a utility that does just that: http://www.nirsoft.net/utils/volumouse.html

i'm using it regularly, and i configured it for volume control when scrolling only when the cursor is on screen edges.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

  • 2 weeks later...

@Orbs

The code above, doesn't. It is stripped code taken from AZJIO post looking at improving/changing a single function.

I am aware of using Send Vol Up / Down, Control Send, and using Nicrmd for controling volume.
Furthermore in his post, he gives software which can do it as well. Though it has to be run in Compability mode with XP.


@Guiness

If i use a basic _WinAPI_WindowsSetHookEx for mouse with no extra code.

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

Global $hHook, $hStub_KeyProc, $buffer = ""

_Main()

Func _Main()
    OnAutoItExitRegister("Cleanup")

    Local $hmod

    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

    while sleep(1000)
    WEnd
EndFunc   ;==>_Main

;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc   ;==>Cleanup

Which, as its taken from the helpfile i assume its the best form/way of writing it and if i run the code, i can sense there is a drag / lag on the mouse. Its more noticable when on the laptop. For some reason, i dont get that feeling with the .dll and the code above has nothing running. So if i was to start anything checks and such, that would make the drag worse.

I have used MouseOnEvent.UDF in the past but if possible, i like to stay away from udfs for smaller "to the job" code rather then a "Block of code, i didn't write or really understand". Also if memory severs, the UDF cant detect some keys on the mouse.

**Edit. I am sorry for late replys. Its becoming harder and harder to find time to use my computer, and even less to spend it on my hobby of coding :(

**Edit 2. The text at the top is bugged. I could remove it, and re-write it but sense i dont know how to reproduce it. I figured i would leave it, incase the orginal post offers any clues into how it happened.

Edited by IanN1990
Link to comment
Share on other sites

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

Global $hHook, $hStub_KeyProc, $Gui

; AutoIt3 v3.3.6.1
; Global Const $WM_MBUTTONDBLCLK = 0x0209
; Global Const $WM_RBUTTONDBLCLK = 0x0206
; Global Const $WM_MOUSEHWHEEL = 0x020E ???

_Main()

Func _Main()
    OnAutoItExitRegister("Cleanup")

    Local $hmod, $sText

    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

    ; Esc - для закрытия скрипта

    $Gui = GUICreate('', 700, 260, -1, -1, $WS_OVERLAPPEDWINDOW)
    $sText = ''
    For $i = 1 To 100
        $sText &= $i &@CRLF
    Next
    $iEdit = GUICtrlCreateEdit($sText, 5, 5, 290, 250)
    GUISetState()

    Do
    Until GUIGetMsg() = -3
EndFunc   ;==>_Main
;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS, $X, $Y
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    ; координаты мыши X, Y
    $X = DllStructGetData($tKEYHOOKS, "vkCode")
    $Y = DllStructGetData($tKEYHOOKS, "scanCode")

    Switch $wParam
        Case $WM_MOUSEWHEEL
            Return 1
            
        Case Else
            WinSetTitle($Gui, '', "X: " & $X & ", Y: " & $Y)
            Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndSwitch
EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc   ;==>Cleanup

http://pastebin.com/3P0ZKj5G

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