Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

using right-click and mouse movement as a "scroll wheel


  • Please log in to reply
6 replies to this topic
hakko
  • Guests
  • Last active:
  • Joined: --
Hi

I've actually got a trackball, but I really miss the scroll wheel from a mouse!

Ideally rotating (clock/anti) the trackball should scroll a page, but my model doesn't have that feature.

So I modified a script here that allows scrolling using the RButton and moving the mouse(trackball) up and down:

$*RButton Up::

SetTimer, MBScroll, off
KeyWait, RButton
KeyWait, RButton, D, T0.20

If ErrorLevel = 0
{
   Send {RButton}
}
return

$*RButton::

Sensitivity = 20 ; how far it takes before the scroll happens
MouseGetPos, X1, Y1
startposx=X1
startposy=Y1
SetTimer, MBScroll, 1

MBScroll:

MouseGetPos, X2, Y2

If Abs(Y2-Y1) >= Sensitivity
{
   SendInput, % "{Blind}{Wheel" (Y2 > Y1 ? "Down}" : "Up}")
   MouseMove, 0, % Y1 - Y2, 0, R
}

return
MouseMove, pos1, pos2 ;return cursor to original position?

I want the cursor to return to the original position (ideally not move at all).

At the moment as I hold down RButton and move the mouse, the page scrolls but the cursor reaches the end of the screen - and not the end of the page.

As you can see above I thought I could save the start X,Y and after the scrolling set mouse position to start X,Y.

Thanks in advance!

Z_Gecko
  • Guests
  • Last active:
  • Joined: --
try one of these:
http://www.autohotke...ht=mouse scroll
http://www.autohotke...ht=mouse scroll
http://www.autohotke...ht=mouse scroll

hakko
  • Guests
  • Last active:
  • Joined: --
Thanks. They each have a good thing but also a bad thing, none of them solves it on it's own.

With a scroll wheel I can scroll horizontally or vertically while the cursor stays in the same place.

To substitute that for trackballs, I need to use the right-click and ball movement for the scroll wheel movement.

So something like:
;;right mouse button pressed
;; save start mouse position

If(right mouse button pressed and mousemoved)
     do_scrollwheel_behaviour().
else
     just right button pressed();; do normal right-click


do_scroll_wheel_behaviour()
{
   is the mouse moving x axis or y axis?
   apply scroll wheel in appropriate direction
   whilst not moving cursor
}

return 



Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
I was just messing around with something like that, so I'll post it here:

#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%

	wheelingSensitivity := 10 ; sensitivity to mouse movement (higher is more sensitive)
	wheelingPeriod := 100 ; timer period
return


RButton & LButton:: GoSub StartWheeling
~*LButton Up:: 		GoSub StopWheeling
~*RButton Up:: 		GoSub StopWheeling

WatchCursor:
	MouseGetPos, wheelingNewMouseX, wheelingNewMouseY
	
	DeltaX := wheelingNewMouseX - wheelingMouseX
	clicks := Round((wheelingNewMouseY - wheelingMouseY)/wheelingSensitivity)
	
	MouseMove wheelingMouseX, wheelingMouseY

	if clicks > 0
		MouseClick WheelDown,,,abs(clicks)
	else if clicks < 0
		MouseClick WheelUp,,,abs(clicks)
return

StartWheeling:
	SystemCursor("OFF")
	MouseGetPos, wheelingMouseX, wheelingMouseY
	SetTimer WatchCursor, %wheelingPeriod%
return

StopWheeling:
	SetTimer WatchCursor, Off
	SystemCursor("ON")
