Sign in to follow this  
Followers 0
kiboost

wizmouse like with autoit

6 posts in this topic

Hi,

Dunno if you know wizmouse, katmouse, deskangel etc, some smallportable freeware that allow the mouse to scroll the windows behind, even if not active. As I have ever some autoit script running on my machines, I wanted to know if I can do such behavior with autoit code to add it to my already running autoit scripts.

Any idea ?


Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

ok after heavy search on the forum and some testing, I get some code here and there I'm able to detect to window under the cursor, and scroll it hardcoded in the script.

So how can I detect the scroll wheel message to send the correct one ?

;#include
;#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
;#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hControl, $hWin, $hOldWin, $aMousePos

While 1
    $aMousePos = MouseGetPos()
    $hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
    $hWin=_WinAPI_GetAncestor($hControl,2)

    _SendMessage($hControl, $WM_VSCROLL, $SB_LINEDOWN, 0) ; <-- need to send the right detected scrolling by user !
    ;_SendMessage($hControl, $WM_VSCROLL, $SB_LINEUP, 0)

    Sleep(10)
WEnd

Func _WindowFromPoint($iX,$iY)
    Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long")
    DllStructSetData($stPoint,1,$iX)
    DllStructSetData($stPoint,2,$iY)
    $stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint))
    $aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
    If @error Then Return SetError(2,@error,0)
    If $aRet[0]=0 Then Return SetError(3,0,0)
    Return $aRet[0]
EndFunc
Edited by kiboost

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ok here is a first working try. Needs mouseevent udf :

problem, if I start the script, itworks well until I mouse click ! Script end with this msg : !>15:32:10 AutoIT3.exe ended.rc:-1073741819

If someone can have a look and give some info on better method or why it would be unstable ?

#include <ScrollBarConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include 'MouseOnEvent.au3'

Local $hControl, $hWin, $hOldWin, $aMousePos

_MouseSetOnEvent($MOUSE_WHEELSCROLLDOWN_EVENT, "_SendWheelDown")
_MouseSetOnEvent($MOUSE_WHEELSCROLLUP_EVENT, "_SendWheelUp")

While 1
Sleep(100)
WEnd

Func _SendWheelDown()
$aMousePos = MouseGetPos()
$hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
$hWin=_WinAPI_GetAncestor($hControl,2)

_SendMessage($hControl, $WM_VSCROLL, $SB_LINEDOWN, 0)
EndFunc

Func _SendWheelUp()
$aMousePos = MouseGetPos()
$hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
$hWin=_WinAPI_GetAncestor($hControl,2)

_SendMessage($hControl, $WM_VSCROLL, $SB_LINEUP, 0)
EndFunc

Func _WindowFromPoint($iX,$iY)
Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long")
DllStructSetData($stPoint,1,$iX)
DllStructSetData($stPoint,2,$iY)
$stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint))
$aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
If @error Then Return SetError(2,@error,0)
If $aRet[0]=0 Then Return SetError(3,0,0)
Return $aRet[0]
EndFunc
Edited by kiboost

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Share this post


Link to post
Share on other sites

ok, same crash with all examples from mouseevent udf, seems this udf is buggy at least on my machine.


Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Share this post


Link to post
Share on other sites

ok, here's another one, assembled from part found here and there on the forum.

It works pretty great, but the scroll still happens sometimes on the active window also. Any idea how to not scroll the active window, but only the one under the cursor ?

; ~~ Mouse Hook ~~
;For more info, Visit: http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx

#include <GUIConstants.au3> ;for $GUI_EVENT_CLOSE
#Include <WinAPI.au3> ;for HIWORD

#include <GUIScrollBars.au3>;
#include <ScrollBarConstants.au3>
#include <SendMessage.au3>;
#include <WindowsConstants.au3>

;These constants found in the helpfile under Windows Message Codes
;Global Const $WM_MOUSEMOVE = 0x0200 ;mouse move
;Global Const $WM_MOUSEWHEEL = 0x020A ;wheel up/down
;Global Const $WM_LBUTTONDBLCLK = 0x0203 ;left button
;Global Const $WM_LBUTTONDOWN = 0x0201 ;already declared
;Global Const $WM_LBUTTONUP = 0x0202 ;already declared
Global Const $WM_RBUTTONDBLCLK = 0x0206 ;right button
;Global Const $WM_RBUTTONDOWN = 0x0204 ;already declared
;Global Const $WM_RBUTTONUP = 0x0205 ;already declared
Global Const $WM_MBUTTONDBLCLK = 0x0209 ;wheel clicks
;Global Const $WM_MBUTTONDOWN = 0x0207 ;already declared
;Global Const $WM_MBUTTONUP = 0x0208 ;already declared

