[PLUGIN] Mouse movement scrolling (MButton)

Editor for AutoHotkey written completely in AutoHotkey.

Moderator: maestrith

User avatar
runie
Posts: 304
Joined: 03 May 2014, 14:50
Contact:

[PLUGIN] Mouse movement scrolling (MButton)

04 Apr 2017, 14:41

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
User avatar
SnowFlake
Posts: 368
Joined: 28 Apr 2015, 05:41
Contact:

Re: [PLUGIN] Mouse movement scrolling (MButton)

11 Apr 2017, 16:20

Do you mind linking to the Github plugin page? i lost it/i cant find it anymore

thanks Runar
:yawn:
User avatar
runie
Posts: 304
Joined: 03 May 2014, 14:50
Contact:

Re: [PLUGIN] Mouse movement scrolling (MButton)

11 Apr 2017, 17:48

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.

Return to “AHK Studio”

Who is online

Users browsing this forum: No registered users and 16 guests