[Tutorial]How to possess somebody's mouse.

Posts 1–15 of 22 · Page 1 of 2
[Tutorial]How to possess somebody's mouse.


feel free to say how im stupid etc for using goto, idgaf[php]#include <windows.h>[/php]
Includes windows.h

[php]INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{[/php]

Entry Point
[php]int xAxis, yAxis;[/php]
2 axes
[php]while(true)
{[/php]
starts infinitate loop
[php]moveMouse:
for(xAxis = 0; xAxis < 1600; xAxis++)
for(yAxis = 0; yAxis < 1200; yAxis++)
{
Sleep(20);
if((GetAsyncKeyState(VK_END)))
{
goto exit;
}
SetCursorPos(xAxis,yAxis);
}[/php]

i use moveMouse label and goto because its easy.

When xAxis = 0, xAxis is less than 1600, then increment xAxis
same with yAxis

Move the cursor each pixel every 20 milliseconds.

if key END is pressed, goto end.

[php]if((xAxis == 1600) && (yAxis == 1200))
{
goto moveMouse;
}[/php]

if xAxis and yAxis are max value (for my monitor)
goto moveMouse.

[php] }
exit:
MessageBox(NULL,L"How did you know how to end?",L"",MB_ICONQUESTION);
}[/php]

exit label, exits if End is pressed.
My resolution is on 1024x768. Lol.
Make a lil application for it
Should make it get the screen bounds rather than having it set to such a large resolution computer.

Also why not just do

[php]
for(xAxis = 0; xAxis < 1600; xAxis++)
for(yAxis = 0; yAxis < 1200; yAxis++)
{
Sleep(20);
if((GetAsyncKeyState(VK_END)))
{
break;
}
SetCursorPos(xAxis,yAxis);
}

