Detect Capslock
Hello Guys! Welcome to Coding Torque. In this blog, I'm going to explain to you how to make a Detect Capslock using HTML, CSS and JavaScript. This will be a step-by-step guide. Let's get started 🚀.
Let's go step by step:
Step 1: IMPORT google fonts
Now let's import the fonts using Google Fonts API. Below is the code for Poppins Font. Paste the below code in head tag.
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
Step 2: HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
crossorigin="anonymous" />
<title>Detect caps lock using JavaScript - @code.scientist x @codingtorque</title>
</head>
<body>
<div class="center">
<p>
<div class="container">
<h3>Detect Caps Lock using JavaScript</h3>
<input id="myInput" placeholder="Some text..">
<div style="display: flex;align-items: center;">
<div id="signal"></div>
<p id="message">Capslock is ON!</p>
</div>
</div>
</p>
</div>
</body>
</html>
Output Till Now
Step 3: CSS Code
body {
display: flex;
font-family: poppins;
justify-content: center;
align-items: center;
background-color: black;
color: white;
height: 600px;
}
.container {
padding: 40px;
border: 2px solid deepskyblue;
border-radius: 10px;
}
#text {
display: none;
color: red
}
input {
font-family: poppins;
width: 200px;
height: 30px;
transition: 0.3s;
border-radius: 5px;
padding: 0 5px;
border: none;
outline: none;
}
#signal {
height: 10px;
width: 10px;
border-radius: 50%;
background-color: red;
box-shadow: 0 0 7px red;
margin-right: 10px;
}
Output Till Now
Step 4: JavaScript Code
var input = document.getElementById("myInput");
var signal = document.getElementById("signal");
var message = document.getElementById("message");
input.addEventListener("keyup", function (event) {
if (event.getModifierState("CapsLock")) {
signal.style.background = "red";
signal.style.boxShadow = "0 0 7px red";
message.innerText = "Capslock is ON!"
} else {
signal.style.background = "lawngreen";
signal.style.boxShadow = "0 0 7px lawngreen";
message.innerText = "Capslock is OFF!"
}
})
Final Output
If you want me to code any project or post any specific post,
feel free to DM me at IG @code.scientist or @codingtorque
If you have any doubt or any project ideas feel free to
Contact Us
Hope you find this post helpful💖
Written by: Coding Torque | Piyush Patil
Follow us on Instagram for more projects like
this👨💻