这是我编写的代码。

#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    POINT cursorPos;
    HWND handle = FindWindowA(NULL,"MyGame");

    ScreenToClient(handle,&cursorPos);

    repeat:

    int x,y;

    if (GetKeyState(VK_UP) & 0x8000) goto Script;

    else goto repeat;

    Script:

    GetCursorPos(&cursorPos);

    cursorPos.x = cursorPos.x;

    cursorPos.y = cursorPos.y + 4;

    SetCursorPos(cursorPos.y, cursorPos.y);


    system("cls");

    cout << "Y Pos : " << cursorPos.y << "\n X Pos: " << cursorPos.x << endl;

    Sleep(5.3);

    goto repeat;


    system("PAUSE");
    return 0;

}


这样,当我按下“向上”箭头时,它将每5.3毫秒将鼠标缓慢下移4个像素。我遇到的问题是,我仅尝试修改鼠标的Y坐标(通过添加到鼠标的坐标来使其向下移动),但是它也向下移动了鼠标的X坐标,导致倾斜线而不是直线向下的线。任何帮助表示赞赏。

最佳答案

尝试更改SetCursorPos(cursorPos.y,cursorPos.y);到SetCursorPos(cursorPos.x,cursorPos.y);

10-08 10:57