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?
* 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?