PDA

View Full Version : Q: Get cursor position under IE5+


Ron Savage
25.05.2001, 04:21
Is there any way to get and set the cursor position? Using IE-specific code is acceptable.

Cheers
Ron Savage
http://savage.net.au/index.html

dayve
25.05.2001, 14:35
I did a quick test and it doesn't seem to work... I am going to review the code now...

dayve

<center>
Nine Inch Nails Forum
http://www.nineinchnailz.com/forum
</center>

Brian Nickel
26.05.2001, 17:21
Heres my mouse object:
<pre id=code><font face=courier size=2 id=code>Mouse={
lastX:0,
lastY:0,
X:0,
Y:0,
move:function(x,y){Mouse.lastX=Mouse.X;Mouse.lastY =Mouse.Y;Mouse.X=x;Mouse.Y=y;if(Mouse.onmove) return Mouse.onmove(Mouse.X,Mouse.Y); return true;},
down:function(){Mouse.isDown=true; if(Mouse.onpress) return Mouse.onpress(Mouse.X,Mouse.Y); return true;},
up:function(){Mouse.isDown=false; if(Mouse.onrelease) return Mouse.onrelease(Mouse.X,Mouse.Y); return true;},
capture:function(){
document.onmousedown = Mouse.down;
document.onmousemove = function(e){return Mouse.move((!document.all)?e.pageX:event.x+documen t.body.scrollLeft,(!document.all)?e.pageY:event.y+ document.body.scrollTop);}
document.onmouseup = Mouse.up;
if (document.layers) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}
}</font id=code></pre id=code>
To capture mouse movements, you call Mouse.capture(), I haven't added Mouse.release() yet.
To add a mouse down handler, Mouse.onpress(x,y).
To add a mouse up handler, Mouse.onrelease(x,y).
To add a mouse movement handler, Mouse.onmove(x,y).
The 5 properties of this object are isDown, X, Y, lastX, and lastY.
isDown refers to whether a button is pressed. X and Y are the page co-ordinates of the cursor and lastX and lastY are the previous co-ordinates of the cursor.

ScriptGuru={
getName:function(){return 'Brian Nickel';},
getEmail:function(){return '[url:6fw69tsbqi]scriptguru@f2s.com[/url:6fw69tsbqi]';},
getURL:function(){return '[url:6fw69tsbqi]http://www.scriptguru.f2s.com[/url:6fw69tsbqi]';}
};

Brian Nickel
27.05.2001, 01:57
Its the same object I use for my dLayer objects, but I excluded all the dLayer events:
<ul>
dLayer.onmouseover()
dLayer.onmouseout()
dLayer.onmousemove(x,y)
dLayer.ondrag(x,y)
dLayer.ondragover()
dLayer.ondragout()
dLayer.onmousedown(x,y)
dLayer.onmouseup(x,y)
dLayer.onclick(x,y)
[/list]
As you can see, I have a <u>lot</u> of time on my hands.

ScriptGuru={
getName:function(){return 'Brian Nickel';},
getEmail:function(){return '[url:z70sqe5bcp]scriptguru@f2s.com[/url:z70sqe5bcp]';},
getURL:function(){return '[url:z70sqe5bcp]http://www.scriptguru.f2s.com[/url:z70sqe5bcp]';}
};

Ron Savage
27.05.2001, 19:38
Thank you, gentlemen. A fine piece of coding. Worthy of my future study.

But, ummmm, not what I imprecisely asked for. By cursor I meant that vertical, blinking thing, not ye olde mouse cursore...


Cheers
Ron Savage
http://savage.net.au/index.html

Brian Nickel
27.05.2001, 19:59
Oh, that cursor.
Mail.com has an HTML editor, I was going to look at it later, I'll pass on my findings.

ScriptGuru={
getName:function(){return 'Brian Nickel';},
getEmail:function(){return '[url:uulqztks6b]scriptguru@f2s.com[/url:uulqztks6b]';},
getURL:function(){return '[url:uulqztks6b]http://www.scriptguru.f2s.com[/url:uulqztks6b]';}
};

Ron Savage
27.05.2001, 20:06
Yes, this happens to be in the context of using an HTML editor, probably a copy of the one you mention. We've developed it a little further.
If you use said editor you notice that:
1) You can create a table
2) You can drag and drop an image into a table cell
3) In the process (ie during the d-and-d), the vertical cursor jumps from cell to cell to track the mouse cursor
4) How the hell do they do that?
5) We believe that solving this problem leads to a solution of how to d-and-d nested tables :-)

Cheers
Ron Savage
http://savage.net.au/index.html

Xanth
27.05.2001, 23:40
Sounds liek they just attached mouseover events to the tables and set focus to field accordingly.

<font color=teal>xanth = new Object();
xanth.name = "Mike";
xanth.mail = "[url:sexgty0xly]belgedin@earthlink.net[/url:sexgty0xly]";
xanth.age = 16;
</font id=teal>

Ron Savage
28.05.2001, 04:05
FYI: I've just tested function mouseObject under IE 5.0, where it worked, under Netscape 6.01, where it worked (amazingly), and under Opera 5.11, where it failed (as expected). Under Opera the text '0,0' appears in what I assume is the status line, above the address line.


Cheers
Ron Savage
http://savage.net.au/index.html