GregsStack / InputSimulatorStandard

Input Simulator Standard
MIT License
70 stars 7 forks source link

how does movemouse work? #113

Open alejo9010 opened 2 years ago

alejo9010 commented 2 years ago

hello, im triying to make this work to move mouse to relative window coord, so i got this

        public async void SetCursorPosition(Point p)
        {
            await Delay(500);
            Rectangle rect;
                NativeMethods.GetWindowRect(process.MainWindowHandle, out rect);
            p.X = p.X + rect.Left;
            p.Y = p.Y + rect.Top;
            simulator.Mouse.MoveMouseTo(Convert.ToDouble(p.X), Convert.ToDouble(p.Y));
        }

but the mouse is off by alot from the actual Point where it should move, i debug the app, and the coords are correct. any idea what happen ?

Gh0stWalk3r commented 2 years ago

Hello @alejo9010 the first thing that comes to my mind is that a DPI setting might throw it off the actual coordinates. Can you tell me a bit more of your system/screen settings, like what OS are you using, do you have DPI scaling activated (which value is it set to), what are the given values and what is the actual result? I wish you a nice day 😄 , Gregor

BigIan1969 commented 9 months ago

I'm seeing this issue too. On a Win 10 VM (Virtualbox) no DPI Scaling I'm trying to click on a control that's pretty much in the middle of the screen but it's clicking on VS's System menu which is top left my actual mouse pointer was somewhere completely different and didn't move throughout execution.

Gh0stWalk3r commented 9 months ago

Hello @BigIan1969 , can you tell me a bit more about the execution/setup? In general I would like to know how the setup looks like and how you interact with it, so that I get a better picture of the issue.

public class DPI {
[DllImport("gdi32.dll")] static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

public enum DeviceCap { VERTRES = 10, DESKTOPVERTRES = 117 }

public static float scaling() { Graphics g = Graphics.FromHwnd(IntPtr.Zero); IntPtr desktop = g.GetHdc(); int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES); int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);

return (float)PhysicalScreenHeight / (float)LogicalScreenHeight; } } '@ -ReferencedAssemblies 'System.Drawing.dll' -ErrorAction Stop Return [DPI]::scaling() * 100