From 6efab2966397df59b185806e6a273e5fab3df0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=BChnel?= Date: Thu, 29 Sep 2016 09:24:39 +0200 Subject: [PATCH] Now with even better keyboard support --- calculator.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/calculator.js b/calculator.js index 34d29cc..a037334 100644 --- a/calculator.js +++ b/calculator.js @@ -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(); @@ -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(); @@ -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(); @@ -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; } }); };