简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM