Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking keys while mouse over links

Status
Not open for further replies.

lambi2001

Programmer
Feb 2, 2005
18
DE
I am trying to do the following:

I have a link and I would like to check if keys are pressed while the mouse is over this link. Lets say I want to check is either 'a' or 'd' is pressed.

that would be a link:

<a href="blah" onMouseOver="checkkeys()">blah text</a>

and this is my function that I collected from somwhere:

function checkkeys(e) {

document.onkeydown = checkkeys

var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
switch(keycode){
case 65:
alert("keycode: " + keycode);
break;
case 68:
alert("keycode: " + keycode);
break;
}

}

This works in so far that when you load the page and press something, nothing happens and when you move over the link the function is called and it checks for the keys. So far so good. Unfortunatly, the function keeps checking for keys after the mouse moved away.

And thats where I need some help.

So I tried someting like document.onkeydown = false after the case statements, which works in Firefox, but not in IE...

Would be nice if somebody can help me.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top