Jump to content

Autoit Mouse Wheel Scroll to Mouse Movement


Recommended Posts

So I'm trying to make a script that will move my mouse when I scroll. I know that's weird, but I have my reasons. What I have so far can detect when I'm moving my mouse, but then when I tell the script to make my mouse move whenever it detects scroll activity it freezes. probably because of some feedback loop.

Anyway, If anyone on here wants to help, I'm at a loss of how to solve this problem. Like maybe when it is about to take the action of moving the mouse it could stop detection for a bit, idk. but I don't know how to do that.

 

 

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

#include <MsgBoxConstants.au3>
#include <Misc.au3>
#include <GUIConstants.au3>

Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"

Global $currentEvent

Global $hDLL = DllOpen("user32.dll")

#Region ### START Koda GUI section ### Form=

;Register callback
$hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)

#EndRegion ### END Koda GUI section ###

While 1

WEnd


Func _Mouse_Proc($nCode, $wParam, $lParam)
    Local $info, $mouseData
    If $nCode < 0 Then
        $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
                "int", $nCode, "ptr", $wParam, "ptr", $lParam)
        Return $ret[0]
    EndIf

    $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam)
    $mouseData = DllStructGetData($info, 3)
    Select
        Case $wParam = $WM_MOUSEWHEEL
            If _WinAPI_HiWord($mouseData) > 0 Then
                ;Wheel Up
                $currentEvent = "WheelUp"

            Else
                ;Wheel Down
                $currentEvent = "WheelDown"
                If _IsPressed("02", $hDLL) Then

                  MsgBox(0,"test","test")

                EndIf
            EndIf
    EndSelect
    
    
    ;;;;;;Mouse Movement CAUSES FREEZING, MAKES ME RESTART COMPUTER:
    if $currentEvent == "WheelUp" then
       $pos = MouseGetPos()
       MouseMove($pos[0]+100,$pos[1]+100,0)
    EndIf
    
    
    
    $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
            "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    Return $ret[0]
EndFunc   ;==>_Mouse_Proc

Func OnAutoItExit()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
    $hM_Hook[0] = 0
    DllCallbackFree($hKey_Proc)
    $hKey_Proc = 0
EndFunc   ;==>OnAutoItExit

 

Link to comment
Share on other sites

Thanks for this, But I should have mentioned in my original post: that I already tried this, I couldn't get it to work the way I wanted because I don't want the mouse to have to be over a gui, to detect if it's wheel is scrolling or not. I want it to be able to detect and respond to the scroll regardless of where the mouse is on the screen.

Can I do that with the example's you've shown here?

Edited by Melba23
Large quote removed
Link to comment
Share on other sites

  • Moderators

LegitStack,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily.

Thanks for your future cooperation in this.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...