• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3716
  • Last Modified:

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?
0
Karalius
Asked:
Karalius
  • 4
  • 3
  • 3
  • +1
1 Solution
 
ahosangFinance Systems DeveloperCommented:
Not possible with javascript.
0
 
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...
0
 
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...
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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>
0
 
KaraliusAuthor Commented:
maybe, but in this example you see two mouses ;] , but I need only one visible..
0
 
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>
0
 
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();
  }
}
0
 
makcCommented:
ppoints raised... hmm, perhaps I'll be back with example of what I was talking about...
0
 
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

0
 
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.
0
 
CodescripterCommented:
Karalius,
Thanks for the points.
~Codescripter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now