Click to See Complete Forum and Search --> : Alt-Q pressed


lascoff
08-21-2003, 04:18 PM
How would you determine if the Alt Q keys are pressed?

sciguyryan
08-22-2003, 03:03 AM
hi,

this code specifies that '113'(q) and '18'(alt) are pushed then, go to http://www.webdevfaqs.com.
all you have to do is change the location part to what you want it to do.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>1</TITLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function whichKey(e) {
if (window.event) {
code = event.keyCode
}
else {
code = e.which;
}
if (code == 113) && (code == 18){ //Chage the code here.
window.location.href = "http://www.webdevfaqs.com";
}
}
document.onkeydown = whichKey;
//-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>


hope that helped...

pyro
08-22-2003, 08:46 AM
It won't work like that, but this should work ok:

<script type="text/javascript">
alt = 0;
function whichKey(e) {
if (window.event) {
code = event.keyCode
}
else {
code = e.which;
}
if (code == 18) {
alt = 1;
}
if (code == 81) {
if (alt == 1) {
alert ("Alt + Q was pushed");
}
}
if (code != 18) {
alt = 0;
}
}
document.onkeydown = whichKey;
</script>

AdamBrill
08-22-2003, 09:15 AM
This would be even better:<script type="text/javascript">
alt = 0;
q = 0;
function whichKey(e) {
if (window.event) {
code = event.keyCode
}
else {
code = e.which;
}
if (code == 18) {
alt = 1;
}
if (code == 81) {
q=1;
}
if(alt==1 && q==1){
alert("Alt + Q was pressed");
alt=0;
q=0;
}
}
document.onkeydown = whichKey;
document.onkeyup = function(){
if (window.event) {
code = event.keyCode
}else{
code = e.which;
}
if (code == 18) {
alt = 0;
}
if (code == 81) {
q = 0;
}
}
</script>Otherwise if you push alt, let it up, then press q, it still triggers the alert...

sciguyryan
08-22-2003, 09:55 AM
hi,


thank you for pointing that pointing that out to me, i'll have to make ajustments to my scripts too... theyr usless as they are...
thanks for the tip.