Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #19489, comment 6


Ignore:
Timestamp:
09/02/2013 10:36:07 AM (12 years ago)
Author:
SergeyBiryukov
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #19489, comment 6

    initial v1  
    11I have been having trouble getting this plugin to work properly -- it kept binding all the keys at once no matter what key I set. Because of this, hitting any key would trigger my alert "hello." It took two days to find what was wrong, but this code below should work for everyone, where 'S' is the key you chose to keydown (or up) upon:
    2 
     2{{{
    33jQuery(document).bind('keydown', function (e){
    44        if (String.fromCharCode(e.keyCode) == 'S') {
    5 alert('hello');
    6 e.preventDefault();
    7 return false;
    8    }
     5                alert('hello');
     6                e.preventDefault();
     7                return false;
     8        }
    99});
    10 
     10}}}
    1111
    1212Hope this is helpful to someone!