Scroll to Precise Window Location

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Scroll to Precise Window Location

Post by JRL » Fri Oct 09, 2020 4:33 pm

I have a desire to use Macro Scheduler on a Remote Desktop session where I'm not allowed to install Macro Scheduler. The solution for me is to un-maximize the RDP session and manipulate it as you would any other window using mouse clicks and keyboard functions. I also want to reduce the size of the window and only work in specific areas without actually rearranging things in the RDP session. This can be accomplished by making the un-maximized RDP session window whatever size you want and then scrolling to the location(s) you want to work with. This is easily accomplished manually. I want to do it via Macro Scheduler. I searched but didn't find a workable method for precisely manipulating the scroll bars other than by mouse moves and clicks.

Below is an example of mouse click manipulation of the scrollbars in Notepad. The Notepad window settings are important to make this work properly, so if you try this make sure your Notepad is configured like mine. I know there are other things I could do, for example, a search for the "X" to produce a similar result in Notepad but I'm not really trying to manipulate Notepad, just using it to demonstrate.

The crux of this method is that when you right click on a scrollbar in many applications you get a menu where one of the menu options is "Scroll Here". So using MouseMoveRel> one can select a position on the scrollbar and scroll fairly precisely. If it works properly for you, it should scroll to the location of the only alpha character in the text file and center it in the window.

Does anyone know a better way? Precise scrolling is important.

Code: Select all

//Notepad font is set to Consolas, Regular, 11
//Notepad Status bar is on

//Delete File before creating it JIC
DeleteFile>%temp_dir%JRLTextFile.txt

//Create a file with an X in the middle
Let>vDoc=
Let>kk=0
Repeat>kk
  Add>kk,1
  Let>vLine=%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%crlf%
  If>kk=658
    Let>vLine=%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%X%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%TAB%%crlf%
  EndIF
  Let>vDoc=%vDoc%%vline%
Until>kk=6000
WriteLn>%temp_dir%JRLTextFile.txt,wres,vDoc
////////////////////////////////////////

//Open File in Notepad
RunProgram>notepad.exe %temp_dir%JRLTextFile.txt
WaitWindowOpen>JRLTextFile*
Wait>1
//////////////////////

//Position and size window as needed
GetWindowHandle>JRLTextFile*,hWndParent
Let>Win_Usehandle=1
MoveWindow>hWndParent,100,50
ResizeWindow>hWndParent,500,400
SetFocus>hWndParent
Let>Win_Usehandle=0
////////////////////////////////////

//Everything to this point is simply setting up
//a window with which to work.

//Mouse moves and clicks to manipulate the scroll bars
//Wait> functions are in place if you need them
MouseMoveRel>485,103
rClick
Wait>0
Send>s
Wait>0
Press Enter

MouseMoveRel>197,360
rClick
Wait>0
Send>s
Wait>0
Press Enter

MouseMoveRel>485,343
Let>LC=0
Repeat>LC
  Add>LC,1
  lClick
Until>LC=4
///////////////////////////////////////////////////////
Using Windows 10 and Macro Scheduler v15.0.12

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Scroll to Precise Window Location

Post by PepsiHog » Sun Mar 14, 2021 6:34 pm

@JRL
Here's the thing. What functionality does the actual window have? I looked up on the internet for functions of notepad. If you press Ctrl-G you get a prompt for what line you want to jump to. You could send the line number, but does the window your working with have the same function?

Without information about the actual window, I can not figure how to help.

Hope this helps :lol:
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Scroll to Precise Window Location

Post by mightycpa » Sun Mar 14, 2021 7:49 pm

Hi JRL,

I wonder if this might help, or get you to something that can help. I haven't used it: https://www.codeproject.com/articles/10 ... -scrolling

The most I've done on RDP is maximize the screen on a second display, and scroll up and down using the arrow controls. That may not deliver the precision you're looking for.

I take it that you're isolating a small portion of the desktop and working within that space? Is that why you unMaximize the RDP window? Again, I haven't worked with it, but there is a Sysinterals utility called Zoomit. https://docs.microsoft.com/en-us/sysint ... ads/zoomit Essentially, it's a drawing tool, but one thing it can do is magnify the desktop. If you do that, then maybe the normal windows scroll arrows could become precise enough to work with.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Scroll to Precise Window Location

Post by mightycpa » Tue Mar 16, 2021 3:13 pm

Hi JRL, for some reason, your question about this fascinates me. I stumbled across another website, they have a very reasonably priced product that might do the job for you. One of the features of their software divides a single monitor (desktop?) into regions, and then turns each of these regions into its own desktop. After that, you can save it as a profile, so that it is easy to summon when you need it. I think that's what it says. Unfortunately, their free version doesn't let you try that feature out.

I was thinking that if you could capture or if you know the general area you need to work in, you could turn it into a desktop, which would eliminate the need for scrolling.

Here's the site: https://www.displayfusion.com/
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Scroll to Precise Window Location

Post by Grovkillen » Thu Mar 14, 2024 9:49 am

Did anyone find a good way of doing this? I would like to use this to scroll a HTMLViewer window back to the place it was before updating the HTML code inside it. The current behavior makes the window jump back up to the top.

I'm using DisplayFusion and the suggested virtual desktop is a cool feature but not to be used in "production".
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Scroll to Precise Window Location

Post by Grovkillen » Thu Mar 14, 2024 10:29 am

If I right click on a standard Windows scroll bar I get a popup menu. Is it possible to add some functionality to MS to get the position or set the position using that? I'm just adding this to the discussion, maybe it will open up a new approach for someone else.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Scroll to Precise Window Location

Post by Grovkillen » Thu Mar 14, 2024 10:38 am

https://learn.microsoft.com/en-us/windo ... tscrollpos
https://learn.microsoft.com/en-us/windo ... crollrange
https://learn.microsoft.com/en-us/windo ... scrollinfo
https://learn.microsoft.com/en-us/windo ... ollbarinfo

user32 dll seems to have this already... anyone better than me in finding the syntax to get this data?

"GetScrollBar" and "SetScrollBar" seems like nice commands to have natively in MS.

Some more on the subject: https://www.codeproject.com/articles/10 ... -scrolling

And just some PowerShell discussions about the subject: https://stackoverflow.com/questions/490 ... htextboxes
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Scroll to Precise Window Location

Post by Grovkillen » Thu Mar 14, 2024 12:57 pm

Ok, I found out how to use the user32.dll call. It's working but not ideal.

Code: Select all

Run>notepad
WaitWindowChanged>5
Let>WIN_USEHANDLE=1
GetActiveWindow>TEMP_handle,,,,
GetWindowChildList>TEMP_handle,TEMP_children
Let>k=0
Repeat>k
Let>k=k+1
Press Enter
Until>k=100

//my TEMP_children is empty, if not you could use this:
LibFunc>User32,GetScrollPos,currentPosition,TEMP_child_handle,1
//I used the "View System Windows" tool and found that my Edit object's handle was 269582 and that way I could get the position of the scrollbar
MDL>currentPosition
The second call (SetScrollPos) is moving the scrollbar but not scrolling the window....

Code: Select all

//LibFunc>User32,GetScrollPos,currentPosition,<handle>,<1=vertical,2=horizontal>
LibFunc>User32,GetScrollPos,currentPosition,269582,1
//LibFunc>User32,SetScrollPos,previousPosition,<handle>,<1=vertical,2=horizontal>,<new position>,<redraw>
LibFunc>User32,SetScrollPos,previousPosition,269582,1,5,true
Let>ME=%Script%

Running: 15.0.27
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts