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
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