Had high hopes for GetCaretPos but...

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
bbrink
Pro Scripter
Posts: 70
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

Had high hopes for GetCaretPos but...

Post by bbrink » Mon Feb 12, 2018 2:28 am

Hi,

I am working on a script that feeds spreadsheet data into an older accounting system. I am having trouble with timing due to some pop up dialogs that cannot easily be tackled with an event handler.

I had high hopes for GetCaretPos being able to confirm which field I am in but it does not work with this application. It returns same coordinates for all fields.

The forum threads on GetCaretPos are dated, I am wondering if anyone has any new ideas on how to use screen coordinates to confirm cursor location?

I am trying to avoid having 2-3 second waits looking for windows that usually do not pop up.

Thanks in advance,

Bob

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Had high hopes for GetCaretPos but...

Post by Marcus Tettmar » Mon Feb 12, 2018 9:52 am

GetCaretPos is something that MAY or MAY NOT work and depends on the app in question and all you can do is try it. It's not going to work for all apps. What may be happening is the caret pos is reported relative to the field it's in, so it's nearly always going to be effectively 0,0 because it's based on the edit field it's in. If you were in a word processing type app this would make more sense.

Unfortunately there are many cases where in automation we need to use a timeout to wait for a window that may or may not appear. Yes, it adds time to the automation, but reliability is usually more important than speed.

Often we also have to assume which field we are in based on our known starting point. E.g. we open a window, first field is focused and we tabbed three times, we must be in the fourth field. But you could also look at using the UI functions - Find Object Wizard - to see if you can FORCE focus to a particular field.

If these dialogs are difficult can you use image recognition instead - use WaitScreenImage with a timeout?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

bbrink
Pro Scripter
Posts: 70
Joined: Thu Dec 31, 2009 2:36 am
Location: Minnesota
Contact:

Re: Had high hopes for GetCaretPos but...

Post by bbrink » Tue Feb 13, 2018 9:17 pm

Hi Marcus
,
Thanks for the great advice. I ran a few more tests and slowed the script down significantly and now GetCaretPos no longer returns same coordinates for every field.

I did notice that (in this app) different coordinates are sometimes returned when the test is run via different means, EXE, manual stepping through debugger or stepping via debugger. Weird. -But the results were consistent as long as the test was run the same way.

Changing the relative/absolute setting did not always change the coordinates that were returned. I tested relative/absolute in NOTEPAD and did not have this issue.

I ended up making my Event Handler smarter using UIClick and UIFocus. Oddly enough UISetValue did not work with this application.

I would suggest to anyone else getting goofy results from GetCarotPos to try UIFocus instead or just prior to GetCarotPos. It worked for me, your mileage may vary.

Thanks again for your great advice, I hope these added notes may help others.

Bob

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