[Codes / Scripts] Detect Caps Lock - Coduri / Scripturi - GAMELIFE România Jump to content

Recommended Posts

Posted

caps.png

Script:

<!DOCTYPE html>
<html>
<style>
#text {display:none;color:red}
</style>
<body>

<h3>Detect Caps Lock</h3>
<p>Press the "Caps Lock" key inside the input field to trigger the function.</p>

<input id="myInput" value="Some text..">
<p id="text">WARNING! Caps lock is ON.</p>

<script>
var input = document.getElementById("myInput");
var text = document.getElementById("text");
input.addEventListener("keyup", function(event) {

if (event.getModifierState("CapsLock")) {
    text.style.display = "block";
  } else {
    text.style.display = "none"
  }
});
</script>

</body>
</html>

 

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...

Important Information