You are currently viewing Keyboard Hit Counter Using HTML,CSS and JavaScript

Keyboard Hit Counter Using HTML,CSS and JavaScript

Keyboard Hit Counter Using HTML,CSS and JavaScript

 

Keyboard Hit Counter Using HTML,CSS and JavaScript
Keyboard Hit Counter Using HTML,CSS and JavaScript

 

Welcome to the Codewithrandom blog. In this blog, we learn how to create a Keyboard Hit Counter(when the user presses any key from the keyboard its counts and shows on the screen). We use Html, Css, and JavaScript for this Keyboard Hit Counter.

I hope you enjoy our blog so let’s start with a basic Html Structure for a Keyboard Hit Counter.

HTML Code For Keyboard Hit Counter

<div id="activity">
<img src="http://code.quirkbot.com/assets/images/logo/white-outline.svg" width="30%" alt="">
<h1 id="counter"><span class="hits">0</span>
<h1>Keys Hit</h1>
</div>

There is all the Html code for the Keyboard Hit Counter. Now, you can see output without Css and JavaScript. then we write Css and JavaScript for the Keyboard Hit Counter.

Portfolio Website Using HTML CSS And JAVASCRIPT ( Source Code)

Only Html Code Output

Keyboard Hit Counter Using HTML,CSS and JavaScript
Keyboard Hit Counter Using HTML,CSS and JavaScript

CSS Code For Keyboard Hit Counter

body {
margin: 0;
font-family: "Open Sans", comic-sans;
position: absolute;
width: 100vw;
height: 100vh;
overflow: hidden;
display: table;
}
#activity {
display: table-cell;
text-align: center;
vertical-align: middle;
}
#activity:before {
content: "Hit Any Key On Your Keyboard";
position: absolute;
top: -1;
left: 0;
width: 100vw;
height: 10vh;
background: rgba(10, 10, 10, 10, 10);
}
#activity:after {
content: "Codewithrandom";
position: absolute;
bottom: 0;
left: 0;
width: 100vw;
height: 12vh;
}
#result {
text-transform: uppercase;
}
a:link,
a:hover,
a:visited,
a:active {
text-decoration: bold;
}
.hits {
font-size: 5.75em;
font-weight: bolder;
}

Here is our updated output with Html and Css.

50+ Html ,Css & Javascript Projects With Source Code

Html + Css output

Keyboard Hit Counter Using HTML,CSS and JavaScript
Keyboard Hit Counter Using HTML,CSS and JavaScript

JavaScript Code For Keyboard Hit Counter

var hits = 0;
var hitElement = document.querySelector(".hits");
document.body.onkeyup = function (e) {
if ((e.keyCode == 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) {
addHit();
}
};
var addHit = function () {
hits++;
renderHits();
};
var renderHits = function () {
hitElement.innerHTML = hits;
};

Final Output Of Keyboard Hit Counter Html,Css and JavaScript

Keyboard Hit Counter Using HTML,CSS and JavaScript
Keyboard Hit Counter Using HTML,CSS and JavaScript

 

 

100+ JavaScript Projects With Source Code ( Beginners to Advanced)

Now we have completed our Keyboard Hit Counter. Here is our updated output with Html, Css, and JavaScript. Hope you like the Keyboard Hit Counter Project. you can see the output video and project screenshots. See our other blogs and gain knowledge in front-end development.

Thank you!

In this post, we learn how to create a Keyboard Hit Counter using Html, Css, and JavaScript. If we made a mistake or any confusion, please drop a comment to reply or help you in easy learning.

Written by – Code With Random/Anki 

Codepen by – Braxtoony

Leave a Reply