Parallel Scrolling script to scroll 2 windows simultaneously

Post your working scripts, libraries and tools for AHK v1.1 and older
emvaized
Posts: 3
Joined: 11 Apr 2023, 12:29

Parallel Scrolling script to scroll 2 windows simultaneously

Post by emvaized » 29 Feb 2024, 00:05

This Autohotkey script allows you to scroll 2 windows or any views in the same window simultaneously. When you hold down the win key, the script sends a scroll event to both the current point under the course, and a second point mirrored horizontally. Thus, by choosing the cursor position, you can achieve simultaneous scrolling of any 2 windows or 2 lists within a single window.
You can adjust scrolling speed by modifying the "WheelTurns" variable.

If you hold Win+Alt, you can set any custom point for scroll by clicking on the screen, and then scrolling with both Win and Alt key pressed will also scroll at stored position

Code: Select all

; Parallel scrolling 
; Autohotkey script by @emvaized
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance, Force
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
#KeyHistory 0
ListLines Off
SetMouseDelay, -1

; Preference for scrolling speed. Defines how much scroll events to send on every detected scroll.
WheelTurns := 5


#WheelUp:: ScrollPoint("WheelUp", WheelTurns)
Return
#WheelDown:: ScrollPoint("WheelDown", WheelTurns)
Return
!#WheelUp:: ScrollPoint("WheelUp", WheelTurns, SavedX, SavedY )
Return
!#WheelDown:: ScrollPoint( "WheelDown", WheelTurns, SavedX, SavedY )
Return

; Save cursor position on Win+Alt+click
#!LButton::
{
	CoordMode, Mouse, Screen
	MouseGetPos, SavedX, SavedY
	ToolTip, Saved point for scroll: %SavedX% x %SavedY%`
	Sleep 1000
	ToolTip
}

ScrollPoint(WhichButton, WheelTurns, PasX = -1, PasY = -1) {
    ; Get desktop size and mouse position
	CoordMode, Mouse, Screen
	WinGetPos, , , Xmax, , Program Manager
	MouseGetPos, MouseX, MouseY

	Loop, %WheelTurns% {
		; Scroll at current position
		MouseClick, %WhichButton% , , , 1, 0, ,

		if (PasX > -1) {
			; Move to previously saved cursor position
			MouseClick, %WhichButton% , PasX, PasY, 1, 0, ,
		} else {
			; Move to horizontally mirrored position and scroll
			MouseClick, %WhichButton% , (Xmax - MouseX), MouseY, 1, 0, ,
		}
		
		; Move cursor back
		MouseMove, MouseX, MouseY ,0 ,
	}
}
The only problem I found for now is that Alt and Win keys are also sent to the target windows along with scroll events. Some windows may respond differently to scroll with Win or Alt keys — such as VSCode, which has ability to scroll faster when Alt key is pressed.

Demonstration of parallel scrolling two windows simultaneously when Win key is pressed (cursor is over left window):
Attachments
demonstration.gif
demonstration.gif (1.65 MiB) Viewed 274 times

Kotte
Posts: 46
Joined: 03 May 2021, 08:33

Re: Parallel Scrolling script to scroll 2 windows simultaneously

Post by Kotte » 20 Mar 2024, 10:23

Haha, this would have been perfect for my current need! I wanted to scroll to separate tabs in my IDE while working on a project for color blind people :D Sadly I couldn't get it to work though. It doesn't jump to the point I stored using but instead jumps a few hundred pixels to the left and scrolls there instead. I tried doing the opposite but that made it jump a few thousand pixels in the wrong direction instead. There seems to be an issue with the position calculation. I'll have to take a closer look when I have more time but I really like the idea!

Post Reply

Return to “Scripts and Functions (v1)”