Skip to content

Commit 0d82ff4

Browse files
Merge pull request harsh98trivedi#44 from robustus-atrax/feat/input-directly-from-keyboard
feat/take input directly from keyboard
2 parents c334951 + 56f53ef commit 0d82ff4

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

index.html

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,43 +65,43 @@ <h1>
6565
<input type="text" name="screen" id="answer" readonly>
6666
<table>
6767
<tr>
68-
<td><button>(</button></td>
69-
<td><button>)</button></td>
68+
<td><button value="(">(</button></td>
69+
<td><button value=")">)</button></td>
7070
<td>
7171
<div class="row">
7272
<div class="col">
73-
<button onclick="clearAll()">C</button>
73+
<button value="C" onclick="clearAll()">C</button>
7474
</div>
7575
<div class="col">
76-
<button onclick="deleteLastEntry()">CE</button>
76+
<button value="CE" onclick="deleteLastEntry()">CE</button>
7777
</div>
7878
</div>
7979
</td>
80-
<td><button>%</button></td>
80+
<td><button value="%">%</button></td>
8181
</tr>
8282
<tr>
83-
<td><button>7</button></td>
84-
<td><button>8</button></td>
85-
<td><button>9</button></td>
86-
<td><button>X</button></td>
83+
<td><button value="7">7</button></td>
84+
<td><button value="8">8</button></td>
85+
<td><button value="9">9</button></td>
86+
<td><button value="*">X</button></td>
8787
</tr>
8888
<tr>
89-
<td><button>4</button></td>
90-
<td><button>5</button></td>
91-
<td><button>6</button></td>
92-
<td><button>-</button></td>
89+
<td><button value="4">4</button></td>
90+
<td><button value="5">5</button></td>
91+
<td><button value="6">6</button></td>
92+
<td><button value="-">-</button></td>
9393
</tr>
9494
<tr>
95-
<td><button>1</button></td>
96-
<td><button>2</button></td>
97-
<td><button>3</button></td>
98-
<td><button>+</button></td>
95+
<td><button value="1">1</button></td>
96+
<td><button value="2">2</button></td>
97+
<td><button value="3">3</button></td>
98+
<td><button value="+">+</button></td>
9999
</tr>
100100
<tr>
101-
<td><button>0</button></td>
102-
<td><button style="font-weight: bold;">.</button></td>
103-
<td><button>/</button></td>
104-
<td><button style="background-color: #25db72; font-weight: bold; color: #ecf0f1;">=</button></td>
101+
<td><button value="0">0</button></td>
102+
<td><button value="." style="font-weight: bold;">.</button></td>
103+
<td><button value="/">/</button></td>
104+
<td><button value="=" style="background-color: #25db72; font-weight: bold; color: #ecf0f1;">=</button></td>
105105
</tr>
106106
</table>
107107
<hr style="max-width: 50vw;">
@@ -154,18 +154,22 @@ <h1>
154154
if (/[0-9]/.test(key)) {
155155
handleButtonPress(key);
156156
}
157-
// operator key is pressed (+, -, *, /), trigger the corresponding operator button press
158-
if (/[\+\-\*\/%]/.test(key)) {
157+
// operator key is pressed (+, -, *, /, %), trigger the corresponding operator button press
158+
if (/[\.\+\-\*\/%()]/.test(key)) {
159159
handleButtonPress(key);
160160
}
161161
}
162162
function handleButtonPress(value) {
163163
// This function simulates the button press of the calculator for the given value
164164
// Find the corresponding button element based on the value
165165
const button = document.querySelector(`button[value="${value}"]`);
166-
if (button) {
167-
button.click();
168-
}
166+
167+
button.classList.add('clicked')
168+
button.click();
169+
170+
setTimeout(() => {
171+
button.classList.remove('clicked')
172+
}, 70)
169173
}
170174
</script>
171175
</html>

styles/style.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,9 @@ input:checked + .toggle-slider:before {
313313
/* Negative Numbers */
314314
.negative {
315315
color: red;
316-
}
316+
}
317+
318+
/* visual effect on pressing button */
319+
.clicked {
320+
transform: scale(0.68); /* Slightly shrink the button */
321+
}

0 commit comments

Comments
 (0)