-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathHoverScroll.ahk
404 lines (336 loc) · 16.2 KB
/
HoverScroll.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; HoverScroll() v1.04
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;© 2014 Scoox
;Send scroll messages to any control without focus
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;** INCLUDE THIS FILE IN AUTUEXECUTE SECTION OF MAIN SCRIPT **
;Specify this in calling script
;#MaxHotkeysPerInterval 500 ;Avoid warning when mouse wheel turned very fast
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Constants
HoverScrollMinLines := 1 ;lines per notch
HoverScrollMaxLines := 5 ;lines per notch
HoverScrollThreshold := 70 ;Max Miliseconds between two consecutive notches (user defined)
HoverScrollCurve := 0 ;Acceleration curve: 0 = Straight line (default), 1 = Parabola
;Determine system frequency in Hz:
DllCall("QueryPerformanceFrequency", "Int64 *", Frequency)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Application exceptions
;NOTE: By default this script will use the target control HWND obtained via DLL call ast this method works in the most places. To use a different method, add to the corresponding group below.
;NOTE: The same window can be added to several different groups
;NOTE: RegEx is allowed in group definitions e.g. "ahk_class Note.?ad" etc
;NOTE: This script assumes that the same method will work with all controls of a given application. Should this limitation be a problem, flexible per-control support may be added in the future.
;Methods:
;GroupAdd, HoverScroll_Hwnd
;GroupAdd, HoverScroll_HwndClassNN
;GroupAdd, HoverScroll_Window ;Post messages to whole window instead of control under mouse
;GroupAdd, HoverScroll_HwndDll ;Default method (no need to explicitly add to this group)
GroupAdd, HoverScroll_Hwnd, Fireface Settings ahk_class #32770 ;RME Fireface settings
;Workarounds:
;GroupAdd, HoverScroll_Loop ;Use this when unable to scroll more than one line per notch
;GroupAdd, HoverScroll_FocusControl ;Use this for apps that refuse to scroll
;GroupAdd, HoverScroll_HScrollAlternative ;Try this for apps that don't respond to standard HORIZONTAL scroll method
GroupAdd, HoverScroll_Loop, ahk_class TEventEditForm ;FL Studio arranger view
GroupAdd, HoverScroll_Loop, ahk_class TFruityLoopsMainForm ;FL Studio arranger view
GroupAdd, HoverScroll_Loop, ahk_class CCLWindowClass ;Studio One main window
GroupAdd, HoverScroll_Loop, ahk_class CCLShadowWindowClass ;Studio One mixer and plugins
GroupAdd, HoverScroll_Loop, Traktor ahk_class NINormalWindow00400000 ;NI Traktor faders, knobs, etc
GroupAdd, HoverScroll_FocusControl, ahk_class TFruityLoopsMainForm
GroupAdd, HoverScroll_FocusControl, ahk_class TProjectPropertiesForm
GroupAdd, HoverScroll_HScrollAlternative, ahk_class MSPaintApp
GroupAdd, HoverScroll_HScrollAlternative, ahk_class classFoxitReader
GroupAdd, HoverScroll_HScrollAlternative, ahk_classDSUI:PDFXCViewer
GroupAdd, HoverScroll_HScrollAlternative, Microsoft Visio ahk_class VISIOA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;MS Office applications
Global HoverScroll_ControlExceptions_MSOffice
HoverScroll_ControlExceptions_MSOffice .= "EXCEL71" ;Excel
HoverScroll_ControlExceptions_MSOffice .= "|_WwG1" ;Word
HoverScroll_ControlExceptions_MSOffice .= "|paneClassDC1" ;PowerPoint
HoverScroll_ControlExceptions_MSOffice .= "|NetUIHWND1" ;Access
;HoverScroll_ControlExceptions_MSOffice .= ... add your own here e.g. Access etc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; HoverScroll()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
Lines:
Optional paramter, default value = 1.
Axis:
1 = Vertical scrolling (default if omitted)
0 (or any value other than 1) = Horizontal scrolling
Ctrl:
1 = Send Ctrl-Wheel
Else (default) = Normal scrolling
Shift:
1 - Send Shift-Wheel
Else (default) = Normal scrolling
Optional parameter, default value = 1.
The number of lines to scroll per scrollwheel notch. Negative values scroll downwards. If omitted this parameter a value of 1 will be used.
Return value:
None.
*/
HoverScroll(Lines=1, Axis=1, Ctrl=0, Shift=0)
{
Critical
SetTitleMatchMode RegEx
CoordMode, Mouse, Screen ;All coords relative to screen
SetBatchLines, -1 ;Run as fast as possible
SetMouseDelay, -1
SetControlDelay, 0
MouseGetPos, m_x, m_y, WinID, ControlClassNN, 1
MouseGetPos,,,, ControlHwnd, 2
;ControlHwndDll := DllCall("WindowFromPoint", "int", m_x, "int", m_y) ;32-bit only (bad)
ControlHwndDll := DllCall( "WindowFromPoint", "int64", (m_y << 32) | (m_x & 0xFFFFFFFF), "Ptr") ;both 64 and 32-bit (good)
;Some applications require that the target control has input focus.
;This won't necessarily activate the window containing the target control, e.g. FL Studio
IfWinExist ahk_id %WinID% ahk_group HoverScroll_FocusControl
{
ControlFocus,, ahk_id %ControlHwnd%
ControlFocus,, ahk_id %ControlHwndDll%
}
;Horizontal scrolling work-around using WM_HSCROLL = 0x114
;This method gives you less control than using WM_MOUSEHWHEEL,
;but may work in some apps where WM_MOUSEHWHEEL does not.
If (Axis != 1) ;If horizontal scrolling
{
IfWinExist ahk_id %WinID% ahk_group HoverScroll_HScrollAlternative
{
Iterations := Abs(Lines)
If (Lines < 0)
Loop %Iterations%
PostMessage, 0x114, 0, 0,, ahk_id %ControlHwnd%
Else
Loop %Iterations%
PostMessage, 0x114, 1, 0,, ahk_id %ControlHwnd%
Return
}
;Microsoft office applications using Office VBA's SmallScroll method
If (ControlClassNN ~= HoverScroll_ControlExceptions_MSOffice)
{
Try ;Avoid weird error if MButton pressed accidentally
{
;Include Acc.ahk in calling script
;See Post #6 by user "jethrow" on the following thread:
;http://www.autohotkey.com/board/topic/35292-horizontal-scroll-in-excel-2007/
;SmallScroll method information
;http://msdn.microsoft.com/en-us/library/office/aa166801%28v=office.10%29.aspx
If Lines < 0
Acc_ObjectFromWindow(ControlHwndDll, -16).SmallScroll(0,0,0,Abs(Lines))
Else
Acc_ObjectFromWindow(ControlHwndDll, -16).SmallScroll(0,0,Abs(Lines),0)
}
Return
}
}
;lParam := (m_y << 16) | m_x ;Does not work with -ve coords when using more than one display
lParam := (m_y << 16) | (m_x & 0x0000FFFF) ;Works with -ve coords (recommended)
wParam := (120 << 16) * (Lines < 0 ? -1 : 1)
wParam |= Ctrl ? 8 : 0
wParam |= Shift ? 4 : 0
;All of the following available focusless scrolling methods were tested.
;The one marked as "BEST" was found to work on the most number of control, and so was chosen as the default method.
;SendMessage, %Axis%, wParam, lParam, %ControlClassNN%, ahk_id %WinID%
;SendMessage, %Axis%, wParam, lParam,, ahk_id %ControlHwndDll%
;SendMessage, %Axis%, wParam, lParam,, ahk_id %ControlHwnd%
;PostMessage, %Axis%, wParam, lParam, %ControlClassNN%, ahk_id %WinID%
;PostMessage, %Axis%, wParam, lParam,, ahk_id %ControlHwndDll% ;** BEST **
;PostMessage, %Axis%, wParam, lParam,, ahk_id %ControlHwnd%
;Looping to send repeated wheel events is slower but works everywhere.
;(wParam * Lines) does not work in a few programs, in which case Loop should be used.
Lines := Abs(Lines)
Iterations := 1
IfWinExist ahk_id %WinID% ahk_group HoverScroll_Loop
{
Iterations := Lines
Lines := 1
}
;WM_MOUSEWHEEL = 0x20A
;WM_MOUSEHWHEEL = 0x20E
If (Axis = 1)
Message := 0x20A ;vertical scroll
Else
Message := 0x20E ;horizontal scroll
IfWinExist ahk_id %WinID% ahk_group HoverScroll_ClassNN
Loop %Iterations%
PostMessage, %Message%, wParam * Lines, lParam, %ControlClassNN%, ahk_id %WinID%
Else IfWinExist ahk_id %WinID% ahk_group HoverScroll_Hwnd
Loop %Iterations%
PostMessage, %Message%, wParam * Lines, lParam,, ahk_id %ControlHwnd%
Else IfWinExist ahk_id %WinID% ahk_group HoverScroll_Window
Loop %Iterations%
PostMessage, %Message%, wParam * Lines, lParam,, ahk_id %WinID%
Else
Loop %Iterations%
PostMessage, %Message%, wParam * Lines, lParam,, ahk_id %ControlHwndDll%
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ScrollLines()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*
MinLines:
Optional paramter, default value = 1.
Minimum number of lines to scroll per notch (typically you'll want this set to 1)
MaxLines:
Optional paramter, default value = 5.
Maximum number of lines to scroll per notch.
Threshold:
Optional paramter, default value = 20.
The higher this value, the easier it is to engage acceleration.
This is a value in milliseconds that represents the time between scrollwheel notches. Acceleration kicks in when the scrollwheel is turned fast enough so that the time between notches is LESS than this value. If the time between notches is GREATER than this value, acceleration is disengaged and the functionr eturns MinLines.
Curve:
Optional paramter, default value = 0 (linear).
Two flavours of of acceleration curve are provided (feel free to add your own). Each curve has a different feel, try and choose the one that you feel more comfortable with.
0 = Straight line
1 = Parabola
;Parameter value ranges (parameters set to values outside will produce undefined behaviour):
;1 <= MinLines <= MaxLines (MinLines = MaxLines disables acceleration)
;Threshold can be any positive number. With invalid values the function returns MaxLines.
;Curve can be 0 or 1, other values default to 0
Return value:
Returns the number of lines to scroll calculated from current scrollwheel angular speed.
*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Standard method (A_TimeSincePriorHotkey), no interpolation
;Simplest and most direct method, but perhaps not the most accurate.
ScrollLines_1(MinLines=1, MaxLines=5, Threshold=50, Curve=0)
{
Static MinInterval := 20 ;MinInterval value calculated automatically afterwards
;If changing scroll direction, assume lowest scroll speed
If (A_ThisHotkey != A_PriorHotkey)
Return MinLines
T := A_TimeSincePriorHotkey
;Record new shortest interval
If (T < MinInterval)
MinInterval := T
;Shift stored times on
Loop % Times.MaxIndex() - 1
Times[A_Index] := Times[A_Index + 1]
If (T > Threshold) ;Normal slow scrolling or changing scroll direction
Lines := MinLines
Else If(T < MinInterval Or Threshold < MinInterval) ;Fastest scrolling allowed
Lines := MaxLines
Else ;Scrolling speeds in between
{
If (Curve = 1)
{
;f(t) = At^2 + Bt + C
A := (MaxLines - MinLines) / ((MinInterval - Threshold)**2)
B := -2 * A * Threshold
C := MinLines - (A * Threshold**2) - (B * Threshold)
;C := MaxLines - (A * MinInterval**2) - (B * MinInterval) ;or this
Lines := Round(A * T**2 + B * T + C)
}
Else ;Default curve is straigth line
{
;f(t) = At + B
A := (MaxLines - MinLines) / (MinInterval - Threshold)
B := MaxLines - (A * MinInterval)
Lines := Round(A * T + B)
}
}
Return Lines
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Standard method (A_TickCount) with linear interpolation
;Increased accuracy over previous method, however it requires more notches to calculate return value.
ScrollLines_2(MinLines=1, MaxLines=5, Threshold=50, Curve=0)
{
;Increase number of items of Times array to reduce the effect of timing errors.
;Each item in this array represents one notch of the scrollwheel. An array with 5 items means that this function will use the time difference between the 5th and the 1st notches in order to calculate the number of lines to scroll. Therefore you first need to turn the wheel 5 times before acceleration kicks in.
;Therefore it follows that if you are only able to scroll through a maximum of, say, 12 notches per scrollwheel stroke (due to physical limitations of your mouse), then using an array with 12 or more items means that acceleration will never be engaged.
;The "delay" introduced by this mechanism may also help remove spurious unintended scrollwheel speed spikes.
;Array must have a minimum of 2 items (undefined behaviour otherwise).
;Recommended number of items: 2 to 5 (determined empirically).
;Using only 2 items is equivalent to using A_TimeSincePriorHotkey
Static Times := [0,0,0,0,0]
Static MinInterval := 20 ;MinInterval value calculated automatically afterwards
;If changing scroll direction, assume lowest scroll speed
If (A_ThisHotkey != A_PriorHotkey)
Return MinLines
Times[Times.MaxIndex()] := A_TickCount
T := (Times[Times.MaxIndex()] - Times[1]) / (Times.MaxIndex() - 1)
;Record new shortest interval
If (T < MinInterval)
MinInterval := T
;Shift stored times on
Loop % Times.MaxIndex() - 1
Times[A_Index] := Times[A_Index + 1]
If (T > Threshold) ;Normal slow scrolling or changing scroll direction
Lines := MinLines
Else If(T < MinInterval Or Threshold < MinInterval) ;Fastest scrolling allowed
Lines := MaxLines
Else ;Scrolling speeds in between
{
If (Curve = 1)
{
;f(t) = At^2 + Bt + C
A := (MaxLines - MinLines) / ((MinInterval - Threshold)**2)
B := -2 * A * Threshold
C := MinLines - (A * Threshold**2) - (B * Threshold)
;C := MaxLines - (A * MinInterval**2) - (B * MinInterval) ;or this
Lines := Round(A * T**2 + B * T + C)
}
Else ;Default curve is straigth line
{
;f(t) = At + B
A := (MaxLines - MinLines) / (MinInterval - Threshold)
B := MaxLines - (A * MinInterval)
Lines := Round(A * T + B)
}
}
Return Lines
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;QPC method with linear interpolation (high precision)
;Most accurate method, same as previous method but using QueryPerformanceCounter call.
;Global Frequency variable to be initialized outside the function in auto-execute section (can be set within the function but that would be wasteful).
ScrollLines_3(MinLines=1, MaxLines=5, Threshold=50, Curve=0)
{
;Increase number of items of Times array to reduce the effect of timing errors.
;Each item in this array represents one notch of the scrollwheel. An array with 5 items means that this function will use the time difference between the 5th and the 1st notches in order to calculate the number of lines to scroll. Therefore you first need to turn the wheel 5 times before acceleration kicks in.
;Therefore it follows that if you are only able to scroll through a maximum of, say, 12 notches per scrollwheel stroke (due to physical limitations of your mouse), then using an array with 12 or more items means that acceleration will never be engaged.
;The "delay" introduced by this mechanism may also help remove spurious unintended scrollwheel speed spikes.
;Array must have a minimum of 2 items (undefined behaviour otherwise).
;Recommended number of items: 2 to 5 (determined empirically).
Static Times := [0,0,0,0,0]
Static MinInterval := 20 ;MinInterval value calculated automatically afterwards
Global Frequency
;If changing scroll direction, assume lowest scroll speed
If (A_ThisHotkey != A_PriorHotkey)
Return MinLines
DllCall("QueryPerformanceCounter", "Int64 *", Value)
Times[Times.MaxIndex()] := Value
T := (Times[Times.MaxIndex()] - Times[1]) / (Times.MaxIndex() - 1) * 1000 / Frequency
;Record new shortest interval
If (T < MinInterval)
MinInterval := T
;Shift stored times on
Loop % Times.MaxIndex() - 1
Times[A_Index] := Times[A_Index + 1]
If (T > Threshold) ;Normal slow scrolling or changing scroll direction
Lines := MinLines
Else If(T < MinInterval Or Threshold < MinInterval) ;Fastest scrolling allowed
Lines := MaxLines
Else ;Scrolling speeds in between
{
If (Curve = 1)
{
;f(t) = At^2 + Bt + C
A := (MaxLines - MinLines) / ((MinInterval - Threshold)**2)
B := -2 * A * Threshold
C := MinLines - (A * Threshold**2) - (B * Threshold)
;C := MaxLines - (A * MinInterval**2) - (B * MinInterval) ;or this
Lines := Round(A * T**2 + B * T + C)
}
Else ;Default curve is straigth line
{
;f(t) = At + B
A := (MaxLines - MinLines) / (MinInterval - Threshold)
B := MaxLines - (A * MinInterval)
Lines := Round(A * T + B)
}
}
Return Lines
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;