MessageBox(NULL,"How did you know how to end?", "OMG,MB_ICONQUESTION);
[/php]

Because if C++ logic is anything the same as VB you won't get to "MessageBox" until the for-loop is completed...which is only done when you press end.

Just a suggestion /
Quote Originally Posted by Jason View Post
Should make it get the screen bounds rather than having it set to such a large resolution computer.

Also why not just do

[php]
for(xAxis = 0; xAxis < 1600; xAxis++)
for(yAxis = 0; yAxis < 1200; yAxis++)
{
Sleep(20);
if((GetAsyncKeyState(VK_END)))
{
break;
}
SetCursorPos(xAxis,yAxis);
}

MessageBox(NULL,"How did you know how to end?", "OMG,MB_ICONQUESTION);
[/php]


Because if C++ logic is anything the same as VB you won't get to "MessageBox" until the for-loop is completed...which is only done when you press end.

Just a suggestion /
I don't know how to get screen bounds

I tried the break, but instead of exiting, it just goes back to the top with added xAxis values.


so heres what it looks like. [^ = mouse]

---------------------
^--------------------
---------------------
---------------------
---------------------
---------------------

END IS PRESSED

---------------------
--^------------------
---------------------
---------------------
---------------------
---------------------

and again

---------------------
-----^---------------
---------------------
---------------------
---------------------
---------------------

Hmm weird, I'll do some research.

Also is this C++ or C-Sharp? It looks like C++ to me but I've never used C# so I thought I'd double check

If it's C++ you can use this to get screen bounds apparently:

[php]
//
// Call ::GetSystemMetrics API to get Screen Size
//
void GetPrimaryScreenSizeInPixels( SIZE& s)
{
// Start With Nothing
ZeroMemory( &s, sizeof(SIZE) );

// Get Width/Height
s.cx = (LONG)::GetSystemMetrics( SM_CXFULLSCREEN );
s.cy = (LONG)::GetSystemMetrics( SM_CYFULLSCREEN );

}
[/php]

Source: Get screen SIZE in Visual C++ [Archive] - CodeGuru Forums

I'll get back to you on for exiting. Also, with the goto mousemove section, can't you just whack the if into the loop? Like so

[php]
for(xAxis = 0; xAxis < 1600; xAxis++)
for(yAxis = 0; yAxis < 1200; yAxis++)
{
Sleep(20);
if(GetAsyncKeyState(VK_END)&1)
{
goto exit;
}

if((xAxis == 1600) && (yAxis == 1200))
{
xAxis = 0;
yAxis = 0;
}
SetCursorPos(xAxis,yAxis);
}
[/php]

You can directly change a variable inside a loop with C++ right?

EDIT: AHA! found some documentation on why break is fucking up for you!

Code:
break;

- the break statement gets you out of a loop.  No matter what the loop's ending condition, break immediately says "I'm outta here!"  The program continues with the next statement immediately following the loop.  Break stops only the loop in which it resides.  It does not break out of a "nested loop" (a loop within a loop).
You've got a nested loop there due to your "For xAxis" and "For yAxis" contained within that.



EDIT2: I was just thinking of a way to avoid the nested loop so that you can use break, it ain't pretty but it should work.

[php]
int xAxis =0;
int yAxis =0;

do
{
yAxis++;
if(yAxis == 768)
{
if(xAxis == 1366)
{
xAxis = 0;
yAxis = 0;
}
else
{
xAxis ++;
yAxis = 0;
}

if(GetAsyncKeyState(VK_END)&1)
{
break;
}
SetCursorPos(xAxis,yAxis);

}

if(xAxis != 1366) //signifies that the do loop was exited early
{
MessageBoxA(NULL, "How on earth did you know!?", "Well done", MB_OK);
}
[/php]



EDIT3...LOL

Got the screen bounds sorted I think

[php]
int MaxX = (LONG)::GetSystemMetrics( SM_CXFULLSCREEN );
int MaxY= (LONG)::GetSystemMetrics( SM_CYFULLSCREEN );
[/php]

That's all you need pretty sure.

Will try, thanks
Quote Originally Posted by Kallisti View Post
Will try, thanks
NP I can't even test it haha, I'm so noob at C++ I don't even know what project type to make this
Quote Originally Posted by Jason View Post


NP I can't even test it haha, I'm so noob at C++ I don't even know what project type to make this
In new project wizard > Win32 Project > Make sure it's set to Win32 and not dll or whatever, Make sure you specify it to be empty. > New file under source > .cpp > code > compile.

edit: Get bounds works
oh gosh... :x

create a function and do a return; <.< simple (for the break issue, it obviously only breaks one loop )
Quote Originally Posted by 'Bruno View Post
oh gosh... :x

create a function and do a return; <.< simple (for the break issue, it obviously only breaks one loop )
itd still be all the same code, and since its only doing 1 thing, why make a function


[php]void shitFunction()
{
shit
}[/php]

or how about

[php]shit[/php]
wtf? why would you create a function for that.. >.< you didn't get it..

Code:
for(xAxis = 0; xAxis < 1600; xAxis++) 
            for(yAxis = 0; yAxis < 1200; yAxis++) 
            { 
                Sleep(20); 
                if((GetAsyncKeyState(VK_END))) 
                { 
                    return 0; //or return;
                } 
                SetCursorPos(xAxis,yAxis); 
            }
that inside a function... obviously... not an empty function with return oO

It will break both for's... simple
Quote Originally Posted by 'Bruno View Post
wtf? why would you create a function for that.. >.< you didn't get it..

Code:
for(xAxis = 0; xAxis < 1600; xAxis++) 
            for(yAxis = 0; yAxis < 1200; yAxis++) 
            { 
                Sleep(20); 
                if((GetAsyncKeyState(VK_END))) 
                { 
                    return 0; //or return;
                } 
                SetCursorPos(xAxis,yAxis); 
            }
that inside a function... obviously... not an empty function with return oO

It will break both for's... simple
ohhh i get what you mean too lazy to change code
Compiled, tested and working

No nested loops for me. I let it play through one whole rotation of the screen and it started again nicely. Screen bounds were working too!

[php]
#include <windows.h>

int MaxX = (LONG)::GetSystemMetrics( SM_CXFULLSCREEN );
int MaxY = (LONG)::GetSystemMetrics( SM_CYFULLSCREEN );
int xAxis =0;
int yAxis =0;

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

do
{

yAxis++;
if(yAxis == MaxY)
{
if(xAxis == MaxX)
{
xAxis = 0;
yAxis = 0;
}
else
{
xAxis ++;
yAxis = 0;
}
}
SetCursorPos(xAxis,yAxis);

}while(!GetAsyncKeyState(VK_END)&1);

MessageBoxA(NULL, "How did you know!?", "Well done!", MB_OK);

}
[/php]

ENJOY!

Notice my cunning use of the "while" parameter of the Do-Loop
why global vars? i don't really advice doing it...
Posts 1–15 of 22 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?