如何在一个窗口中获取滚动量? [英] How to grab the scrolling amount in one window?

查看:144
本文介绍了如何在一个窗口中获取滚动量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是同时滚动两个窗口的第一步,第二步是找到一种方法来应用该金额到另一个程序.但是我真的不知道从哪里开始,我从Google看到的所有内容都是关于修改鼠标滚动的行为,而不是在一个窗口中滚动数量 .使用此方法而不是听键的优点:

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

解决方案

我可以告诉你我会做什么,但这不会很有趣...

假设文本大致均匀地分布(可能不会在两种语言之间,以及两个具有不同文本大小和宽度的窗口之间,在工作之前请认真考虑一下),那么目标是强制两者滚动条相对于整个滚动条的百分比相同.因此,您需要编写一个函数来确定每个滚动条所占的百分比.我将截取两个窗口并截取滚动条的重要部分,如下所示:

特别是向上和向下按钮,滚动手柄的顶部,滚动手柄的底部.将它们保存在自己的文件中.如果两个窗口绘制的滚动条略有不同,请对两个窗口都执行此操作.

现在棘手的部分.编写一个执行以下操作的函数:对最右边的25个像素内或指定窗口内的顶部按钮进行图像搜索.底部按钮相同.手柄顶部也一样.手柄底部也一样.使用它来确定窗口的位置.

SetTitleMatchMode, 2 ; so it matches the end of the title
WinGetPos , X, Y, Width, Height, LibreOffice Writer ;exact substring of window name required

使用类似的方法找到滚动条部件.

CoordMode, Pixel , Screen ;so image search searches entire screen
barwidth = 25 ; make sure it's more than the bar is wide.
ImageSearch, TopButtonX, TopButtonY, X+Width-barwidth , Y, X+Width, Y+Height, TopButton.bmp ; no jpg, fuzzy edges make searches fail

然后做一些数学运算,例如:

TopButtonY := TopButtonY+TopButtonImageHeight ; because we only care about the position of the bottom of the button.
BottomHandleY := BottomHandleY+BottomHandleImageHeight   ; because we only care about where the bottom of the handle is.
HandleHeight := TopHandleY - BottomHandleY ; how tall the scroll handle is
TotalHeight := TopButtonY - BottomButtonY - HandleHeight ;how tall the scroll field is
HandleOffset := TopHandleY - TopButtonY ;how far it is from the top
HandlePercent := HandleOffset / TotalHeight ; the part we care about. return this value

使用类似的功能,您可以知道每个窗口的滚动方式.剩下的就是发送滚动命令.有几种选择.

; ControlSend , Control, Keys, LibreOffice Writer
ControlSend , Control, {Pgdown}, LibreOffice Writer ; or {Pgup}
ControlSend , Control, {WheelUp}, LibreOffice Writer ; or {wheeldown}
ControlSend , Control, {Up}, LibreOffice Writer ; or {down}

如果在窗口处于非活动状态时可以使用向上/向下箭头移动插入符号,则即使花费更长的时间,这也可能是最精确的选择.最快,最精确的方法是也使用控件发送来模拟单击拖动.要使用ControlSend,您需要弄清楚正在使用哪个控件. WindowSpy可以帮助您.

所以首先:找到两个窗口的滚动位置.第二,确定哪个窗口处于活动状态.第三,按正确的方向轻推非活动窗口.重复直到它们在一定的公差范围内(否则它将不断地上下反弹).

我对此不太强调,但是在尝试进行此操作之前,请确保使滚动条大致位于相同的位置.如果不是这样,您将浪费很多时间来摆弄它.请记住,文字越长,准确性就会越低.

如果这是一个选项,我肯定会考虑将两个窗口的内容复制到一个程序中,该程序可让您更多地访问控件(或专门用于此目的的更好的控件).如果您有更多访问权限,则可以使用段落分隔符来更精确地对齐文本.

如果您真的只是想同时看到两个文本(段落确实对齐),则可以找到一个文本编辑器来告诉您以下信息:

