簡體   English   中英

使用SendInput模擬游戲中的360鼠標移動

[英]Simulate a 360 mouse movement inside a game using SendInput

好的,我現在有了這段代碼,只要您按住鍵盤上的Z鍵,鼠標光標就會向右移動。

碼:

if (GetAsyncKeyState(0x5A))
{
    cMouseInput mInput;
    mInput.MouseMove(1, 0);  // Right
    //mInput.MouseMove(-1, 0); // Left
}

功能:

void cMouseInput::MouseMove(int X, int Y)
{
    double fScreenWidth = GetSystemMetrics(SM_CXSCREEN) - 1;
    double fScreenHeight = GetSystemMetrics(SM_CYSCREEN) - 1;
    double fX = X * (65535.0f / fScreenWidth);
    double fY = Y * (65535.0f / fScreenHeight);

    INPUT mInput = { 0 };
    mInput.type = INPUT_MOUSE;
    mInput.mi.dwFlags = MOUSEEVENTF_MOVE;
    mInput.mi.dx = fX;
    mInput.mi.dy = fY;

    SendInput(1, &mInput, sizeof(INPUT));
}

現在,我希望它可以在游戲中僅需按一下鍵就可以進行完整的旋轉( 基本上是360度 )。 而且在進行旋轉時,我想再次執行4次按鍵。

我不知道這樣做的好方法。也許使用計時器會是個好主意?

像, Start timer on key-press -> execute other key-press -> End timer and release key

但是我該怎么辦呢?

我設法做到了自己想做的(也許不是最好的方法,但是它做了我打算做的事情。)

if (GetAsyncKeyState(i1x1Value) & 1)
{
    cMouseInput mInput;

    int iCount = 0;
    HANDLE hTimer = CreateEvent(NULL, FALSE, FALSE, NULL);
    while (iCount < 4)
    {
        WaitForSingleObject(hTimer, i1x1Sleep); // Wait for x amount
        mInput.MouseMove(50, 0); // Right

        iCount++; // Repeat 4 times
    }
    CloseHandle(hTimer);
}

如果您有任何改善建議,請說。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM