Center mouse cursor in app

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Center mouse cursor in app

Post by Esabik » Fri Jan 31, 2014 3:08 pm

Is there a way to center the mouse in the middle of the active window on the screen?? I want to do this because i am using waitcursorchanged> in my script and just in case its not centered in the app, i might end up with unwanted results. Now if it centers to the middle of the screen itself and not the app, that will work as well.

This is what i am waiting on:

//press enter to start report generation
press enter
wait>4
//waiting on cursor to change from hourglass
WaitCursorChanged>7000
wait>.3
SetFocus>Crystal Reports for Macola - [WO Items to Pick List3m.rpt]
wait>.2

Thanks
Just when you thought it was safe to go in the water........:evil:

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

Post by Marcus Tettmar » Fri Jan 31, 2014 3:46 pm

Sure:

Code: Select all

//get x,y and width and height of active window
GetActiveWindow>title,x,y,w,h

//now some elementary math to calculate the middle of the window
Let>xpos={%x%+(%w% div 2)}
Let>ypos={%y%+(%h% div 2)}

//put the mouse there
MouseMove>xpos,ypos
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Post by Esabik » Fri Jan 31, 2014 4:15 pm

[quote="Marcus Tettmar"]Sure:

Great thanks that works like magic!!!! See it here and then poof its there.... :shock:
Just when you thought it was safe to go in the water........:evil:

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