Skip to content

Commit

Permalink
Now with even better keyboard support
Browse files Browse the repository at this point in the history
  • Loading branch information
mischah committed Sep 29, 2016
1 parent 966ff69 commit 6efab29
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@

// Register key event
document.addEventListener('keydown', function (e) {
// console.log('keyCode', e);
switch (e.key) {
case '1':
document.querySelector('button[data-number="1"]').focus();
Expand Down Expand Up @@ -246,6 +247,10 @@
document.querySelector('button[data-action="clear"]').focus();
document.querySelector('button[data-action="clear"]').click();
break;
case 'Clear':
document.querySelector('button[data-action="clear"]').focus();
document.querySelector('button[data-action="clear"]').click();
break;
case '/':
document.querySelector('button[data-action="divide"]').focus();
document.querySelector('button[data-action="divide"]').click();
Expand All @@ -254,6 +259,10 @@
document.querySelector('button[data-action="equal"]').focus();
document.querySelector('button[data-action="equal"]').click();
break;
case '=':
document.querySelector('button[data-action="equal"]').focus();
document.querySelector('button[data-action="equal"]').click();
break;
case '%':
document.querySelector('button[data-action="percent"]').focus();
document.querySelector('button[data-action="percent"]').click();
Expand All @@ -274,6 +283,10 @@
document.querySelector('button[data-action="float"]').focus();
document.querySelector('button[data-action="float"]').click();
break;
case ',':
document.querySelector('button[data-action="float"]').focus();
document.querySelector('button[data-action="float"]').click();
break;
}
});
};
Expand Down

0 comments on commit 6efab29

Please sign in to comment.