user6821023
user6821023

Reputation:

Mouse Movement Script / Program

This is the code I have written.

#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;

}

It is so that when I press the 'UP' arrow it will slowly move the mouse down 4 pixels every 5.3 ms. The problem I have with it is that I am only trying to modify the Y coordinates of the mouse (To make it move down by adding to its coordinates) but, it is also moving the X coordinates of the mouse down, resulting in a slanted line instead of a straight down one. Any help appreciated.

Upvotes: 0

Views: 895

Answers (1)

Rok
Rok

Reputation: 496

try changing SetCursorPos(cursorPos.y, cursorPos.y); to SetCursorPos(cursorPos.x, cursorPos.y);

Upvotes: 1

Related Questions