-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMiddle Scroll.ahk
80 lines (64 loc) · 1.87 KB
/
Middle Scroll.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;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
if((A_PtrSize=8&&A_IsCompiled="")||!A_IsUnicode){
SplitPath,A_AhkPath,,dir
if(!FileExist(correct:=dir "\AutoHotkeyU32.exe")){
MsgBox,Requires AutoHotkey 1.1 to run
ExitApp
}
Run,"%correct%" "%A_ScriptName%" "%file%",%A_ScriptDir%
ExitApp
return
}
; 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("{DBD5A90A-A85C-11E4-B0C7-43449580656B}")
; 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("LButton", "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))
}