Sign in to follow this  
Followers 0
glumbler

Slowing down Mouse only within Certain Windows

3 posts in this topic

Hi, I did do a quick search on the forums but couldn't find anything...

I keep a TightVNC window logged into a remote PC and keep that window Shrunk Small, always ontop in the bottom left corner of my desktop.

I frequently move my mouse into that small window to operate the remote PC, but the problem I have is that my mouse moves too fast on the remote side because it is calibrated to the full screen size of this PC.

So if it makes sense (I hope it does) I would like to find out how I can dynamically decrease the mouse speed, but only when it is within the tiny VNC window. Kind of like the window has a lot of treacle, or Higgs particles in it so the mouse moves slower.

And then when coming out of the window to reset the mouse speed to what it was.

VeryManyThanks for any replies/guidance/pointing in the right direction and happy holidays, unless you don't celebrate the holidays, in which case disregard...

Glumbler.

Share this post


Link to post
Share on other sites



You could use _WinAPI_GetCursorInfo / WinGetPos (or something else) to get the position of the pointer relative to the window, and modify the pointer speed when needed
As this changes a system parameter (https://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx#) you must get the initial speed, change it when the pointer is on the window, and change it back when it is out
The speed value is  1 to 20

MsgBox(0,"", getMouseSpeed() )

Func getMouseSpeed()
    Local $call = DllCall("user32.dll", "int", "SystemParametersInfo", "int", 0x0070, "int", 0, "int*", "", "int", 0)
    Return $call[3]
EndFunc

Func setMouseSpeed($speed)
    Local $call = DllCall("user32.dll", "int", "SystemParametersInfo", "int", 0x0071, "int", 0, "int", $speed, "int", 0)
EndFunc

 

Share this post


Link to post
Share on other sites

Thank you mikell, I pieced together the below script based on several sources available online - so this is not my work just joined up the pieces I needed to make it work...

#include <WinAPI.au3>
#include <Misc.au3>

Global Const $SPI_SETMOUSESPEED = 0x0071
Global Const $SPI_GETMOUSESPEED = 0x0070
Global Const $TargetWindow = "Title of Window you want to slow down mouse for"

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

Local $hControl, $hWin, $hOldWin, $aMousePos
$hOldWin = ""
While Not _IsPressed("1B")
    $aMousePos = MouseGetPos()
    $hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
    ; Since _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window
    $hWin=_WinAPI_GetAncestor($hControl,2)
    If $hWin <> $hOldWin Then
        WinHandler ( WinGetTitle($hWin))
        $hOldWin = $hWin
    EndIf
    Sleep(10)
WEnd

Func WinHandler ( $sTitle )
    Static $OldSpeed
    ConsoleWrite ("Window Info: Window under mouse = " & $sTitle & @CRLF )
    If ( $sTitle = $TargetWindow ) Then
        $OldSpeed = DllCall('user32.dll','int','SystemParametersInfo','uint',$SPI_GETMOUSESPEED,'uint',0,'int*','','uint',0)[3]
        $SetSpeed = 1
    Else
        $SetSpeed = $OldSpeed
    EndIf
    DllCall("user32.dll", "int", "SystemParametersInfo", "int", $SPI_SETMOUSESPEED, "int", 0, "int", $SetSpeed, "int", 0)
EndFunc

 

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