Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Simulate scroll wheel using right mouse button


  • Please log in to reply
4 replies to this topic
  • Guests
  • Last active:
  • Joined: --
I'm using a laptop with eraser head and two mouse button.
I miss the scroll wheel so much.

I used to use Mo'Scroll but it doesn't remember the settings, so everytime I turn on my laptop, I have to set the settings again.

Recently, I read this post from VxE:
http://www.autohotke...429.html#199429

My modification basically send vertical and horizontal scroll when the right mouse button is pressed.

And here is my modification:
$~*RButton Up::SetTimer, WatchTheMouse, off

$RButton::
MouseGetPos, ox, oy
SetTimer, WatchTheMouse, 5

WatchTheMouse:
MouseGetPos, nx, ny
If ((dx := nx-ox)**2 > 8 )
{
	times := Abs(dy) / 4
	ControlGetFocus, control, A
	
	Loop, %times%
	{
		If (dx > 0)
			SendMessage, 0x114, 1, 0, %control%, A ; 0x114 is WM_HSCROLL 
		Else
			SendMessage, 0x114, 0, 0, %control%, A ; 0x114 is WM_HSCROLL
	}
}
If ((dy := ny-oy)**2 > 8 )
{
	times := Abs(dy) / 4
	
	Loop, %times%
	{
		If (dy > 0)
			Click WheelDown
		Else
			Click WheelUp
	}	
}
MouseMove ox, oy
return

My question is how can I avoid the context menu caused by the right button up? By doing so, I'll also need to use KeyWait in someway to:

Wait for, let say 200ms, if user doesn't release the right button, the scroll mode begins (timer set to on).
Upon right mouse button up, if scroll mode is activated (timer is on), suppress the right button up to avoid context menu.

Thanks

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
$*RButton::

scrollz = 1

MouseGetPos, ox, oy

SetTimer, WatchTheMouse, 5

Hotkey, $*RButton Up, RButtonup, on

return



RButtonup:

SetTimer, WatchTheMouse, off

Hotkey, $*RButton Up, RButtonup, off

If scrollz

	Click Right

return
You can try this instead of the two hotkeys above the watching routine.

  • Guests
  • Last active:
  • Joined: --
Thanks VxE. Though your code didn't actually prevent the right click context menu, it did hint me about the HotKey command and turning on/off of hotkeys.

From my previous code and VxE's hint, I've come up with a KeyWait for 400ms before starting the scrolling mode. Once the scrolling mode starts, a tray tooltip pop ups. The tooltip is dismissed when user release the right button.

And my code for those who may find their interest:
$*RButton::
Hotkey, $*RButton Up, RButtonup, off
KeyWait, RButton, T0.4
If ErrorLevel = 1
{
	Hotkey, $*RButton Up, RButtonup, on
	MouseGetPos, ox, oy
	SetTimer, WatchTheMouse, 5
	TrayTip, Scrolling started, Scrolling mode has been started
}
Else
	Send {RButton}
return

RButtonup:
Hotkey, $*RButton Up, RButtonup, off
SetTimer, WatchTheMouse, off
TrayTip
return

WatchTheMouse:
MouseGetPos, nx, ny
If ((dx := nx-ox)**2 > 8 )
{
	times := Abs(dy) / 4
	ControlGetFocus, control, A
	
	Loop, %times%
	{
		If (dx > 0)
			SendMessage, 0x114, 1, 0, %control%, A ; 0x114 is WM_HSCROLL 
		Else
			SendMessage, 0x114, 0, 0, %control%, A ; 0x114 is WM_HSCROLL
	}
}
If ((dy := ny-oy)**2 > 8 )
{
	times := Abs(dy) / 4
	
	Loop, %times%
	{
		If (dy > 0)
			Click WheelDown
		Else
			Click WheelUp
	}	
}
MouseMove ox, oy
return


anotherperson8923
  • Guests
  • Last active:
  • Joined: --
Here's an improved version that gives a more predictable scrolling distance, especially at slow mouse speeds.

$*RButton::
Hotkey, $*RButton Up, RButtonup, off
KeyWait, RButton, T0.4
If ErrorLevel = 1
{
   Hotkey, $*RButton Up, RButtonup, on
   MouseGetPos, ox, oy
   SetTimer, WatchTheMouse, 5
   movedx := 0
   movedy := 0
   TrayTip, Scrolling started, Scrolling mode has been started
}
Else
   Send {RButton}
return

RButtonup:
Hotkey, $*RButton Up, RButtonup, off
SetTimer, WatchTheMouse, off
TrayTip
return

WatchTheMouse:
MouseGetPos, nx, ny
movedx := movedx+nx-ox
movedy := movedy+ny-oy

timesX := Abs(movedx) / 4
ControlGetFocus, control, A
Loop, %timesX%
{
    If (movedx > 0)
    {
        SendMessage, 0x114, 1, 0, %control%, A ; 0x114 is WM_HSCROLL
        movedx := movedx - 4
    }
    Else
    {
        SendMessage, 0x114, 0, 0, %control%, A ; 0x114 is WM_HSCROLL
        movedx := movedx + 4
    }
}

timesY := Abs(movedy) / 4
Loop, %timesY%
{
    If (movedy > 0)
    {
        Click WheelDown
        movedy := movedy - 4
    }
    Else
    {
        Click WheelUp
        movedy := movedy + 4
    }
}   

MouseMove ox, oy
return


anotherperson8923
  • Guests
  • Last active:
  • Joined: --
Here's a slight modification that I'm using with my Logitech Marble Mouse with four buttons.

The small left button is the activator key for the scroll wheel. Scrolling begins immediately. If the mouse is not moved while the button is pressed, a click is sent instead.

If you are using SetPoint, set button 3 to "Generic Button" for this to work.

$*XButton1::
Hotkey, $*XButton1 Up, XButton1up, off
;KeyWait, XButton1, T0.4
;If ErrorLevel = 1
;{
   Hotkey, $*XButton1 Up, XButton1up, on
   MouseGetPos, ox, oy
   SetTimer, WatchTheMouse, 5
   movedx := 0
   movedy := 0
   pixelsMoved := 0
   TrayTip, Scrolling started, Emulating scroll wheel
;}
;Else
;   Send {XButton1}
return

XButton1up:
Hotkey, $*XButton1 Up, XButton1up, off
SetTimer, WatchTheMouse, off
TrayTip
If (pixelsMoved = 0)
{
    ;The mouse was not moved, send the click event
    ; (Default action is 'Back', replace these with a different action here if desired)
    Send {XButton1}
    Send {XButton1Up}
}
return

WatchTheMouse:
MouseGetPos, nx, ny
movedx := movedx+nx-ox
movedy := movedy+ny-oy

pixelsMoved := pixelsMoved + Abs(nx-ox) + Abs(ny-oy)

timesX := Abs(movedx) / 4
ControlGetFocus, control, A
Loop, %timesX%
{
    If (movedx > 0)
    {
        SendMessage, 0x114, 1, 0, %control%, A ; 0x114 is WM_HSCROLL
        movedx := movedx - 4
    }
    Else
    {
        SendMessage, 0x114, 0, 0, %control%, A ; 0x114 is WM_HSCROLL
        movedx := movedx + 4
    }
}

timesY := Abs(movedy) / 4
Loop, %timesY%
{
    If (movedy > 0)
    {
        Click WheelDown
        movedy := movedy - 4
    }
    Else
    {
        Click WheelUp
        movedy := movedy + 4
    }
}   

MouseMove ox, oy
return
[/code]