Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 61cefa8

Browse files
authored
Merge pull request tajulafreen#11 from tajulafreen/event-code
50Projects-HTML-CSS-JavaScript: Event code
2 parents d6710b1 + a6f956b commit 61cefa8

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ In order to run this project you need:
155155
</details>
156156
</li>
157157

158+
<li>
159+
<details>
160+
<summary>Event Code</summary>
161+
<p>The Event Code project is a simple web application that allows users to obtain the keycode of any key they press on their keyboard. Built using HTML, CSS, and JavaScript, the application provides a user-friendly interface where users can press any key, and the corresponding keycode will be displayed on the screen in real-time. This project serves as a practical demonstration of event handling in web development and can be used as a learning tool for understanding keyboard events in JavaScript.</p>
162+
<ul>
163+
<li><a href="https://tajulafreen.github.io/50Projects-HTML-CSS-JavaScript/Source-Code/EventCode/">Live Demo</a></li>
164+
<li><a href="https://github.com/tajulafreen/50Projects-HTML-CSS-JavaScript/tree/main/Source-Code/EventCode">Source</a></li>
165+
</ul>
166+
</details>
167+
</li>
168+
158169
</ol>
159170

160171
<p align="right">(<a href="#readme-top">back to top</a>)</p>

Source-Code/EventCode/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="style.css">
7+
<title>Event Code</title>
8+
</head>
9+
<body>
10+
<div id="insert">
11+
<button class="key">
12+
press any key to get the keyCode
13+
</button>
14+
</div>
15+
16+
<script src="script.js"></script>
17+
</body>
18+
</html>

Source-Code/EventCode/script.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const insert = document.getElementById('insert');
2+
3+
window.addEventListener('keydown', (e) => {
4+
insert.innerHTML = `<ul>
5+
<li class="key">
6+
${e.key === ' ' ? 'Space' : e.key}
7+
<small>event.key</small>
8+
</li>
9+
<li class="key">
10+
${e.keyCode}
11+
<small>event.keyCode</small>
12+
</li>
13+
<li class="key">
14+
${e.code}
15+
<small>event.code</small>
16+
</li>
17+
</ul>`;
18+
console.log(e);
19+
});

Source-Code/EventCode/style.css

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
* {
2+
box-sizing: border-box;
3+
}
4+
5+
body {
6+
background-color: floralwhite;
7+
font-family: "Segoe UI", sans-serif;
8+
margin: 0;
9+
overflow: hidden;
10+
height: 100vh;
11+
padding: 20px;
12+
display: flex;
13+
justify-content: center;
14+
align-items: center;
15+
}
16+
17+
#insert {
18+
display: flex;
19+
flex-direction: column;
20+
align-items: center;
21+
}
22+
23+
ul {
24+
display: flex;
25+
}
26+
27+
li {
28+
list-style-type: none;
29+
margin: 0;
30+
padding: 20px;
31+
background-color: #fffafa;
32+
display: flex;
33+
flex-direction: column;
34+
align-items: center;
35+
}
36+
37+
.key {
38+
border: 1px solid #999;
39+
background-color: #eee;
40+
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
41+
align-items: center;
42+
font-size: 20px;
43+
font-weight: bold;
44+
padding: 20px;
45+
margin: 30px;
46+
min-width: 150px;
47+
position: relative;
48+
}
49+
50+
.key small {
51+
position: absolute;
52+
top: -24px;
53+
left: 0;
54+
text-align: center;
55+
width: 100%;
56+
font-size: 14px;
57+
color: #555;
58+
}

0 commit comments

Comments
 (0)