PDA

View Full Version : On Mouse Move... I don't get it.



Dibler
01-03-2007, 06:22 PM
Okay... first time I have a problem I can't solve. I've been trying and trying. I want to make a program where I have this target and I should keep the mouse in the middle even it moves randomly to different directions... a bit like shooting a target or so... my code goes like this...

* On show *
-- Set variables
Power = 1 -- (This ads up by clicking mouse)
MouseX = 172
MouseY = 190

--Start timer
Page.Timer(200) -- (This speed is just for testing, can be faster)

* On Timer *
-- Random direction
direction = Math.Random(4)
if direction == 1
then
MouseX = MouseX + power
MouseY = MouseY
elseif direction == 2
then
MouseX = MouseX - power
MouseY = MouseY
elseif direction == 3
then
MouseX = MouseX
MouseY = MouseY - power
elseif direction == 4
then
MouseX = MouseX
MouseY = MouseY + power
end

-- Move mouse cursor to new coordinates
DLL.CallFunction(_SystemFolder .. "\\user32.dll", "SetCursorPos", MouseX..","..MouseY, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);

So... now my mouse cursor is moving randomly to some direction... and that's it... I can't control it really. Surely it moves to some point if I move my cursor but it goes back to same place, since the code says so... but what I want is that when I move mouse to right it ads MouseX... or down it ads MouseY.... and so on. Is it possible? :huh Or maybe I'm doing it all wrong?

Dibler
01-03-2007, 08:02 PM
Never mind. Problem solved... I realised my stupid mistake. I didn't use flat style so I had to make it slightly different and ad some pixels to X and Y coordinates.

* On Show*
-- Set variables
Power = 1 -- (This ads up by clicking mouse)

-- Start the timer
Page.StartTimer(50);

* On Timer *
-- Get the coordinates
tMousePos = System.GetMousePosition(true);
MouseX = tMousePos.X
MouseY = tMousePos.Y

-- Random direction
if direction == 1
then
MouseX = MouseX + power
MouseY = MouseY
elseif direction == 2
then
MouseX = MouseX - power
MouseY = MouseY
elseif direction == 3
then
MouseX = MouseX
MouseY = MouseY - power
elseif direction == 4
then
MouseX = MouseX
MouseY = MouseY + power
end

-- Move mouse cursor to new coordinates
DLL.CallFunction(_SystemFolder .. "\\user32.dll", "SetCursorPos", (MouseX+4)..","..(MouseY+50), DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);


But if someone has better idea I'm always open for suggestions.