How to scroll down to the middle of a window?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Nkc784sq67xd
Posts: 5
Joined: 07 Jul 2023, 13:27

How to scroll down to the middle of a window?

Post by Nkc784sq67xd » 03 Dec 2023, 10:56

In a window, say, a folder window or a web browser window, one can pres CTRL + HOME to scroll upmost or CTRL + END to scroll downmost.

But what if I want to scroll to the very middle of the window, how can this be done? With AHk, perhaps?

Nkc784sq67xd
Posts: 5
Joined: 07 Jul 2023, 13:27

Re: How to scroll down to the middle of a window?

Post by Nkc784sq67xd » 03 Dec 2023, 15:43

Why no one replies?

Maybe the vast majority of users work with version 1 instead of with version 2?

User avatar
andymbody
Posts: 1027
Joined: 02 Jul 2017, 23:47

Re: How to scroll down to the middle of a window?

Post by andymbody » 03 Dec 2023, 16:03

Nkc784sq67xd wrote:
03 Dec 2023, 15:43
Why no one replies?
I would say because this is an unusual request. Not easily answered. It will probably take longer for the right person to see your question and respond (if it is universally possible as all). I think this is relatively easy in a browser using JavaScript, but not sure how challenging it is with an app Window.

Nkc784sq67xd
Posts: 5
Joined: 07 Jul 2023, 13:27

Re: How to scroll down to the middle of a window?

Post by Nkc784sq67xd » 03 Dec 2023, 19:55

I agree.

I have found this way to do it in JavaScript, and it may use as a base for someone here for an AHk solution:

Code: Select all

// go to downmost part of a webpage to discover its height
window.setTimeout(()=>{
    window.scrollTo(0, document.body.scrollHeight);
}, 1000)

window.setTimeout(()=>{
// go back to topmost part of the discovered webpage
    window.scrollTo({
        top: 100,
        left: 100,
        behavior: "instant",
    });
}, 2000)

window.setTimeout(()=>{
    // scroll to the middle of a discovered webpage
    window.scrollTo(0, document.documentElement.scrollHeight * 0.50);
}, 3000)

[Mod edit: Changed default AHK code tags to JavaScript-specific Codebox tags.]

emp00
Posts: 175
Joined: 15 Apr 2023, 12:02

Re: How to scroll down to the middle of a window?

Post by emp00 » 04 Dec 2023, 14:59

@Nkc784sq67xd Have you searched the forum for scrollheight?
I found this right away: viewtopic.php?p=148094#p148094
Should be easily converted to v2, the Acc library for AHK v2 is available here: viewtopic.php?t=107857

Good luck and please post your solution here. Thanks.

Descolada
Posts: 1273
Joined: 23 Dec 2021, 02:30

Re: How to scroll down to the middle of a window?

Post by Descolada » 05 Dec 2023, 01:30

Nkc784sq67xd wrote:
03 Dec 2023, 15:43
Why no one replies?

Maybe the vast majority of users work with version 1 instead of with version 2?
It's because this is a difficult problem to solve in a general manner. For older win32 apps you could use SetScrollPos and for a lot of applications you can use the previously mentioned Acc method (it should also work in apps where SetScrollPos works). However, some applications can't be scrolled programmatically, for example Chrome. In that case you would need to use some kind of image-based approach to detect where the scroll thumb is and use Send/ControlSend to scroll. Alternatively inject Javascript through the URL bar, or use Chrome.ahk to directly automate the browser.

As you can see, creating a working reliable solution for ALL applications is near impossible. Perhaps we could help if you specify which application you want to automate?

Post Reply

Return to “Ask for Help (v2)”