keyEvents.js 688 B

1234567891011121314151617181920212223242526272829
  1. // implement `key` events
  2. document.onkeydown = checkKey;
  3. function checkKey(e) {
  4. e = e || window.event;
  5. if (e.keyCode == '81') {
  6. // `q` for quit expe
  7. console.log('`q` key is pressed');
  8. window.location = ''
  9. }
  10. else if (e.keyCode == '37') {
  11. // left arrow
  12. console.log('left arrow is pressed');
  13. }
  14. else if (e.keyCode == '39') {
  15. // right arrow
  16. console.log('right arrow is pressed');
  17. }
  18. else if (e.keyCode == '13') {
  19. // right arrow
  20. // TODO : avoid refresh with `enter` key when it is not necessary
  21. console.log('right arrow is pressed');
  22. window.location = window.location.href
  23. }
  24. }