如何同时滚动两个窗口?

时间:2018-01-21 10:30:05

标签: variables scroll scrollbar autohotkey code-duplication

我想要simultaneously scroll two windows,但热键输入法要求我多次复制它。我的想法是使用Function HotkeysA_ThisHotKey变量,但如果使用此脚本,则WheelDown在程序中禁用:

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

我希望ScrollKeyWheelUpWheelDownPgUpPgDnUpDown相匹配。

理想情况,我认为脚本应检测第一个程序的滚动程度,然后将该数量应用于第二个程序。优点:

  • 滚动将是无缝的,因为其他程序在后台滚动
  • 点击滚动条
  • 不同的滚动速度不会影响比较
  • 在文本编辑器中移动行不会在PDF查看器中滚动页面


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

2 个答案:

答案 0 :(得分:3)

试试这个

#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

答案 1 :(得分:1)

基于user3419297's answer,此修改过的脚本允许您定义要在脚本顶部滚动的两个应用的标题:

#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