Home > Enterprise >  Is it possible to use a double value in mouse_event in C#?
Is it possible to use a double value in mouse_event in C#?

Time:07-22

I need to use a value of type double and move the mouse by a given value. Unfortunately double is not compatible with mouse_event, and only int is compatible. In C as well as AHK it worked without any problem. Is it possible to use double or any value that allows decimal digits in mouse_event in any way? I tried editing

public static extern void mouse_event(uint dwFlags, int dx, int dy, uint dwData, int dwExtraInfo);

to

public static extern void mouse_event(uint dwFlags, double dx, double dy, uint dwData, int dwExtraInfo);

and then the mouse immediately went to the bottom left corner of the screen so this solution doesn't work. I also tried converting value to INT type, but then it doesn't move because the value after conversion sets to 0.

CodePudding user response:

No, you cannot. The function signature is fixed, and you don't get to change it just because.

If you want to use sort-of fractional values, operate the function in MOUSEEVENTF_ABSOLUTE mode. As long as your display less than 65536 pixels wide or high, this allows you to pass coordinates with sub-pixel precision.

  • Related