简体   繁体   中英

Smooth mouse movement in C++

I was wondering if anyone could help me with some code, essentially I've made a small function that moves the mouse cursor relative to the mouse cursor's current position, however the cursor teleports; I'd like to find a way to make it 'glide', smoothly so it looks a little more natural.

Here is the code below:

#import <Windows.h>

void MouseXY(int x, int y) {
        POINT p;
        if (GetCursorPos(&p)) {
            SetCursorPos(p.x + x, p.y + y);
        }
    }

Any help would be greatly appreciated.

If you want the cursor to slide smoothly instead of teleporting, I would suggest using while loop, some delta value, and Sleep function...

What you are basically doing there is instantaneously moving the cursor.

What you probably want is to move the cursor with smaller steps.

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