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.
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 . And also while it is doing that spin, I want to execute another key-press 4 times.
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
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.
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.