lundi 4 juillet 2016

JS - Map alphanumeric keyboard keyCode to a dial pad number 2 - 9

I'm trying to create a dialer widget, catch "keydown" event and highlight the corresponding dialer number.

So, for example clicking "A" on the keyboard, would highlight "2" on the UI:

dialer HTML UI

I've managed to map the first 5 digits (2-6). Since they contain 3 letters each, I was able to map the keyCode like so:

Math.floor(((KeyCode - 65) / 3) + 2).

Q: Is there a way to do it in one line, so PQRS and WXYZ would fit the solution?




Aucun commentaire:

Enregistrer un commentaire