jQuery Javascript Detect if shift enter pressed

0.69K views
no comments
4 Jul 2014 12:02 am

Sometimes we want call a function if user pressed two keys together at the same time. Like Shift+Enter, CTRL+S  more others, I wrote a little code how to call a function if user pressed two keys. copy keys name from another post Keycodes in javascript to use easily with key names.

var j  = jQuery;
    shift = 16;
    enter = 13;
    var shift_pressed = null;
    j(document).ready(function (){
        var shift_enter=null;
        j('body').delegate('.shiftenter','keydown',function (eve){
            if(eve.keyCode==shift){
                shift_pressed=true;
            }

        })
        j('body').delegate('.shiftenter','keyup',function (eve){
            var this_ele  = j(this);

            if(eve.keyCode==shift){
                shift_pressed=false;
            }

            if(eve.keyCode==enter &&shift_pressed==true ){
                //here is shift+enter pressed
                //CALL YOUR CODE......
             }

        })
})

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>