how to move mouse cursor?

I need to move mouse cursor,for example you open web page and mouse cursor moves to some location. I have some code and it works in java, but in javascript it doesn't.  Can somebody show small example how to do it in javascript?
KaraliusAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahosangFinance Systems DeveloperCommented:
Not possible with javascript.
makcCommented:
however, I think it can be done with javascript and layered windowless transparent flash. this flash would have to a) turn off cursor b) substitute it with simmilar image c)accept commands from javascript and move it accordingly, and d) fire back mouse events.

As you see, this is not even remotely simple job, so 150 pts... hell, 500 pts yet would not be enought...
KaraliusAuthor Commented:
it is really imposible directly? hm... but never say never, or smth else ;]
makc> I can increasy points, if somebody will offer something really useful, or maybe even give whole 1000 for example...
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

CodescripterCommented:
Hi Karalius,

What if you were to simply make the user *believe* that the mouse cursor was moving?
The following example will simulate a moving mouse cursor, and take a specified action when it is in the proper position:

//--- Example ------------------------------------------------------//

<html><head><title>test</title>

<script language="JavaScript"><!--
function ReplaceMouse() {
  document.body.style.cursor = "text";
  document.getElementById("fakemouse").style.visibility = "visible";
}

function MoveCursor() {
  var d = document.getElementById("fakemouse");
  var x = d.style.posLeft;
  var y = d.style.posTop;
 
  if (x < 400 || y < 300) {
    d.style.posLeft = x + 1;
    d.style.posTop = y + 1;
    setTimeout("MoveCursor()", 1);
  }
  else {
    document.thisForm.btnDoSomething.click();
  }
}
//--></script>

</head>


<body onload="ReplaceMouse(); MoveCursor()">

<h2>Moving the fake mouse</h2>
<hr>
<br><br>

<div id="buttonDiv" style="position:absolute; top:290; left:360; z-index:1">
<form name="thisForm">
<input name="btnDoSomething" type="button" value="Do Something" onclick="alert('Button was clicked.');">
</form>
</div>

<div id="fakemouse" style="position:absolute; top:100; left:200; z-index:20; visibility:hidden"><img src="http://www.scld.org/images/mousecursor.gif"></div>


</body></html>
KaraliusAuthor Commented:
maybe, but in this example you see two mouses ;] , but I need only one visible..
CodescripterCommented:
Okay, how about this... (I'm really trying for these points!)   =)
What I did was used the inherent properties of the windows draw function for the mouse cursor in that it draws each pixel of the text cursor the "opposite" color of the pixel it is covering.

//--- Example ------------------------------------------------------//

<html><head><title>test</title>

<script language="JavaScript"><!--
function ReplaceMouse() {
  document.body.style.cursor = "text";
  document.getElementById("pseudorealmouse").style.visibility = "visible";
  document.getElementById("fakemouse").style.visibility = "visible";
}

function MoveCursor() {
  var d = document.getElementById("fakemouse");
  var x = d.style.posLeft;
  var y = d.style.posTop;
 
  if (x < 400 || y < 300) {
    d.style.posLeft = x + 1;
    d.style.posTop = y + 1;
    setTimeout("MoveCursor()", 1);
  }
  else {
    document.thisForm.btnDoSomething.click();
  }
}

function FollowCursor() {
  var x = window.event.x;
  var y = window.event.y;
  var d = document.getElementById("pseudorealmouse");

  d.style.posLeft = x - 5;
  d.style.posTop = y - 10;
}
//--></script>

</head>


<body onload="ReplaceMouse(); MoveCursor()" onmousemove="FollowCursor()">

<h2>Moving the fake mouse</h2>
<hr>
<br><br>

<div id="buttonDiv" style="position:absolute; top:290; left:360; z-index:1">
<form name="thisForm">
<input name="btnDoSomething" type="button" value="Do Something" onclick="alert('Button was clicked.');">
</form>
</div>

<div id="fakemouse" style="position:absolute; top:100; left:200; z-index:20; visibility:hidden"><img

src="http://www.scld.org/images/mousecursor.gif"></div>

<div id="pseudorealmouse" style="position:absolute; top:100; left:200; z-index:20; visibility:hidden"><img

src="http://www.scld.org/images/textcursor.gif"></div>


</body></html>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodescripterCommented:
Another thought, Karalius:

If you would like to speed up the movement of the "fake" mouse, simply increase the distance it moves per clock cycle as follows:


function MoveCursor() {
  var d = document.getElementById("fakemouse");
  var x = d.style.posLeft;
  var y = d.style.posTop;
 
  if (x < 400 || y < 300) {
    d.style.posLeft = x + 2;      //   <--- increase change in x
    d.style.posTop = y + 2;      //   <--- increase change in y
    setTimeout("MoveCursor()", 1);
  }
  else {
    document.thisForm.btnDoSomething.click();
  }
}
makcCommented:
ppoints raised... hmm, perhaps I'll be back with example of what I was talking about...
KaraliusAuthor Commented:
codescripte>not bad example... ;]
but ... jes, if you dont move mouse, it is ok, but if you move it, you can see 2 cursors...
but the main thing is only one cursor...

so I will try to wait another examle, or smth else.

ps..sure, you will give some point for effor,
and maybe it is another way not in javascript to do it? I mean from web-page
javascript isn't necessary

makcCommented:
i can't get my hands to install flash. but, trust me, that's possible to hide cursor and to change the way thing, that replaces cursor, moves. for example, take a look at http://joecartoon.com/pages/torpedojoe/ (cursor is not hidden there, but it is possible to hide it; you should take a look at the torpedo launcher motion - it is not truly "follows" a cursor, and so could be potentially moved to any location within movie rectangle)

p.s.: you don't have to accept this answer, okey.
CodescripterCommented:
Karalius,
Thanks for the points.
~Codescripter
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.