Ultrashock Forums > Development > Client Side
Browser - Disable CTRL key

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
Browser - Disable CTRL key
Old 2008-01-20

Hi all,
I'm developing a RIA in Flash and i need to disable the input of CTRL key in the browser.
Someone know how to do it (I think using javascript)?

Thanks
postbit arrow 3 comments | 4138 views postbit arrow Reply: with Quote   
Registered User
r_bartoli is offline
seperator
Posts: 453
2004-07-28
Age: 27
r_bartoli lives in Italy
seperator

Ultrashock Member Comments:
r_bartoli r_bartoli is offline r_bartoli lives in Italy 2008-01-20 #3 Old  
Thanks Anik, I'm using it now but it doesn't work in IE7...

The script is this one:
Code:
<script language="JavaScript">
function disableCtrlKeyCombination(e)
{
        //list all CTRL + key combinations you want to disable
        var forbiddenKeys = new Array(‘a’, ‘n’, ‘c’, ‘x’, ‘v’, ‘j’);
        var key;
        var isCtrl;

        if(window.event)
        {
                key = window.event.keyCode;     //IE
                if(window.event.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }
        else
        {
                key = e.which;     //firefox
                if(e.ctrlKey)
                        isCtrl = true;
                else
                        isCtrl = false;
        }

        //if ctrl is pressed check if other key is in forbidenKeys array
        if(isCtrl)
        {
                for(i=0; i<forbiddenkeys .length; i++)
                {
                        //case-insensitive comparation
                        if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
                        {
                                alert(‘Key combination CTRL + ‘
                                        +String.fromCharCode(key)
                                        +‘ has been disabled.’);
                                return false;
                        }
                }
        }
        return true;
}
</script>
And I'm using it like this:

Code:
<body onkeypress="return disableCtrlKeyCombination(event);" onkeydown="return disableCtrlKeyCombination(event);" leftMargin="0" topMargin="0">
Any idea?

Thanks
Reply With Quote  
vigneshwaran vigneshwaran is offline vigneshwaran lives in India 2009-11-24 #4 Old  
perfect script its working, thank u so much...
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: