PDA

View Full Version : Disable function keys F1 and F5 - again!!


mmasci
09-03-2004, 02:48 AM
The debate continues.... After reading the myriad of forum entries, I thought it was time to post one of my own.

Is there a way to disable function keys F5 and F1 in a swf? I have to use a swf and not a projector because of other fscommand calls that my flash needs to runs.

Below is the code i have "borrowed" from previous forum entries... as you can conclude, it doesn't work. Is there any headway that has been made into this area as a result of the AS2.0 release???

HTML/JavaScript code

document.onkeydown = function(){
if(window.event && window.event.keyCode == 116)
{ // Capture and remap F5
window.event.keyCode = 506;
}

if(window.event && window.event.keyCode == 506)
{ // New action for F5
alert('F5 key was pressed');
return false;
}
}

ActionScript code:

keyListener = new Object();
keyListener.onKeyDown = function() {
//getURL("javascript:alert('"+Key.getCode()+"')");
//trace (Key.getCode());
if (Key.getCode()>111 && Key.getCode()<=123) {
//trace (Key.getCode());
return false;
}
};
keyListener.onKeyUp = function() {
//getURL("javascript:alert('"+Key.getCode()+"')");
if (Key.getCode()>111 && Key.getCode()<=123) {
//trace (Key.getCode());
return false;
}
};
Key.addListener(keyListener);


Any thoughts/ideas????

M.

atrangee
01-18-2008, 02:34 PM
The original post is in 2004, but I am posting the reply because it might help someone else. I had a similar problem too.

for F1 you can use :
document.onhelp = function(){
window.event.keyCode = 503;
return false;
};

and for Other Fn keys :
var blockedKeysArr = [16,17,18,36,45,112,113,114,115,116,117,118,119,120 ,121,122,123];
document.onkeydown = function() {
for(var t=0;t<blockedKeysArr.length;t++){
if(window.event.keyCode == blockedKeysArr[t]){
window.event.keyCode = 503;
return false;
}
}
//alert(window.event+"::"+keyPressed);
};

Hope this helps someone who requires to disable the function keys !!

Also this requires the focus to be in the HTML Page, so you can set it by calling a Javascript function within an enterframe, so that the HTML page is in focus constantly.
Any queries would be welcome :
mumbaimerijaan@rediffmail.com