4

I want to simultaneously scroll two windows, but the hotkey input method requires me to duplicate it multiple times. My idea is to use Function Hotkeys and A_ThisHotKey variable, but the WheelDown is disable in the program if using this script:

WheelDown::
ScrollKey := A_ThisHotKey
SetTitleMatchMode, 2
IfWinActive, Writer
{
        CoordMode, Mouse, Screen
        WinGet, active_id, ID, A
        IfWinExist, Sumatra
        {
                Send {ScrollKey}
                WinActivate ; Automatically uses the window found above.
                Send {ScrollKey}
                Send {ScrollKey}
                WinActivate, ahk_id %active_id%
        }
}
Else
{
        Send {A_ThisHotKey}
}
return

I want ScrollKey to match WheelUp, WheelDown, PgUp, PgDn, Up, Down.

Ideally, I think the script should detect how much the first program is scrolled, then apply that amount to the second one. Advantages:

  • Scrolling will be seamless since the other program are scrolled in the background
  • Clicking on the scrollbar works
  • Different scrolling speeds don't affect the comparison
  • Moving lines in text editors won't scroll pages in PDF viewers


FYI: Send/SendRaw/SendInput/SendPlay/SendEvent: Send keys & clicks
How to grab the scrolling amount in one window?
Also asked on Reddit: How to simultaneously scroll two windows?

Ooker
  • 1,969
  • 4
  • 28
  • 58
  • I tried to use `A_ThisHotKey` but it doesn't work – Ooker Jan 21 '18 at 11:21
  • Hi Ooker, if any of the answers solved your problem, feel free to mark it as the answer so this question is no longer "_unanswered_" in the search results :) - If no answer is sufficient, yet, feel free to comment and/or add information to your question regarding your specific problem. – Marcus Mangelsdorf Apr 19 '18 at 08:27
  • Hi @MarcusMangelsdorf, thank you so much for your effort. Unfortunately I haven't tried your method yet for having done with the project. As I haven't confirmed whether it works or not yet, I think accepting it I think it would be misleading for future viewers. If that's not a problem I'm willing to do it, as there is a higher chance that it just works :) – Ooker Apr 19 '18 at 11:10

2 Answers2

3

Try this

#SingleInstance Force
Process, Priority, , High

; SetTitleMatchMode, 2

GroupAdd, Scroll_Group, ahk_class Notepad
GroupAdd, Scroll_Group, ahk_class Notepad++

SetWinDelay 0

#If (WinActive("ahk_class Notepad") && WinExist("ahk_class Notepad++")) || (WinActive("ahk_class Notepad++") && WinExist("ahk_class Notepad"))

    WheelUp::
    WheelDown::
    PgUp::
    PgDn::
    Up::
    Down::  
        MouseGetPos, mX, mY
        Send {%A_ThisHotKey%}
        GroupActivate Scroll_Group  ; activate the next window of this group
        If (A_ThisHotKey = "WheelUp" || A_ThisHotKey = "WheelDown")
            MouseMove, 200, 200, 0  ; move the mouse over the currently active window 
        Send {%A_ThisHotKey%}   
        GroupActivate Scroll_Group
        MouseMove, mX, mY, 0
    return

#If
user3419297
  • 9,537
  • 2
  • 15
  • 24
  • It doesn't work. Using the classes or the processes of the programs when adding them into the group doesn't work. And why do you use specific value of coordinates of the mouse (`MouseMove, 200, 200, 0`)? – Ooker Jan 22 '18 at 08:12
  • Try my edited answer with Notepad and Notepad++. On my system WheelUp/WheelDown only work if the mouse pointer is over the window that has to be scrolled, therefore the MouseGetPos and MouseMove commands in the code. – user3419297 Jan 22 '18 at 13:20
  • it adds `0xd0450` in the second window if up or down arrow keys are hold, and `d0450` if PgUp and PgDn are hold. Do you know how to detect the scrolling amount? See my edit in the question – Ooker Jan 23 '18 at 11:46
2

Based on user3419297's answer, this modified script allows you to define the titles of the two apps you want to scroll at the top of the script once:

#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.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Process, Priority, , High
SetTitleMatchMode, 2

; Set your desired app names here. It is enough to use a part of the window's title
PART_OF_TITLE_OF_APP_A := "Notepad++"
PART_OF_TITLE_OF_APP_B := "Word"

GroupAdd, Scroll_Group, %PART_OF_TITLE_OF_APP_A%
GroupAdd, Scroll_Group, %PART_OF_TITLE_OF_APP_B%

SetWinDelay 0

#If (WinActive(PART_OF_TITLE_OF_APP_A) && WinExist(PART_OF_TITLE_OF_APP_B))
    || (WinActive(PART_OF_TITLE_OF_APP_B) && WinExist(PART_OF_TITLE_OF_APP_A))

    WheelUp::
    WheelDown::
    PgUp::
    PgDn::
    Up::
    Down::  
        MouseGetPos, mX, mY
        Send {%A_ThisHotKey%}
        GroupActivate Scroll_Group  ; activate the next window of this group
        If (A_ThisHotKey = "WheelUp" || A_ThisHotKey = "WheelDown")
            MouseMove, 200, 200, 0  ; move the mouse over the currently active window 
        Send {%A_ThisHotKey%}   
        GroupActivate Scroll_Group
        MouseMove, mX, mY, 0
    return
Marcus Mangelsdorf
  • 2,852
  • 1
  • 30
  • 40