Link to home
Start Free TrialLog in
Avatar of Karalius
Karalius

asked on

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?
Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

Not possible with javascript.
Avatar of makc
makc

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...
Avatar of Karalius

ASKER

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...
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>
maybe, but in this example you see two mouses ;] , but I need only one visible..
ASKER CERTIFIED SOLUTION
Avatar of Codescripter
Codescripter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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();
  }
}
ppoints raised... hmm, perhaps I'll be back with example of what I was talking about...
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

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.
Karalius,
Thanks for the points.
~Codescripter