Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AutoScroll


  • Please log in to reply
4 replies to this topic
antonyb
  • Members
  • 61 posts
  • Last active: Mar 07 2006 09:24 AM
  • Joined: 26 May 2004
Hello,

In IE and FireFox, if, while browsing, you click the middle mouse button, you can then scroll around the page you're looking at simply by moving your mouse. Scrolling is centered on the place where you first clicked. I find that really handy, so thought I'd add it everywhere :D

Firstly you need the images from here. Unzip them somewhere, then edit the following script, changing the as_imageroot variable to the directory you unzipped put them. Run the script, hit the middle button, and scroll away!

Any additions/improvements more than welcome.

Ant.

DetectHiddenWindows, On
CoordMode, Mouse, Screen

;// AutoScroll: Root Directory for images
as_imageroot = C:\Documents and Settings\Administrator\AutoHotKey Scripts\Images

;// AutoScroll: One acceleration notch in pixels
as_notch = 30

;// Bind Middle Mouse Button to AutoScroll
$MButton::GoSub, MouseButtonHandler

;// Mouse Button Handler Function.
;// Any windows that you don't want AutoScroll to function in
;// can be filtered out here. I've filtered out FireFox; it
;// has its own AutoScroll mode.

MouseButtonHandler:
  MouseGetPos, mbh_x, mbh_y, mbh_id, mbh_ctrl, 1
  WinGetClass, mbh_class, ahk_id %mbh_id%

  if ( mbh_class = "MozillaWindowClass" )
  {
    MouseClick, Middle
  }
  else
  {
    GoSub, AutoScroll
  }
  return


;// Main AutoScroll Function
AutoScroll:

  ;// Store the point where the button was clicked
  as_startx = %mbh_x%
  as_starty = %mbh_y%

  ;// Figure out the center point of the image
  as_splashx := ( as_startx - 15 )
  as_splashy := ( as_starty - 15 )

  ;// Provide the first image name
  as_image = center
  
  ;// Initialize some values
  as_xlast = 0
  as_ylast = 0
  as_xlastvector = 0
  as_ylastvector = 0

  Loop
  {
    as_changed = 0
    
    ;// Get the latest mouse position
    MouseGetPos, as_x, as_y

    ;// Break out of the loop if the Left Mouse Button is clicked
    GetKeyState, as_state, LButton, P
    if as_state = D
      break

    if as_x != %as_xlast%
    {
      as_xvector := round((as_startx - as_x)/100)

      if as_xvector != %as_xlastvector%
      {
        as_xspeed := 10 // Abs(as_xvector)
  
        if as_xvector = 0
          SetTimer, AutoScrollX, Off 
        else
          SetTimer, AutoScrollX, %as_xspeed% 
    
        as_xlastvector = %as_xvector%
      }
      as_xlast = %as_x%
      as_changed = 1
    }


  
    if as_y != %as_ylast%
    {
      as_yvector := round((as_starty - as_y)/as_notch)
      as_yvector := (as_yvector * Abs(as_yvector))

      if as_yvector != %as_ylastvector%
      {
        if as_yvector = 0
        {
          SetTimer, AutoScrollY, Off
        }
        else
        {
          as_yspeed := ((400 // Abs(as_yvector)) + 1)
          SetTimer, AutoScrollY, %as_yspeed% 
        }
    
        as_ylastvector = %as_yvector%
      }
      as_ylast = %as_y%
      as_changed = 1
    }



    ;// Update the image if necessary
    if as_changed = 1
    {
      if (as_xvector=0 and as_yvector=0)
        as_image = center
      else if (as_xvector=0 and as_yvector>0)
        as_image = n
      else if (as_xvector=0 and as_yvector<0)
        as_image = s
      else if (as_xvector>0 and as_yvector=0)
        as_image = w
      else if (as_xvector<0 and as_yvector=0)
        as_image = e
      else if (as_xvector<0 and as_yvector>0)
        as_image = ne
      else if (as_xvector>0 and as_yvector>0)
        as_image = nw
      else if (as_xvector>0 and as_yvector<0)
        as_image = sw
      else if (as_xvector<0 and as_yvector<0)
        as_image = se

      if as_image != %as_lastimage%
      {
        SplashImage, %as_imageroot%\%as_image%.bmp, b X%as_splashx% Y%as_splashy% Hide, , , autoscrollsplash
        WinSet, TransColor, FF00FF , autoscrollsplash
        SplashImage, Show, , , , autoscrollsplash
        as_lastimage = %as_image%
      }
    }

    sleep, 10
  }

  GoSub, AutoScrollQuit
  return

AutoScrollY:
  ControlGetFocus, asy_control, A
  if as_yvector > 0
    MouseClick, WU
  else
    MouseClick, WD
  return

AutoScrollX:
  ControlGetFocus, asx_control, A
  if as_xvector > 0
    SendMessage, 0x114, 0, 0, %asx_control%, A
  else
    SendMessage, 0x114, 1, 0, %asx_control%, A
  return

AutoScrollQuit:
  SplashImage, Off
  SetTimer, AutoScrollY, Off
  SetTimer, AutoScrollX, Off
  return


skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
Very pretty!

Skrommel

compdude
  • Guests
  • Last active:
  • Joined: --
Can someone tell me how to modify the script to allow for horizontal scrolling as well. Thanks

ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
Good, but I found a case where it doesn't behave as expected. In Windows Explorer, where you have a divided window, it will scroll whichever side was last active regardless of where you middle-click. I'm not sure exactly how hard it would be to give focus to the side you click on, but it would definitely be desirable.

cjtron
  • Members
  • 34 posts
  • Last active: Jul 25 2011 10:27 PM
  • Joined: 24 Aug 2010
thank you for sharing