Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

When you attach 'keypress' event it will give char code which can be easily converted to sign, e.g.:

    document.addEventListener('keypress', function(event) {
      sign = String.fromCharCode(event.charCode);

      if (sign === 'A') {
        console.log('Pressed shift+a');
      }
      else if (sign === 'c' && event.ctrlKey) {
        console.log('Pressed ctrl+c');
      }
    });
I have tested this technique with several layouts (azerty, dvorak, bepo) and it seems to be working fine. For special keys such as enter, esc or backspace you will have to listen for 'keydown' event instead.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: