Page 1 of 1

[PLUGIN] Mouse movement scrolling (MButton)

Posted: 04 Apr 2017, 14:41
by runie
Wrote a quick plugin to implement middle mouse button scrolling.

Quick installation:
Download the plugin in AHK Studio via 'Download Plugins'
Note: AHK Studio 1.003.17 or later will automatically launch this plugin when AHK Studio starts.

Manual Installation:
1. Go to AHK Studio's plugin directory
2. Create a new file and paste the code below into it
3. Restart AHK Studio by pressing Alt-T ('Refresh Plugins' doesn't seem to work atm)
4. Start the plugin (Plugin menu inside AHK Studio)

Code: Select all

;Startup
;Menu MButton Scroll

/*
	Desc: Implements the scrolling up/down functionality via the middle mouse button in AHK Studio

	Written by Runar "RUNIE" Borge
	Plugin for AHK Studio by maestrith
	Forum topic: https://autohotkey.com/boards/viewtopic.php?f=62&t=300
	Plugin topic: https://autohotkey.com/boards/viewtopic.php?f=62&t=30107
	
*/

#NoTrayIcon
#SingleInstance,Force

; fasty fast
SetBatchLines -1

; settings
Key := "MButton" ; key to toggle the scrolling
DeadZone := 60 ; deadzone in pixels
MaxDiff := A_ScreenHeight/3.6 ; maximum up/down movement in pixels
MaxSleep := 50 ; maximum time between scroll calls in ms

; get studio object
x:=ComObjActive("AHK-Studio")

; close this script when studio closes
x.AutoClose(A_ScriptHwnd)

; get sc control handle
sc := x.sc()

; get hwnd of ahk studio window
hwnd := x.hwnd()

; bind key
Hotkey, IfWinActive, % "ahk_id" hwnd
Hotkey, % Key, StartScroll
return

StartScroll:
MouseGetPos,, StartY,, Control

; only apply to scintilla controls
if !InStr(Control, "Scintilla")
	return

; disable hotkey
Hotkey, % Key, Off

Loop {
	; get new pos
	MouseGetPos,, CurrentY
	; scroll up or down if outside deadzone
	if (CurrentY > StartY + DeadZone) ; scroll up
		sc.2342
	else if (CurrentY < StartY - DeadZone) ; scroll down
		sc.2343
	; sleep x amount depending on mouse position
	DllCall("Sleep", UInt, Abs(Limit(Abs(StartY-CurrentY)/MaxDiff, 0, 1) - 1) * MaxSleep)
} until GetKeyState(Key, "P") || GetKeyState("Escape", "P") || !WinActive("ahk_id" hwnd)

; enable the hotkey again
Hotkey, % Key, On
return

Limit(Var, Min, Max) {
	return (Var>Max?Max:(Var<Min?Min:Var))
}
Edit: cleaned up the code and made scrolling smoooother

Re: [PLUGIN] Mouse movement scrolling (MButton)

Posted: 11 Apr 2017, 16:20
by SnowFlake
Do you mind linking to the Github plugin page? i lost it/i cant find it anymore

thanks Runar

Re: [PLUGIN] Mouse movement scrolling (MButton)

Posted: 11 Apr 2017, 17:48
by runie
SnowFlake wrote:Do you mind linking to the Github plugin page? i lost it/i cant find it anymore

thanks Runar
maestrith's GitHub was accidentally flagged by GitHub and suspended.
The mishap has been reverted, here's the link to the plugin page.