如何同时滚动两个窗口?

问题描述 投票:0回答:3

我想同时滚动两个窗口,但热键输入法需要我重复多次。我的想法是使用 Function Hotkeys

A_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

我希望

ScrollKey
匹配
WheelUp
WheelDown
PgUp
PgDn
Up
Down

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

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


仅供参考:Send/SendRaw/SendInput/SendPlay/SendEvent:发送按键和点击
如何抓取一个窗口的滚动量?
Reddit 上还问:如何同时滚动两个窗口?

variables scroll scrollbar autohotkey code-duplication
3个回答
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

2
投票

基于user3419297的回答,这个修改后的脚本允许您定义要在脚本顶部滚动一次的两个应用程序的标题:

#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

0
投票

我创建了WinSyncScroll,当你滚动另一个窗口时它会滚动一个窗口。

© www.soinside.com 2019 - 2024. All rights reserved.