Click to See Complete Forum and Search --> : Pop up message on key press


DaveKinnell
05-25-2003, 06:46 PM
Can anyone help me I'm after a script, or any kind of code that when a certain key is pressed (e.g ctrl) a popup message appears, similarly to the right click code below

<script name='Javascript'>
<!--
function right( val ) {
if (navigator.appName == 'Netscape' && (val.which == 3 || val.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
alert("Function disabled");
return false;
}
return true;
}
document.onmousedown = right;
document.onmouseup = right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown = right;
window.onmouseup = right;
//-->
</script>

only it works with keyboard keys. I hope this is specific enough

Jona
05-25-2003, 07:15 PM
<script>
//untested code
function alertOnKeyPress(e){
if(navigator.appName=="Netscape" && e.which==104){
alert("You pressed the 'h' key!"); location.href="home.html"; return true;
} else if(navigator.appName=="Microsoft Internet Explorer" && e.keyCode==104){
alert("You pressed the 'h' key!"); location.href="home.html"; return true;}
return false;
}
document.onkeydown = alertOnKeyPress;
document.onkeyup = alertOnKeyPress;
document.onkeypress = alertOnKeyPress;
if(document.layers) window.captureEvents(Event.KEYDOWN);
if(document.layers) window.captureEvents(Event.KEYUP);
if(document.layers) window.captureEvents(Event.KEYPRESS);
}
</script>

khalidali63
05-25-2003, 08:57 PM
Originally posted by Jona

if(document.layers) window.captureEvents(Event.KEYDOWN);
if(document.layers) window.captureEvents(Event.KEYUP);
if(document.layers) window.captureEvents(Event.KEYPRESS);
}
</script>


There are errors in the script...and the biggest thing that is omitted is that it will not work with NS6+ browsers

:)

Jona
05-25-2003, 09:11 PM
Originally posted by Jona
//untested code

Enough said... I made a mistake.. ;)

DaveKinnell
05-27-2003, 05:45 AM
Thanks Dave, the code works perfectly