Getting position and size of the scroll bar

Get help with using AutoHotkey and its commands and hotkeys
User avatar
SALZKARTOFFEEEL
Posts: 60
Joined: 10 May 2017, 11:14
GitHub: SALZKARTOFFEEEL
Location: Germany
Contact:

Getting position and size of the scroll bar

14 May 2017, 07:17

Hi there,
I am currently trying to solve an issue I have with Windows. Whenever you use a scroll bar, there is a limit on how far you can move your mouse until the scrolling gets reset.
I hate Windows for doing this, it is very annoying!
I have already searched the web for useful methods to turn this off, but I don't think there is one.
Instead I now had the idea to simply limit the cursor's movement to the area that is still acceptable (or rather just to the are of the scroll bar itself).

I'd say that half the cake is already done, since I found this script that lets me confine the cursor to an area already!
Now I just need a way to actually get the coordinates of the scroll bar. No, if you want to tell me a method that would get me some sort of percentage of how far I am on the page, that probably doesn't help.
I am thinking of some sort of function that would either • retrieve one coordinate, the top left corner preferably, an then two other values that represent the width and (much more importantly) the height. • or retrieve four coordinates, simply the four corner-coordinates, just like the mouse-confine-script is accepting.

As far as my research within Window Spy goes, the scroll bar isn't always the same width, nor is it even always a window control. I think, this is going to be quite the challenge.
Well, if you have any better ideas or know a method to do this with, please tell me! Of course, if you happen to know a method to just disable the resetting, that would be great too!
Thanks!
User avatar
jeeswg
Posts: 6395
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Getting position and size of the scroll bar

14 May 2017, 10:51

Try AccViewer and the Acc library, it seems to give you most of the information e.g. control/control element coordinates and percentage scrolled.

Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

E.g. Notepad:

Code: Select all

q:: ;notepad - scrollbar get scroll % + coordinates
ControlGet, hCtl, Hwnd,, Edit1, ahk_class Notepad
oAcc := Acc_Get("Object", "5", 0, "ahk_id " hCtl)
oRect := Acc_Location(oAcc)
MsgBox, % oAcc.accValue "`r`n" oRect.x " " oRect.y " " oRect.w " " oRect.h
oAcc := ""
return
==================================================
there is a limit on how far you can move your mouse until the scrolling gets reset.
Could you explain this further, could you give a common program, that I could recreate this problem with.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
SALZKARTOFFEEEL
Posts: 60
Joined: 10 May 2017, 11:14
GitHub: SALZKARTOFFEEEL
Location: Germany
Contact:

Re: Getting position and size of the scroll bar

14 May 2017, 13:38

