提问人:Ooker 提问时间:1/21/2018 最后编辑:Ooker 更新时间:4/12/2018 访问量:2600
如何同时滚动两个窗口?
How to simultaneously scroll two windows?
问:
我想同时滚动两个窗口,但热键输入法要求我多次复制它。我的想法是使用函数热键和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 上被问到:如何同时滚动两个窗口?
答:
3赞
Relax
1/22/2018
#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
评论
0赞
Ooker
1/22/2018
这是行不通的。在将程序添加到组中时,使用程序的类或进程不起作用。为什么要使用鼠标坐标的特定值()?MouseMove, 200, 200, 0
0赞
Relax
1/22/2018
用记事本和记事本++试试我编辑的答案。在我的系统上,WheelUp/WheelDown 仅在鼠标指针位于必须滚动的窗口上时才起作用,因此代码中的 MouseGetPos 和 MouseMove 命令。
0赞
Ooker
1/23/2018
如果按住向上或向下箭头键,以及是否按住 PgUp 和 PgDn,它会在第二个窗口中添加。您知道如何检测滚动量吗?在问题中查看我的编辑0xd0450
d0450
2赞
Marcus Mangelsdorf
4/12/2018
#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
评论
A_ThisHotKey