;Consts/structs from msdn
Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
;~ Global Const $WH_MOUSE_LL = 14        ;already declared
;~ Global Const $tagPOINT = "int X;int Y" ;already declared

OnAutoItExitRegister("OnAutoItExit")

;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)


While 1
sleep(100)
WEnd

Func _SendWheelDown()
;ConsoleWrite("_SendWheelDown"&@CR)
$aMousePos = MouseGetPos()
$hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
$hWin=_WinAPI_GetAncestor($hControl,2)

_SendMessage($hControl, $WM_VSCROLL, $SB_LINEDOWN, 0)

EndFunc

Func _SendWheelUp()
;ConsoleWrite("_SendWheelUp"&@CR)
$aMousePos = MouseGetPos()
$hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
$hWin=_WinAPI_GetAncestor($hControl,2)

_SendMessage($hControl, $WM_VSCROLL, $SB_LINEUP, 0)

EndFunc

Func _WindowFromPoint($iX,$iY)
;ConsoleWrite("_WindowFromPoint"&@CR)
Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long")
DllStructSetData($stPoint,1,$iX)
DllStructSetData($stPoint,2,$iY)
$stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint))
$aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
If @error Then Return SetError(2,@error,0)
If $aRet[0]=0 Then Return SetError(3,0,0)
Return $aRet[0]
EndFunc

Func _Mouse_Proc($nCode, $wParam, $lParam) ;function called for mouse events..
;define local vars
Local $info, $ptx, $pty, $mouseData, $flags, $time, $dwExtraInfo
Local $xevent = "Unknown", $xmouseData = ""

If $nCode < 0 Then ;recommended, see http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx
     $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], "int", $nCode, "ptr", $wParam, "ptr", $lParam) ;recommended
     Return $ret[0]
EndIf

$info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) ;used to get all data in the struct ($lParam is the ptr)
$ptx = DllStructGetData($info, 1) ;see notes below..
$pty = DllStructGetData($info, 2)
$mouseData = DllStructGetData($info, 3)
$flags = DllStructGetData($info, 4)
$time = DllStructGetData($info, 5)
$dwExtraInfo = DllStructGetData($info, 6)
; $ptx = Mouse x position
; $pty = Mouse y position
; $mouseData = can specify click states, and wheel directions
; $flags = Specifies the event-injected flag
; $time = Specifies the time stamp for this message
; $dwExtraInfo = Specifies extra information associated with the message.

;Find which event happened
Select
     Case $wParam = $WM_MOUSEMOVE
         ;$xevent = "Mouse Move"
     Case $wParam = $WM_MOUSEWHEEL
         ;$xevent = "Mouse Wheel"
         If _WinAPI_HiWord($mouseData) > 0 Then
             $xmouseData = "Wheel Forward"
_SendWheelUp()
         Else
             $xmouseData = "Wheel Backward"
_SendWheelDown()
         EndIf
     Case $wParam = $WM_LBUTTONDBLCLK
         ;$xevent = "Double Left Click"
     Case $wParam = $WM_LBUTTONDOWN
         ;$xevent = "Left Down"
     Case $wParam = $WM_LBUTTONUP
         ;$xevent = "Left Up"
     Case $wParam = $WM_RBUTTONDBLCLK
         ;$xevent = "Double Right Click"
     Case $wParam = $WM_RBUTTONDOWN
         ;$xevent = "Right Down"
     Case $wParam = $WM_RBUTTONUP
         ;$xevent = "Right Up"
     Case $wParam = $WM_MBUTTONDBLCLK
         ;$xevent = "Double Wheel Click"
     Case $wParam = $WM_MBUTTONDOWN
         ;$xevent = "Wheel Down"
     Case $wParam = $WM_MBUTTONUP
         ;$xevent = "Wheel Up"
EndSelect

;This is recommended instead of Return 0
$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

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Share this post


Link to post
Share on other sites

Anyone on this one ?


Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Share this post


Link to post
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
Sign in to follow this  
Followers 0