mousemove for all screen resolutions

Started by edmoran, February 26, 2015, 10:03:05 AM

Previous topic - Next topic

edmoran

I have a script that uses many mousemoves and mouseclicks.  It finally works perfectly...for my screen resolution.  I have dual monitors at 1920x1080 resolution.  Now I need to make it work fine for two additional resolutions, or even better....for ANY resolution.  How do I go about making this script work properly?  I know I'll start by getting the users resolution with winmetrics(0) and (1).  But then do I need to multiply each coordinate by a certain factor?  If so, how do I go about calculating that factor?

Ed

td

The coordinates you use with MouseMove or MousePlay are virtual screen coordinates.  This means that in theory you don't need to do anything when moving your script to systems with different resolutions.  There are a few caveats, however. 


  • Since virtual screen coordinates are 1000X1000 and most modern monitors have more than a 1000 pixels in either dimension you loose some precision.  This means mouse positioning can be off target when going to a different resolution unless you coordinates are centered on the object you are going to drag or click.
  • If you change to a monitor with a different aspect ratio, the shape of screen widgets can change and throw off your coordinates relative to a targeted widget.
  • If you go from a dual monitor system with the desktop stretched across both monitors to a single monitor system any coordinates that would place the mouse on the second monitor will have no meaning on a single monitor system.  This also applies to a system with dual monitors but with a different relationship between the primary and secondary monitor.
  • If you try to use a script created on a HD monitor on a system with a 4K or 5K monitor, good luck.
  • Using a dual monitor system with monitors that  are not the same screen resolutions may cause unexpected results.
.

Using window relative mouse coordinates can ameliorate some issues but cause others.

In short, test carefully.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

edmoran

The reason my script doesn't work is because the application I am trying to send mouse clicks to has a particular pixel size.  So it looks different under different screen resolutions.

td

What precisely do you mean by 'particular pixel size'? If you mean that it has a fixed Windows virtual screen coordinate ( not the same as WinBatch virtual screen coordinates) size then you should be OK using Windows relative mouse moves.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade