Could help if you have problems with:
- mouse cursor does not move to the correct position
- mouse cursor always moves to edges
- mouse cursor moves only to the center of window width or window height
Code: Select all
CoordMode, Pixel, Client
CoordMode, Mouse, Client
; global vars
appOriginalWidth := 320 ; original width of the dos app/game (common 320)
appOriginalHeight := 240 ; original height of the dos app/game (common 240)
appScreenScale := 1 ; scale factor (see "Actions > #appScreenScale" in description below for the correct value)
DosBoxMouseMove(x, y) {
global appOriginalWidth, appOriginalHeight, appScreenScale
x := x * appScreenScale
y := y * appScreenScale
MouseMove, 0, 0
while (x > 0)
{
if (x > appOriginalWidth) {
MouseMove, appOriginalWidth, 0, 0, R
x -= appOriginalWidth
}
else {
MouseMove, x, 0, 0, R
x = 0
}
}
while (y > 0)
{
if (y > appOriginalHeight) {
MouseMove, 0, appOriginalHeight, 0, R
y -= appOriginalHeight
}
else {
MouseMove, 0, y, 0, R
y = 0
}
}
}
Explanation
There are three layers of coordinates:
- original app/game resolution (320x240)
- DosBox basic resolution (640x480)
- DosBox window resolution (can differ)
Conditions
- MouseMove can not move more than the original resolution width or height to work exactly.
- Every coordinate from ImageSearch or PixelSearch is based on the DosBox basic resolution.
- The final MouseMove coordinates have to be converted to the DosBox window resolution.
Solution
We have to find a way that the different resolutions can interact with each other.
- We want to use the same coordinates resolution. The best is to use the DosBox basic resolution because ImagesSearch and PixelSearch are using it.
- We need to divide the total mouse distance in smaller MouseMove steps to get this done.
Actions
1) Convert coodinates from basic to window resolution #appScreenScale
We can do this by using a scale factor as a global variable which is the ratio between DosBox window resolution and DosBox basic resolution. When DosBox is run in the default window (640x480) appScreenScale is 1. If DosBox is run in a bigger window or fullscreen the factor depends on the real resolution and what DosBox makes out of it. It's a bit tricky. In short: DosBox scales the original resolution up until it fits best in the window. The scale basis is the original resolution. Example: for a screen with 1920x1080 it makes a window resolution of 1280x960 (4 x original resolution). Because this is twice of the DosBox basic resolution (640x480) appScreenScale is 2 in this case. Maby you have to play with the value depending on your screen.
2) Divide MouseMove in multiple steps
Because MouseMove can not move more than the original resolution, we have to use a simple trick. For example out of a distance of 400px we make two MouseMove actions, one with 320px and one with 80px.
Global vars
The global vars should be set at top of the script. If you change between different window sizes or fullscreen you have to update appScreenScale with the correct value.
This solution will probably not work in every use case.
Please let me know, if it does not work for you.