Jump to content

SciTE AutoScroll, middle mousebutton browser style scrolling


Recommended Posts

Browser style middle mousebutton scrolling in SciTE. not as smooth though, and the button has to be kept down.

Can be tested without compiling, just open some large scripts and try it out.

;SciTE AutoScroll, middle mousebutton scrolling
;https://www.autoitscript.com/forum/topic/208861-scite-autoscroll-middle-mousebutton-browser-style-scrolling/

Global $hDLL = DllOpen("user32.dll"), $Scroll, $PosInit, $Pos, $Dir, $hCtrl; !!!

Global $Speed = 200; adjust to your likings (100 = fast, 500 = too slow)
Global $Dist = 10; amount of pixels the mouse has to move before starting scrolling

While ProcessExists("SciTE.exe"); while SciTE exist...

   While WinActive("[Class:SciTEWindow]");...and is active

      If BitAND(DllCall($hDLL, "short", "GetAsyncKeyState", "int", "0x04")[0], 0x8000) Then $Scroll = True ; if middle mousebutton is pressed activate scroll

         $PosInit = MouseGetPos(1) ; get initial mouse y-position for comparison
         $hCtrl = DllCall($hDLL, "int", "WindowFromPoint", "long", MouseGetPos(0), "long", $PosInit)[0]; get handle under mousecursor
         
         While $Scroll; while scroll is activated

            $Pos = MouseGetPos(1); get mouse y-position
            $Dir = (($Pos < $PosInit) ? 0:1); get direction
            If Abs($PosInit - $Pos) > $Dist Then DllCall($hDLL, "lresult", "SendMessageW", "hwnd", $hCtrl, "uint", 0x0115, "wparam", $Dir, "lparam", 0); scroll if mouse has been moved beyond starting point ($WM_VSCROLL, $SB_LINEDOWN/$SB_LINEUP)
            If Not BitAND(DllCall($hDLL, "short", "GetAsyncKeyState", "int", "0x04")[0], 0x8000) Then $Scroll = False; if middle mouse button is released deactivate scroll
            Sleep($Speed - Sqrt(($Pos - $PosInit)^2)); speed of scroll depending on distance from startpos, adjust to your likings

         WEnd
   Sleep(10); easy on the cpu usage if SciTE is active but button isnt pressed
   WEnd
Sleep(10); easy on the cpu usage if SciTE exists but isnt active
WEnd

; exit if SciTE is closed or doesnt exist
DllClose($hDLL)
Exit

Easily changed to other editors, or your own autoit gui, just change these two lines...

While ProcessExists("Notepad.exe"); while SciTE exist...

   While WinActive("[Class:Notepad]");...and is active

...for example Notepad.

Changes:

Spoiler
If $Pos < $PosInit - $Dist Or $Pos > $PosInit + $Dist Then

could be written as

If Abs($PosInit - $Pos) > $Dist Then

removed "= True" and "= False" from the keystates, wasnt really needed

fixed some global/local mess

Removed Round() from the Sleep as Sleep doesnt care

$Dir = (($Pos < $PosInit - $Dist) > ($Pos > $PosInit + $Dist) ? 0:1); get direction

could be written as

$Dir = (($Pos < $PosInit) ? 0:1); get direction

 

 

Edited by Werty

Some guy's script + some other guy's script = my script!

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...