How to Disable Ctrl Key using Javascript

How to Disable ctrl key using javascript and HTML code. Today we will learn how can we turn off the ctrl key or any other combination key with a ctrl key like Ctrl+V Ctrl+C and more. But first, we must know about the issue and what is the cause.

Ctrl key combinations are important but in any case, we do not need them. This trick can be also used for web browsers. In the web browsers, we can see, people using Ctrl-A, Ctrl C keys for a shortcut.

With this guide, you will be able to disable the ctrl key using javascript or HTML code.

More:

How to enable WiFi calling in Redmi phones

What is JavaScript?

In simple words, Java is a program and javascript is a code that tells the program whether it is positive or negative.

Why disable the Ctrl key is a must for websites?

In many cases, we see our visitors copying content. Copied articles are not only harmful to those who copy but also a negative side for the owner. In that case, site owners can take precautions to make their site anti plagiarized content.

All we need to do is make a code to disable Ctrl from the webpage. In the HTML coder, we can do it very easily.

How to disable Ctrl Key using Java Script

disable ctrl and f12 using java script

If you are a coder or you have basic knowledge of it then, you might do it without any problem. Below, we mentioned the code to disable the ctrl key.

This piece of code has to go in the code editor of your program. So, copy this piece of code and paste it. Just like that, you can disable the Ctrl key using Javascript.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Disable Ctrl Key, Right click and F12 </title>

<script language="JavaScript">

//////////F12 disable code////////////////////////

    document.onkeypress = function (event) {

        event = (event || window.event);

        if (event.keyCode == 123) {

           //alert('No F-12');

            return false;

        }

    }

    document.onmousedown = function (event) {

        event = (event || window.event);

        if (event.keyCode == 123) {

            //alert('No F-keys');

            return false;

        }

    }

document.onkeydown = function (event) {

        event = (event || window.event);

        if (event.keyCode == 123) {

            //alert('No F-keys');

            return false;

        }

    }

/////////////////////end///////////////////////

//Disable right click script

//visit http://www.rainbow.arch.scriptmania.com/scripts/

var message="Sorry, right-click has been disabled";

///////////////////////////////////

function clickIE() {if (document.all) {(message);return false;}}

function clickNS(e) {if

(document.layers||(document.getElementById&&!document.all)) {

if (e.which==2||e.which==3) {(message);return false;}}}

if (document.layers)

{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}

else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")

//

function disableCtrlKeyCombination(e)

{

//list all CTRL + key combinations you want to disable

var forbiddenKeys = new Array('a', 'n', 'c', 'x', 'v', 'j' , 'w');

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>

</head>

<body onkeypress="return disableCtrlKeyCombination(event);" onkeydown="return disableCtrlKeyCombination(event);">

Press ctrl and you can check various key is disable with CTRL. like  — 'a', 'n', 'c', 'x', 'v', 'j' , 'w' Just add key in above the array and disable key as you want.

</body>

</html>

So, Here is the code for disabling the Ctrl key using the javascript code editor.

protect your website using ctrl key turn off

Final Words: We can all do these simple steps to disable Ctrl Key using Javascript. Although, this can be tricky if you do not know to use a code editor. Code Editor can be downloaded for free. Check for details on our website to know How to use the code editor to disable the Ctrl key using JavaScript.

I hope you like this article, please share and support How2Guide.

More:

Leave a Comment