Solved

how to move mouse cursor?

Posted on 2003-11-04
11
3,613 Views
Last Modified: 2012-05-04
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
Comment
Question by:Karalius
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 12

Expert Comment

by:ahosang
ID: 9679983
Not possible with javascript.
0
 
LVL 3

Expert Comment

by:makc
ID: 9680118
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
 

Author Comment

by:Karalius
ID: 9681704
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
 
LVL 2

Expert Comment

by:Codescripter
ID: 9683430
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
 

Author Comment

by:Karalius
ID: 9685322
maybe, but in this example you see two mouses ;] , but I need only one visible..
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Accepted Solution

by:
Codescripter earned 500 total points
ID: 9688508
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
 
LVL 2

Expert Comment

by:Codescripter
ID: 9688556
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
 
LVL 3

Expert Comment

by:makc
ID: 9695437
ppoints raised... hmm, perhaps I'll be back with example of what I was talking about...
0
 

Author Comment

by:Karalius
ID: 9697337
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
 
LVL 3

Expert Comment

by:makc
ID: 9833544
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
 
LVL 2

Expert Comment

by:Codescripter
ID: 10011773
Karalius,
Thanks for the points.
~Codescripter
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now