Javascript/jQuery Keypress logging

前端 未结 7 1743
日久生厌
日久生厌 2020-12-30 14:34

I would like to be able to log the key presses on a specific page, trying to implement an \'Easter egg\' type functionality where when the correct keys are pressed in the co

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 14:39

    I have earlier used this code to use the up/down arrows to scroll through a list, it should be relativly easy to extend this to check for a certain key combo.

    $("#SearchInput").keydown(function(e){
      switch(e.which) { 
         // User pressed "up" arrow
         case 38:
            navigate('up');
         break;
         // User pressed "down" arrow
         case 40:
            navigate('down');
         break;
         // User pressed "enter"
         case 13:
            if(currentUrl != '') {
               window.location = currentUrl;
            }
         break;
      }
    

提交回复
热议问题