如果autohotkey将允许您阅读该信息的文本,则可以将PDF复制到autohotkey的内存中(按行分隔),并在可编辑文档中移动时使用autohotkey仅显示PDF的相应段落./p>

希望我说的东西有帮助,祝你好运.

This is the first step to scroll two windows simulteneously, the second step is to find a way to apply that amount to the other program. But I really don't know where to start, all I see in from Google is about modifying the behavior of the scroll of the mouse, not the scrolling amount in one window. Advantages of using this instead of listening to the keys:

  • 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

解决方案

I can tell you what I would do, but it's not going to be fun...

Assuming the text is roughly evenly distributed (which it might not be between two languages like that, and two windows with different text sizes and widths, really consider this carefully before you do the work), then the goal is to force both scroll bars to be at the same percent relative to their whole. So what you need to do is write a function to determine what percent each scroll bar is at. I would screen capture both windows and crop out the important parts of the scroll bar like this:

Specifically the up and down buttons, the top of the scroll handle, the bottom of the scroll handle. Save them in their own files. Do it for both windows in case they draw their scroll bars a little differently.

Now the tricky part. Write a function that does the following: imagesearch for the top button within rightmost 25 pixels or of the specified window. Same for the bottom button. Same for the top of the handle. Same for the bottom of the handle. Use this to determine where your window is.

SetTitleMatchMode, 2 ; so it matches the end of the title
WinGetPos , X, Y, Width, Height, LibreOffice Writer ;exact substring of window name required

Use something like this to find the scroll bar parts.

CoordMode, Pixel , Screen ;so image search searches entire screen
barwidth = 25 ; make sure it's more than the bar is wide.
ImageSearch, TopButtonX, TopButtonY, X+Width-barwidth , Y, X+Width, Y+Height, TopButton.bmp ; no jpg, fuzzy edges make searches fail

Then do some math, something like:

TopButtonY := TopButtonY+TopButtonImageHeight ; because we only care about the position of the bottom of the button.
BottomHandleY := BottomHandleY+BottomHandleImageHeight   ; because we only care about where the bottom of the handle is.
HandleHeight := TopHandleY - BottomHandleY ; how tall the scroll handle is
TotalHeight := TopButtonY - BottomButtonY - HandleHeight ;how tall the scroll field is
HandleOffset := TopHandleY - TopButtonY ;how far it is from the top
HandlePercent := HandleOffset / TotalHeight ; the part we care about. return this value

With a function like that, you can know how scrolled each window is. All that's left is to send the scroll commands. There's a few choices.

; ControlSend , Control, Keys, LibreOffice Writer
ControlSend , Control, {Pgdown}, LibreOffice Writer ; or {Pgup}
ControlSend , Control, {WheelUp}, LibreOffice Writer ; or {wheeldown}
ControlSend , Control, {Up}, LibreOffice Writer ; or {down}

If it lets you move the caret with up/down arrows while the window is inactive, that is probably the most precise option, even if it takes a bit longer. The fastest most precise way is to simulate a click drag also using control send. To use ControlSend you need to figure out which control you're working on. WindowSpy can help you with that.

So first: Find the scroll positions of both windows. Second determine which window is active. Third, nudge the inactive window in the correct direction. Repeat until they're within a certain tolerance range (otherwise it will bounce up and down endlessly).

I can't emphasize this enough, but please make sure that getting the scroll bars in approximately the same positions is sufficiently close before even attempting this. If it isn't, you will have wasted a lot of time fiddling with it. Keep in mind it will be less and less accurate the longer the text is.

If it is an option, I would definitely consider copying the contents of both windows into a program that gives you more access to the controls (or better one that is specialized for this purpose). If you had more access, you could use the paragraph breaks to line up the texts with far more precision.

If you really just want to see both texts side by side (and the paragraphs do line up), you could find a text editor that tells you information like this:

If autohotkey will let you read the text of that information, you can copy the PDF into autohotkey's memory (separated by line) and use autohotkey to show only the corresponding paragraph of the PDF as you move around in the editable document.

Hope something I said helps, good luck.

这篇关于如何在一个窗口中获取滚动量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