【问题标题】:How to simultaneously scroll two windows?如何同时滚动两个窗口?
【发布时间】:2018-01-21 10:30:04
【问题描述】:

我想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

我希望 ScrollKey 匹配 WheelUpWheelDownPgUpPgDnUpDown

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

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


仅供参考:Send/SendRaw/SendInput/SendPlay/SendEvent: Send keys & clicks
How to grab the scrolling amount in one window?
也在 Reddit 上提问:How to simultaneously scroll two windows?

【问题讨论】:

  • 我尝试使用A_ThisHotKey,但它不起作用
  • 您好,Ooker,如果有任何答案解决了您的问题,请随时将其标记为答案,这样该问题在搜索结果中就不再是“unanswered”了 :) - 如果没有足够的答案,请随时就您的具体问题发表评论和/或添加信息。
  • 嗨@MarcusMangelsdorf,非常感谢您的努力。不幸的是,我还没有尝试过你的方法来完成这个项目。由于我还没有确认它是否有效,我认为接受它我认为这会对未来的观众产生误导。如果这不是问题,我愿意这样做,因为它更有可能起作用:)

标签: variables scroll scrollbar autohotkey code-duplication


【解决方案1】:

试试这个

#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

【讨论】:

  • 它不起作用。将程序添加到组中时使用程序的类或进程不起作用。还有为什么要使用鼠标坐标的具体值(MouseMove, 200, 200, 0)?
  • 用记事本和记事本++试试我编辑的答案。在我的系统上 WheelUp/WheelDown 仅在鼠标指针位于必须滚动的窗口上方时才有效,因此代码中的 MouseGetPos 和 MouseMove 命令。
  • 如果按住向上或向下箭头键,则在第二个窗口中添加0xd0450,如果按住 PgUp 和 PgDn,则添加d0450。你知道如何检测滚动量吗?在问题中查看我的编辑
【解决方案2】:

基于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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多