简体   繁体   English

使用SendInput模拟游戏中的360鼠标移动

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

Ok so, I have this code right now which makes the mouse cursor move to the right as long as you hold down the Z key on the keyboard. 好的,我现在有了这段代码,只要您按住键盘上的Z键,鼠标光标就会向右移动。

Code: 码:

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

The function: 功能:

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));
}

Now, I want it to do a full circle spin( a 360 basically ) inside a game with just 1 key press . 现在,我希望它可以在游戏中仅需按一下键就可以进行完整的旋转( 基本上是360度 )。 And also while it is doing that spin, I want to execute another key-press 4 times. 而且在进行旋转时,我想再次执行4次按键。

I can't figure out a good way to do this.. maybe using a timer would be a good idea? 我不知道这样做的好方法。也许使用计时器会是个好主意?

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

But how would I go about this? 但是我该怎么办呢?

I managed to do what I wanted (in what might not be the best way, but it does what I intended for it to do..) 我设法做到了自己想做的(也许不是最好的方法,但是它做了我打算做的事情。)

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);
}

If u have any suggestions to improve this, please do say. 如果您有任何改善建议,请说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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