AutoHotkey – How to Scroll Two PDF Documents

adobe-acrobatautohotkeypdf

I am trying to make a script that scrolls all the opened PDF documents at the same time. The problem is that I can not get it to work unless I specifically name each window that has to be scrolled and send the actions to it. Also, in the current state I need to catch the scroll event in another window (ex: Notepad) but this is actually ok since I may also want to scroll some of the PDFs manually and then resume synchronous scrolling.

Here's my workflow:

  1. Open 2 or more PDF documents.
  2. Open a Notepad file and start scrolling into the notepad file.

Result: All opened PDFs start scrolling.

Here's my code (borrowed from the interwebz 🙂

WheelDown::
SetTitleMatchMode, 2
IfWinActive, Notepad ; Replace 'SafariTitle' by the title of the safari windows
{
        CoordMode, Mouse, Screen
        WinGet, active_id, ID, A
        IfWinExist, Adobe
        {
                Send {WheelDown}
                WinActivate ; Automatically uses the window found above.
                Send {WheelDown}
                Send {WheelDown}
                WinActivate, ahk_id %active_id%
        }

}
Else
{
        Send {WheelDown}
}
return

WheelUp::
SetTitleMatchMode, 2
IfWinActive, Notepad ; Replace 'SafariTitle' by the title of the safari windows
{
        CoordMode, Mouse, Screen
        WinGet, active_id, ID, A
        IfWinExist, Adobe
        {
                Send {WheelUp}
                WinActivate ; Automatically uses the window found above.
                Send {WheelUp}
                Send {WheelUp}
                WinActivate, ahk_id %active_id%
        }
        }
        Else
        {
                Send {WheelUp}
        }
return

Right now it works for scrolling only one PDF.

How can I get it to look and scroll through all of them?

Best Answer

Found the solution:

WheelDown::
SetTitleMatchMode, 2
IfWinActive, Notepad ;
{
        CoordMode, Mouse, Screen
    WinGet, active_id, ID, A        
    WinGet, id, list, Adobe,, Program Manager
        Loop, %id%
    {
        Send {WheelDown}
            this_id := id%A_Index%
            WinActivate, ahk_id %this_id%
            Send {WheelDown}
            Send {WheelDown}
            WinActivate, ahk_id %active_id%
        }

}
Else
{
        Send {WheelDown}
}
return

WheelUp::
SetTitleMatchMode, 2
IfWinActive, Notepad ;
{
        CoordMode, Mouse, Screen
        WinGet, active_id, ID, A
        WinGet, id, list, Adobe,, Program Manager
        Loop, %id%
    {
        Send {WheelUp}
            this_id := id%A_Index%
            WinActivate, ahk_id %this_id%
            Send {WheelUp}
            Send {WheelUp}
            WinActivate, ahk_id %active_id%
        }
        }
        Else
        {
                Send {WheelUp}
        }
return

Now it works. You need Adobe Acrobat Reader (or acrobat Pro, something with acrobat) and Notepad.

How it works:

  1. Open the PDFs that you want to scroll synchronously.

  2. Open one Notepad window (this will be the control window so you can also scroll the PDFs autonomously (each separately). The Notepad window can be re-sized really small.

  3. Click the Notepad window and scroll away.

Each PDF gets selected and scrolled as you scroll in the Notepad window. Select each PDF manually if you want to scroll it alone.

Related Question