First of all, this is my code right now
Okay, the Acc library seems to definitely be a step forward, thanks!
Right now I can actually get the script to work perfectly!.... But only in Notepad. I need it to work in (close to) all windows and applications.
I think it is because of the "5" in Acc_Get("Object", "5", 0, "ahk_id " hCtl). From my understanding, this is the child path, a number which correlates to the scroll bar of Notepad, but not the scroll bar of other windows.
So if I really have to specify this child path, this method might not work, since it seems to be different from window to window. If there's a way to not specify this though, this would still be able to work with a bit of tweaking!
Maybe I just made a silly mistake, but at the moment, I don't think so.
jeeswg wrote:
there is a limit on how far you can move your mouse until the scrolling gets reset.
Could you explain this further, could you give a common program, that I could recreate this problem with.
Well, you can pretty much use any program within Windows.
When you grab the scroll bar handle (I hope it's called that) and move your cursor far beyond the possible scrolling area (far to the left for example), the scrolling will reset. It will not let you scroll and the handle will reset to its previous position.
I hope, I made it clear this time. This was probably made so you could actually cancel your scrolling, but I think, it's very annoying.

Anyway, thanks for the reply, it has really helped me already! I think, it's just a small step from now on.
User avatar
jeeswg
Posts: 6395
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Getting position and size of the scroll bar

14 May 2017, 14:02

[it calls it a 'thumb' here:]
Scroll Bar Controls
https://msdn.microsoft.com/en-us/library/ms997557.aspx

[I see, the behaviour occurs when you drag, one link I found about it:]
gui design - Why do scrollbars revert to original scroll distance when mouse is dragged sideways too far? - User Experience Stack Exchange
https://ux.stackexchange.com/questions/ ... gged-sidew

Yes, each program you use might need different child paths or other techniques entirely.

For a child path, sometimes you can use 'scroll_bar' or 'scroll_bar1' instead of a number which might help a bit.

Hmm, I had wondered, if maybe there was a system-wide setting for the horizontal and vertical 'reset distances' (my term).

I had thought maybe you could do something like send a repeated WM_MOUSEMOVE message, but this might not work very well.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
DanielToward13
Posts: 63
Joined: 18 May 2017, 10:56

Re: Getting position and size of the scroll bar

25 Jan 2018, 15:12

@jeeswg Your code works in Notepad but is there a way to know the scroll bar position in almost every program (specially Chrome, Firefox, Adobe Acrobat)? If no then what are the alternative ways?
User avatar
jeeswg
Posts: 6395
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Getting position and size of the scroll bar

25 Jan 2018, 15:38

- Unfortunately in Chrome and Firefox, it seems that you cannot get any information via AccViewer/controls for the scrollbars.
- You could ask at either of these threads, if that information can be retrieved via other means, otherwise something like PixelSearch could be used for an approximate figure.
[Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium! - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=42890
Using Selenium with AutoHotkey- Cross browser automation! - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=32323
- You can retrieve such information via COM in Internet Explorer and HTML Help.
- Adobe Reader uses ScrollBar controls, so you might be able to retrieve information from those, I haven't tested yet.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6395
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Getting position and size of the scroll bar

25 Jan 2018, 16:46

- For Adobe Reader:

Code: Select all

;from WinUser.h:
;SB_HORZ := 0
;SB_VERT := 1
;SB_CTL := 2
;SB_BOTH := 3

q:: ;adobe reader - get scrollbar positions
ControlGet, hCtl1, Hwnd,, ScrollBar1, A
ControlGet, hCtl2, Hwnd,, ScrollBar2, A
;SB_CTL := 2
vPos1 := DllCall("user32\GetScrollPos", Ptr,hCtl1, Int,2)
vPos2 := DllCall("user32\GetScrollPos", Ptr,hCtl2, Int,2)
DllCall("user32\GetScrollRange", Ptr,hCtl1, Int,2, IntP,vMin1, IntP,vMax1)
DllCall("user32\GetScrollRange", Ptr,hCtl2, Int,2, IntP,vMin2, IntP,vMax2)
vOutput := vMin1 " " vPos1 " " vMax1 " " Round(vPos1/vMax1*100) "%"
. "`r`n" vMin2 " " vPos2 " " vMax2 " " Round(vPos2/vMax2*100) "%"
MsgBox, % vOutput
return
- Note: you can retrieve the page number from an Edit control that is always visible, and the last page number from a Static control when you do Ctrl+G. You can also retrieve the last page number via Xpdf (pdftotext.exe, pdfinfo.exe etc).
- Search terms: SBM_GETPOS, GetScrollPos, GetScrollInfo, GetScrollRange.

- For Internet Explorer/HTML Help (requires WBGet function, see link in script):

Code: Select all

;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

q:: ;internet explorer/html help - get vertical scrollbar position
;position of topmost visible point relative to height
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)

vPosY := oWB.document.documentElement.scrollTop
vPosH := oWB.document.documentElement.scrollHeight
vPosPct := Round(vPosY/vPosH*100)
MsgBox, % vPosPct "%"
oWB := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: afe, Albireo, andersson-c, asad41163, Portwolf and 123 guests