return
;===============================================================================================================================================================
; from the AHK documentation...
SystemCursor(OnOff=1)   ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
    static AndMask, XorMask, $, h_cursor
        ,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
        , b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13   ; blank cursors
        , h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13   ; handles of default cursors
    if (OnOff = "Init" or OnOff = "I" or $ = "")       ; init when requested or at first call
    {
        $ = h                                          ; active default cursors
        VarSetCapacity( h_cursor,4444, 1 )
        VarSetCapacity( AndMask, 32*4, 0xFF )
        VarSetCapacity( XorMask, 32*4, 0 )
        system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
        StringSplit c, system_cursors, `,
        Loop %c0%
        {
            h_cursor   := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
            h%A_Index% := DllCall( "CopyImage",  "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
            b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
                , "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
        }
    }
    if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
        $ = b  ; use blank cursors
    else
        $ = h  ; use the saved cursors

    Loop %c0%
    {
        h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
        DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
    }
}
;===============================================================================================================================================================

"wheeling mode" is activated if you press down and hold the right mouse button followed by the left mouse button.

The mouse moving bugged me too, so I just kept it in the same place and hid it. If you choose not to hide it, it will jitter.

So far, I haven't found any undesired issues with this script. Previous things I had tried would disable right clicks or right click drags or get stuck... but this version has been very well behaved. If you use it, do tell me if you run into anything odd.

ddh819
  • Members
  • 22 posts
  • Last active: Aug 02 2009 05:21 AM
  • Joined: 27 Dec 2006
rapte_of_suzaku, that script is great. Is it possible to make it scroll left and right also?

Rapte_Of_Suzaku
  • Members
  • 901 posts
  • Last active: Jul 08 2011 02:12 PM
  • Joined: 29 Feb 2008
yep, that is easy enough to add. For the new left-right movement, the arrow keys are used.

#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%

   wheelingSensitivity := 10 ; sensitivity to mouse movement (higher is more sensitive)
   wheelingPeriod := 100 ; timer period
return


RButton & LButton:: GoSub StartWheeling
~*LButton Up:: 		GoSub StopWheeling
~*RButton Up:: 		GoSub StopWheeling

WatchCursor:
	MouseGetPos, wheelingNewMouseX, wheelingNewMouseY
	
	taps := Round((wheelingNewMouseX - wheelingMouseX)/wheelingSensitivity)
	clicks := Round((wheelingNewMouseY - wheelingMouseY)/wheelingSensitivity)
	
	MouseMove wheelingMouseX, wheelingMouseY

	if clicks > 0
		MouseClick WheelDown,,,abs(clicks)
	else if clicks < 0
		MouseClick WheelUp,,,abs(clicks)
		
	if taps > 0
		SendInput % "{Right "abs(taps)"}"
	else if taps < 0
		SendInput % "{Left "abs(taps)"}"
return

StartWheeling:
	SystemCursor("OFF")
	MouseGetPos, wheelingMouseX, wheelingMouseY
	SetTimer WatchCursor, %wheelingPeriod%
return

StopWheeling:
	SetTimer WatchCursor, Off
	SystemCursor("ON")
return
;===============================================================================================================================================================
; from the AHK documentation...
SystemCursor(OnOff=1)   ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
    static AndMask, XorMask, $, h_cursor
        ,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
        , b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13   ; blank cursors
        , h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13   ; handles of default cursors
    if (OnOff = "Init" or OnOff = "I" or $ = "")       ; init when requested or at first call
    {
        $ = h                                          ; active default cursors
        VarSetCapacity( h_cursor,4444, 1 )
        VarSetCapacity( AndMask, 32*4, 0xFF )
        VarSetCapacity( XorMask, 32*4, 0 )
        system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
        StringSplit c, system_cursors, `,
        Loop %c0%
        {
            h_cursor   := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
            h%A_Index% := DllCall( "CopyImage",  "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
            b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
                , "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
        }
    }
    if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
        $ = b  ; use blank cursors
    else
        $ = h  ; use the saved cursors

    Loop %c0%
    {
        h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
        DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
    }
}
;===============================================================================================================================================================



Just to throw it out there, I use the "Grab and Drag" Firefox addon for fast trackball-only scrolling (obviously, it only works in Firefox, but that is where I need it most anyways). I made the wheeling script so that I could zoom in and out using only a trackball. If you will be using this script mostly while browsing (with Firefox), I would highly recommend you check out "Grab and Drag".

Anyways, I'm glad you like it!

ddh819
  • Members
  • 22 posts
  • Last active: Aug 02 2009 05:21 AM
  • Joined: 27 Dec 2006
That works pretty well! Thanks for the Firefox tip, but there are other applications I can use this functionality too.